我想把数据库连接文件写在另一个类里publicclassLoginFrameextendsJFrameimplementsActionListener{privateStringwelcomeMsg="欢迎使用图书管理系统!";privateJLabelIbWelcome=newJL...
我想把数据库连接 文件写在另一个类里
public class LoginFrame extends JFrame implements ActionListener {
private String welcomeMsg = "欢迎使用图书管理系统!";
private JLabel IbWelcome = new JLabel(welcomeMsg);
private JLabel IbDept = new JLabel("请选择登录方式:");
private JComboBox cbDept = new JComboBox();
private JLabel IbAccount = new JLabel("请您输入账号:");
private JTextField tfAccount = new JTextField(10);
private JLabel IbPassword = new JLabel("请您输入密码:");
private JPasswordField pfPassword = new JPasswordField(10);
private JButton btLogin = new JButton("登录");
private JButton btRegister = new JButton("退出");
public LoginFrame(){
super("登录");
this.setLayout(new FlowLayout());
this.add(IbWelcome);
this.add(IbDept);
this.add(cbDept);
cbDept.addItem("学生");
cbDept.addItem("管理员");
this.add(IbAccount);
this.add(tfAccount);
this.add(IbPassword);
this.add(pfPassword);
this.add(btLogin);
this.add(btRegister);
this.setSize(240,200);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setResizable(false);
this.setVisible(true);
btLogin.addActionListener(this);
btRegister.addActionListener(this);
}
public void actionPerformed(ActionEvent e) {
if(e.getSource() == btLogin){
String dept = (String)cbDept.getSelectedItem();
String account = tfAccount.getText();
String password = new String(pfPassword.getPassword());
if("学生".equals(dept)){
不会写了!!!!!
}
}
}
}
我知道怎么连数据库但是怎么写着另外一个文件里,并且调用呢
展开