import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;

public class MainFrame extends JFrame {
public MainFrame() {
// TODO Auto-generated constructor stub
this.setTitle("登录界面");
this.setSize(460,350);
JLabel adress = new JLabel("节点地址:");
JTextField ja = new JTextField();
JLabel port = new JLabel("节点端口:");
JTextField jp = new JTextField();
JLabel password = new JLabel("连接密码:");
JTextField jpa = new JTextField();
JLabel Lport = new JLabel("本地端口:");
JTextField jL = new JTextField();

JButton exit = new JButton("退出");
exit.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
System.exit(0);
}
});
JButton ensure = new JButton("确认");
JButton cancle = new JButton("取消");

adress.setBounds(50, 50, 70, 30);
port.setBounds(50, 100, 70, 30);
password.setBounds(50, 150, 70, 30);
Lport.setBounds(50, 200, 70, 30);
exit.setBounds(120, 250, 60, 30);
ensure.setBounds(200, 250, 60, 30);
cancle.setBounds(280, 250, 60, 30);

ja.setBounds(250, 50, 180, 25);
jp.setBounds(250, 100, 180, 25);
jpa.setBounds(250, 150, 180, 25);
jL.setBounds(250, 200, 180, 25);
// 设置布局为空,使用坐标控制控件位置的时候,一定要设置布局为空
this.setLayout(null);

this.add(adress);
this.add(port);
this.add(password);
this.add(Lport);
this.add(exit);
this.add(ensure);
this.add(cancle);

this.add(ja);
this.add(jp);
this.add(jpa);
this.add(jL);

this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);

}
public static void main(String[] args) {
// TODO Auto-generated method stub
new MainFrame();
}

}



自作的一个Prison Break 界面_java