快捷搜索:  as  2018  FtCWSyGV  С˵  test  xxx  Ψһ  w3viyKQx

和记娱乐怡情怎么样:用SWING组件实现登录对话框



作者:Javazealot

/*本法度榜样是模拟的中文Java技巧网的登录窗口,用Swing组件实现的,不过还有一些必要完善的地方,以是我盼望能获得各位和记娱乐怡情怎么样Java喜欢者的建议*/

import java.awt.*;

import javax.swing.*;

import java.awt.event.*;

/*

*/

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);

JP和记娱乐怡情怎么样asswordField 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.setEc和记娱乐怡情怎么样hoChar(´*´);

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,否则中文无法显示

您可能还会对下面的文章感兴趣: