在Intellij IDEA中连接表单Java,swing

时间:2018-06-12 12:53:43

标签: java swing intellij-idea

我正在使用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;
}

0 个答案:

没有答案