I'm not able to see content on JFrame ,when JFrame shows up.
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class GraphicUse extends JPanel
{
public void PaintComponent(Graphics gr)
{
super.paintComponents(gr);
this.setBackground(Color.BLUE);
gr.setColor(Color.WHITE);
gr.fillRect(50, 50, 100, 100);
gr.setColor(new Color(139,38,190));
gr.fillRect(50, 70, 100, 100);
gr.setColor(Color.RED);
gr.drawString("This is a new String", 50, 90);
}
public static void main(String[] args)
{
}
}
And displaying it in another class which extends Frame
JFrame newframe = new JFrame("Color Frame");
newframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
GraphicUse gu = new GraphicUse();
newframe.add(gu);
newframe.setSize(250,300);
newframe.setVisible(true);