Hi, I am trying to make simple gui which switches jpanel inside jframe but my IDE says "Cannot make static reference to non static method setPage(int) from the type Main". Why is that? There is no static modifier on actionPerformed or at setPage or actually anywhere else than public static void main(String[] args) {}
Main.java
package net.viped;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
public class Main extends JFrame{
PwGUI pwgui = new PwGUI();
FirstPageGUI fpgui = new FirstPageGUI();
public Main() {
setContentPane(pwgui);
setSize(800, 600);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public void setPage(int i) {
switch(i) {
case 1:
setContentPane(pwgui);
break;
case 2:
setContentPane(fpgui);
break;
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
new Main();
}
}
PwGUI.java
package net.viped;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JPanel;
public class PwGUI extends JPanel implements ActionListener{
JButton ok = new JButton();
public PwGUI(){
ok.addActionListener(this);
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if (e.getActionCommand().equals(ok)) {
Main.setPage(2);
}
}
}
FirstPageGUI.java
package net.viped;
import javax.swing.JButton;
import javax.swing.JPanel;
public class FirstPageGUI extends JPanel{
JButton newProject = new JButton();
public FirstPageGUI() {
add(newProject);
}
}