计算机技术论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

  • 欢迎访问 计算机技术论坛-电脑迷与初学者的家园!由于论坛管理严格,新注册会员可能遇到各种问题,无法解决的请发邮件 admin@jsjbbs.cn
查看: 2832|回复: 0

java代码( 续):

[复制链接]
发表于 2009-9-6 23:46:02 | 显示全部楼层 |阅读模式
package swing布局管理器包;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.WindowConstants;
public class Login extends JFrame {
private JLabel userLabel;
private JLabel passLabel;
private JButton exit;
private JButton login;
private JTextField userName;
private JPasswordField userPassword;
public Login() {
  setTitle("登录窗口");
  setBounds(300, 200, 300, 150);
  getContentPane().setLayout(null);
  userLabel = new JLabel();
  userLabel.setText("用户名:");
  getContentPane().add(userLabel);
  userLabel.setBounds(10, 10, 200, 18);
  getContentPane().add(userLabel);  //向容器中添加组件。
                                   //其中的getContentPane()方法返回作为此窗口的 contentPane 的 Container(对象)。
  userName = new JTextField();
  userName.setBounds(60, 10, 200, 18);
  getContentPane().add(userName);
  passLabel = new JLabel();
  passLabel.setText("密  码:");
  passLabel.setBounds(10, 50, 200, 18);
  getContentPane().add(passLabel);
  userPassword = new JPasswordField();
  userPassword.setBounds(60, 50, 200, 18);
  getContentPane().add(userPassword);
  login = new JButton();
  login.setText("登录");
  login.setBounds(90, 80, 60, 18);
  getContentPane().add(login);
  exit = new JButton();
  exit.setText("退出");
  exit.setBounds(170, 80, 60, 18);
  getContentPane().add(exit);
  setResizable(false);    //当参数为false时,表明禁止改变参数的大小;当参数为true时,表明窗口的大小可以改变。
  setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);    //设置窗体的关闭方式,
                                                                   //其中的WindowConstants是个接口,
                                                            // WindowConstants.EXIT_ON_CLOSE表示一个常量3。
                                                            
}
public static void main(String[] args) {
  Login loginFrame=new Login();
  loginFrame.setVisible(true);
}
}
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

无图版|手机版|计算机技术论坛 JSJBBS.CN @ 2008-2024 ( 鲁ICP备17021708号 )

技术支持 : 北京康盛新创科技有限责任公司

快速回复 返回顶部 返回列表