模拟实现本站登录窗口(AWT版本)

来源:互联网 发布:喜欢一个人知乎 编辑:程序博客网 时间:2024/04/28 17:55
<script type="text/javascript">google_ad_client = "pub-8800625213955058";/* 336x280, 创建于 07-11-21 */google_ad_slot = "0989131976";google_ad_width = 336;google_ad_height = 280;//</script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>/*本程序是模拟的中文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 77750 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();}} 附:本程序已通过调试,没有任何错误.
原创粉丝点击
热门IT博客
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 衣柜关不上怎么办 大理石不亮怎么办 城市书房怎么办卡 冬天鞋子潮湿怎么办 木地板地平不平怎么办 房子长时间不住怎么办 房子长期不住怎么办 房子装修不合格怎么办 装修没签合同怎么办 做事手脚慢怎么办 天生干活慢怎么办 小孩做事慢怎么办 孩子太慢怎么办 甲醛中毒后怎么办 甲醛中毒怎么办啊 甲醛中毒头晕怎么办 装修合同违约怎么办 装修房子不懂怎么办 自己设计房子怎么办 银行房贷还不上怎么办 周末装修扰民怎么办 楼下装修扰民怎么办 卧室内飘窗太高怎么办 中介欠钱不给怎么办 医院欠钱不给怎么办 gta4很卡怎么办 鞋子长了怎么办 银行收到假币怎么办 物业太差怎么办 装修引起纠纷怎么办 装修合同纠纷怎么办 签合同违约怎么办 工程车晚上扰民怎么办 孕妇电解质紊乱怎么办 冲正收入怎么办 建筑工程建造师怎么办 怎么办市政资质 拿不到工资怎么办 工地上拖欠工资怎么办 拖欠一个月工资怎么办 物业资质停办怎么办