Reputation: 19
any ideas what im doing wrong here..im supposed to see 2 rectangles in my JFrame but all i get is a grey box. So no rectangles, colors or nothing responds to my code.
Here is the class with the main method :
import javax.swing.JFrame;
public class Paron {
public static void main(String[] args) {
JFrame f = new JFrame("Rektanglar");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Rektanglar r = new Rektanglar ();
f.add(r);
f.setSize(400, 250);
f.setVisible(true);
}
}
and here is my JPanel code:
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JPanel;
public class Rektanglar extends JPanel {
public void PaintComponent (Graphics g) {
super.paintComponent (g);
this.setBackground(Color.WHITE);
g.setColor(Color.BLUE);
g.fillRect(25,25, 100, 100);
g.setColor(Color.RED);
g.fillRect(40,40,100,100);
}
}
what am i missing? thanks for any help
Upvotes: 2
Views: 300
Reputation: 159754
It's paintComponent
not PaintComponent
. Java is case sensitive.
@Override
public void paintComponent(Graphics g) {
Add the @Override
annotation to allow the compiler to check for the existence of the method.
Upvotes: 5
Reputation: 22233
public void PaintComponent (Graphics g) {
the p
for PaintComponent
has to be lowercase:
public void paintComponent (Graphics g) {
Upvotes: 0