模拟实现登录窗口(Swing版本)
2008-01-05 08:49:51 来源:WEB开发网核心提示:/*本程序是模拟的中文java技术网的登录窗口,用Swing组件实现的,不过还有一些需要完善的地方,所以我希望能得到各位Java爱好者的建议*/import java.awt.*;import javax.swing.*;import java.awt.event.*;/*<APPLETCODE=dialogin
/*本程序是模拟的中文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,否则中文无法显示.
[]
赞助商链接