求助 java awt 登陆界面
程序代码:
import java.awt.*; import java.awt.event.*; import javax.swing.*; public class denglu extends javax.swing.JFrame { private JPanel jPanel1; private JButton bntLogin; private JButton bntCannel; private JPasswordField pwd; private JTextField username; private JLabel jLabel2; private JLabel jLabel1; public static void main(String[] args) { denglu inst = new denglu(); inst.setLocationRelativeTo(null); inst.setVisible(true); } public denglu() { super(); initGUI(); } private void initGUI() { try { setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); { jPanel1 = new JPanel(); getContentPane().add(jPanel1, BorderLayout.CENTER); jPanel1.setLayout(null); { jLabel1 = new JLabel(); jPanel1.add(jLabel1); jLabel1.setText("用户名"); jLabel1.setBounds(45, 30, 75, 25); } { jLabel2 = new JLabel(); jPanel1.add(jLabel2); jLabel2.setText("密码"); jLabel2.setBounds(45, 75, 55, 15); } { username = new JTextField(); jPanel1.add(username); username.setBounds(100, 30, 140, 25); } { pwd = new JPasswordField(); jPanel1.add(pwd); pwd.setBounds(100, 70, 140, 25); } { bntLogin = new JButton(); jPanel1.add(bntLogin); bntLogin.setText("Ok"); bntLogin.setBounds(80, 120, 60, 30); bntLogin.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { if (username.getText().equals("1040610203") && pwd.getText().equals("1040610203")) { JOptionPane.showMessageDialog(denglu.this, "登录成功"); } else { JOptionPane.showMessageDialog(denglu.this, "登录失败"); } } }); bntCannel = new JButton(); jPanel1.add(bntCannel); bntCannel.setText("Exit"); bntCannel.setBounds(160, 120, 60, 30); bntCannel.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { System.exit(0); } }); } } pack(); setSize(300, 215); } catch (Exception e) { e.printStackTrace(); } } }
、、、、、、、、、、、
怎样添加 键盘监视器呢 还有怎样添加窗口名称