标签:
package test;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class chuangt extends JFrame {
public chuangt(){
//设置大小
this.setSize(500,400);
//设置标题
this.setTitle("登录界面");
//窗体的初始位置
this.setLocationRelativeTo(null);//设置为null相对我的屏幕居中
//设置窗体不可调整
this.setResizable(false);
//设置窗体自动关闭
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//设置窗体布局
this.setLayout(null);//自由布局
//添加控件类的实例
JLabel jl =new JLabel("用户名:");
jl.setBounds(100, 100, 70, 30);
this.add(jl);
JTextField jt =new JTextField();
jt.setBounds(150, 100, 200, 30);
this.add(jt);
JLabel jl1 =new JLabel("密码:");
jl1.setBounds(110, 150, 70, 30);
this.add(jl1);
JPasswordField jt1 =new JPasswordField();
jt1.setBounds(150, 150, 200, 30);
this.add(jt1);
JButton btn=new JButton("注册");
btn.setBounds(250, 250, 70, 30);
this.add(btn);
JButton btn1=new JButton("登录");
btn1.setBounds(150, 250, 70, 30);
btn1.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
setVisible(false);
cti2 ct =new cti2(chuangt.this);
ct.setVisible(true);
}
});
this.add(btn1);
}
public static void main(String args[]){
chuangt ct=new chuangt();
ct.setVisible(true);
}
}
标签:
原文地址:http://www.cnblogs.com/54ljj/p/5414421.html