用SWING组件实现登录对话框

王朝system·作者佚名  2008-05-31
窄屏简体版  字體:   |    |    |  超大  

作者:Javazealot

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

import java.awt.*;

import javax.swing.*;

import java.awt.event.*;

/*

<APPLET

CODE=dialoginput.class

WIDTH=300

HEIGHT=200>

</APPLET>

*/

public class dialoginput extends JApplet implements ActionListener

{

JLabel top=new JLabel("Welcome to cn-java net !");

JButton display=new JButton("会员登录");

JLabel welcomeWord=new JLabel(" 您还没有登录 ");

JLabel title=new JLabel(" 登 录 窗 口 "),

name=new JLabel("会员名:"),

password=new JLabel("密码:");

JTextField inputname=new JTextField(12);

JPasswordField inputpassword=new JPasswordField(12);//与AWT不同的是,Swing有一个用于口令的非凡控件,就是JPasswordField

JButton ok=new JButton("确定"),

cancel=new JButton("放弃");

private JDialog dialog=new JDialog((Frame)null,"登录",true);

public void init()

{

Container contentPane=getContentPane();

Container dialogContentPane=dialog.getContentPane();

JPanel p=new JPanel();

contentPane.setLayout(new GridBagLayout());

GridBagConstraints gbc=new GridBagConstraints();

gbc.gridy=0;

contentPane.add(top,gbc);

gbc.gridx=GridBagConstraints.RELATIVE;

gbc.gridy=1;

contentPane.add(display,gbc);

gbc.gridx=GridBagConstraints.RELATIVE;

gbc.gridy=2;

contentPane.add(welcomeword,gbc);

dialogContentPane.setLayout(new GridBagLayout());

GridBagConstraints gbb=new GridBagConstraints();

gbb.gridx=1;

gbb.gridy=0;

dialogContentPane.add(title,gbb);

gbb.gridx=GridBagConstraints.RELATIVE;

gbb.gridy=1;

dialogContentPane.add(name,gbb);

dialogContentPane.add(inputname,gbb);

gbb.gridx=GridBagConstraints.RELATIVE;

gbb.gridy=2;

dialogContentPane.add(password,gbb);

dialogContentPane.add(inputpassword,gbb);

inputpassword.setEchoChar(′*′);

gbb.gridx=GridBagConstraints.RELATIVE;

gbb.gridy=3;

p.setLayout(new FlowLayout());

p.add(ok);

p.add(cancel);

gbb.gridx=1;

gbb.gridy=4;

dialogContentPane.add(p,gbb);

display.addActionListener(this);

ok.addActionListener(this);

cancel.addActionListener(this);

}

public void actionPerformed(ActionEvent e)

{

if(e.getSource()==display){

dialog.setBounds(200,200,300,200);

dialog.show();

}else if(e.getSource()==ok){

welcomeword.setText("您好,"+inputname.getText()+",欢迎光临中文Java技术网!");

}else if(e.getSource()==cancel){

welcomeword.setText("你没有输入!");

}

dialog.setVisible(false);

}

}

附:本程序已通过调试,需要单独编一个Html,否则中文无法显示

 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
© 2005- 王朝網路 版權所有 導航