0

I am making application, using IDEA Forms. I want to have different forms. First for login, then for displaying information from database after login. I created two different forms. First one: MenuMain and second AdminForm. After clicking a login button in MenuMain I want to open AdminForm, I tried with setContentPane and passing main panel from AdminForm, but it does not work. How to solve this?

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);
}

And the AdminForm Code:

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;
}
Cœur
  • 37,241
  • 25
  • 195
  • 267
  • Please share your code – BackSlash Jun 12 '18 at 12:55
  • So this is the main from main in MenuMainForm:JFrame menuFrame = new JFrame("Kawiarnia"); menuFrame.setContentPane(new MenuMainForm().panel1); menuFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); menuFrame.setExtendedState(JFrame.MAXIMIZED_BOTH); menuFrame.setVisible(true); – Natalia Gazda Jun 12 '18 at 12:58
  • Don't paste it in the comments please. Edit the question and include the code using the code tool. – BackSlash Jun 12 '18 at 12:59
  • Ok, got it:) Sorry my first post on slack, Ididnt added all code concerning Databasse, just the forms gui part. – Natalia Gazda Jun 12 '18 at 13:03
  • Use a [`CardLayout`](http://download.oracle.com/javase/8/docs/api/java/awt/CardLayout.html) as shown in [this answer](http://stackoverflow.com/a/5786005/418556). – Andrew Thompson Jun 12 '18 at 15:11

0 Answers0