JSPCN主页 | JSP空间 | 网站制作 | JSP下载 | JSP论坛 | JSP教程 | 关于JSPCN | 联系我们
JSP虚拟主机,jsp空间,java空间,java虚拟空间,详细请点击进入
做最专业的JSP中文网站 当前位置首页--JAVA技术--JAVA类  
文章搜索:
关键字 标题
  
JSP中文网内容管理系统(JCMS)
JSP虚拟主机
网络笔记本
网摘,图片,笔记收藏
虚拟服务器

JSPCN文章目录分类
JSP配置[219]JSP基础[136]
中文问题[69]上传问题[27]
JAVABEAN[46]数据库[212]
文件操作[126]图片声音[17]
JSP其他[57]时间相关[16]
JAVAMAIL[72]STRUTS[144]
开发工具[28]教程系列[157]
JSP实例[89]
JAVA基础[421]APPLET[78]
JAVA网络[179]Applica[115]
Servlet[98]XML[163]
J2ME[257]J2EE[374]
考试相关[63]JAVA线程[90]
EJB[261]Swing[26]
Java API[141]声音图片[28]
异常处理[33]JAVA实例[290]
JAVA类[139]SUN[89]
Hibernate[6]JMX[8]
Spring[34]
本版推荐文章 
本版热点文章 
相关文章链接 
 
用AWT组件实现登录对话框
作者:未知     文章来源:www.jspcn.net
访问次数:390次     加入时间:2005年01月19日
作者:Javazealot

/*本程序是模拟的中文Java技术网的登录窗口,用AWT组件实现的,不过还有一些需要完善的地方,所以我希望能得到各位Java爱好者的建议*/

import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;

//对话框创建

class okcanceldialog extends Dialog implements ActionListener
{
Panel p;
Label top,name,password;
TextField inputname,inputpassword;
Button ok,cancel;
String data;
okcanceldialog(Frame hostFrame,String title,boolean dModal)
{
super(hostFrame,title,dModal);
p=new Panel();
p.setLayout(new FlowLayout());
setSize(300,200);
setLayout(new GridBagLayout());//用网格包装布局为放置组件
GridBagConstraints gbb=new GridBagConstraints();
top=new Label("登 录 窗 口 ");
gbb.gridx=1;
gbb.gridy=0;//在第一行显示top标签
add(top,gbb);

name=new Label("会员名:");
gbb.gridx=GridBagConstraints.RELATIVE;
gbb.gridy=1;//在第二行显示会员名标签和相应文本框
add(name,gbb);
inputname=new TextField(20);
add(inputname,gbb);

password=new Label("密码:");
gbb.gridx=GridBagConstraints.RELATIVE;
gbb.gridy=2;在第二行显示密码标签和相应文本框
add(password,gbb);
inputpassword=new TextField(20);

add(inputpassword,gbb);
inputpassword.setEchoChar(´*´);


ok=new Button("确定");
p.add(ok);
ok.addActionListener(this);

cancel=new Button("放弃");
p.add(cancel);
cancel.addActionListener(this);
p.add(new Label(" "));//将两个按钮和一个含有很多空格的标签加入板(注:标签的 //作用是为了把按钮挤在中间)
gbb.gridx=1;
gbb.gridy=3;//在第四行显示板

add(p,gbb);
data=new String();

addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){System.exit(0);}});//用以关闭窗 //口

}

public void actionPerformed(ActionEvent event)
{
if(event.getSource()==ok){
data=" 您好,"+inputname.getText()+",欢迎光临中文Java技术网!";
}else if(event.getSource()==cancel){
data=" 你没有输入! ";
}
setVisible(false);
}
}


//窗口创建
class dialogframe extends Frame implements ActionListener
{
Label firstpage,word;
Button enter;
okcanceldialog dialog;
dialogframe(String title)
{
super(title);
setLayout(new GridBagLayout());
GridBagConstraints gbc=new GridBagConstraints();

firstpage=new Label("Welcome to cn-java net");


enter=new Button("会员登录");
gbc.gridy=0;
add(firstpage,gbc);

word=new Label(" 您还没有登录 ");
gbc.gridx=GridBagConstraints.RELATIVE;
gbc.gridy=1;
add(enter,gbc);

enter.addActionListener(this);
gbc.gridx=GridBagConstraints.RELATIVE;
gbc.gridy=2;//在第三行显示欢迎词
add(word,gbc);
dialog=new okcanceldialog(this,"登录",true);


}

public void actionPerformed(ActionEvent event)
{
if(event.getSource()==enter){
dialog.setVisible(true);
word.setText(dialog.data);
}
} //此方法用来显示对话框
}




//主类
public abstract class mainclass implements ActionListener
{
public static void main(String[] args)
{
dialogframe f=new dialogframe("Welcome");//创建窗口实例
f.setSize(300,200);
f.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){System.exit(0);}});
f.show();
}
}

附:本程序已通过调试,没有任何错误.
 
Copyright © 2002-2005 JSPCN.net. All rights reserved.
JSP中文网    备案序号:蜀ICP备05001583号
成都恒海科技发展有限公司    成都市一环路南二段6号新瑞楼三楼8号