我正在使用IDEA
表单进行申请。我希望有不同的形式。首先登录,然后登录后显示数据库中的信息。我创造了两种不同的形式。第一个:MenuMain
和第二个AdminForm
。单击MenuMain中的登录按钮后,我想打开AdminForm,我尝试使用setContentPane
并从AdminForm传递主面板,但它不起作用。怎么解决这个问题?
public class MenuMainForm extends JFrame implements ActionListener {
private JPanel panel1;
private JTextPane logowanieText;
private JTextField userField;
private JTextField passField;
private JButton logowanieButton;
public MenuMainForm(){
logowanieButton.addActionListener(this);
public void actionPerformed(ActionEvent e) {
AdminForm adminForm = new AdminForm();
this.setContentPane(adminForm);
}
public static void main( String[] args){
JFrame menuFrame = new JFrame("Kawiarnia");
menuFrame.setContentPane(new MenuMainForm().panel1);
menuFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
menuFrame.setExtendedState(JFrame.MAXIMIZED_BOTH);
menuFrame.setVisible(true);
}
和AdminForm代码:
public class AdminForm extends JPanel{
private JPanel adminPanel;
private JButton infoKawiarniaButton;
private JTable tabelaInfo;
private static String QUERY_INFO = "SELECT * FROM NATALIAGAZDA.KAWIARNIE ";
public AdminForm() {
DefaultTableModel model = (DefaultTableModel) tabelaInfo.getModel();
model.addRow(new Object[]{"Atrybut", "Wartosc"});
public JPanel getAdminPanel() {
return adminPanel;
}