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

<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(); } } 附:本程序已通过调试,没有任何错误.
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值