My code is an example from my book and I'm doing something wrong concerning the creation and reference on the class paneel.
The error is:
Main.java:14: error: non-static variable this cannot be referenced from a static context
frame.setContentPane( new paneel() );
What am I doing wrong?
package vb303;
import javax.swing.*;
import java.awt.*;
public class Vb303 extends JFrame{
public static void main(String[] args) {
JFrame frame = new Vb303();
frame.setSize(400,200);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setTitle("vb303");
frame.setContentPane( new paneel() );
frame.setVisible(true);
}
public class paneel extends JPanel{
private int totaalMinuten, uren, restMinuten;
public paneel(){
totaalMinuten = 1412;
uren = totaalMinuten /60;
restMinuten = totaalMinuten %60;
}
public void paintComponent(Graphics g){
super.paintComponents(g);
g.drawString(totaalMinuten+ "minuten =", 50, 30);
g.drawString(uren + "uuren",50,30);
g.drawString(restMinuten + "minuten", 50, 90);
}
}
}