I have a problem. I have 2 classes(MainFrame and MainContacts) I want to get the panel which is declared in MainContacts class and show it when I click action in the menu.
When i click right now nothing is happening, just like before click. I don't know where the problem is
My code:
public class MainFrame {
JFrame mainFrame = new JFrame("Team Helper");
JPanel mainPanel = new JPanel();
JMenuBar mainMenuBar = new JMenuBar();
JMenu file = new JMenu("Plik");
JMenuItem close = new JMenuItem("Zakoncz");
JMenu tools = new JMenu("Narzedzia");
JMenuItem contacts = new JMenuItem("Kontakty");
JMenu help = new JMenu("Pomoc");
JMenuItem information = new JMenuItem("O programie");
public void runContactForm()
{
new MainContacts();
}
public MainFrame(){
mainFrame.setJMenuBar(mainMenuBar);
mainMenuBar.add(file);
file.add(close);
close.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
mainFrame.dispose();
}
});
mainMenuBar.add(tools);
tools.add(contacts);
contacts.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
runContactForm();
}
});
mainMenuBar.add(help);
help.add(information);
mainFrame.add(mainPanel);
mainFrame.setVisible(true);
mainFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
mainFrame.setSize(1600, 800);
mainFrame.setResizable(false);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
new MainFrame();
}
});
}
}
second class:
public class MainContacts extends MainFrame {
JPanel leftPanel = new JPanel();
JPanel rightPanel = new JPanel();
JButton show = new JButton("Pokaż");
JButton addContact = new JButton("Dodaj kontakt");
public MainContacts() {
leftPanel.add(show);
leftPanel.add(addContact);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
new MainContacts();
}
});
}
}