This is the code of a recent java application that I created. It was created in Eclipse IDE and there were no errors found. I am wondering my mistake... Just check the below code for errors.
The First Class:
import javax.swing.*;
public class GraphicsGo extends JFrame{
/**
*
*/
private static final long serialVersionUID = 1L;
public static void main(String[] args) {
System.out.println("Noice");
JFrame jf = new JFrame();
JPanel pnl = new JPanel();
jf.add(pnl);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
graphics gr = new graphics();
jf.setSize(400, 250);
pnl.add(gr);
jf.setVisible(true);
}
}
The Second Class:
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JPanel;
public class graphics extends JPanel{
/**
*
*/
private static final long serialVersionUID = 1L;
public void PaintComponent(Graphics g) {
super.paintComponent(g);
this.setBackground(Color.red);
g.setColor(Color.blue);
g.drawRect(0, 0, 2, 2);
setVisible(true);
}
}
The window I think I did everything right.
The classes are two different files.