JFrame showing nothing.
-
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); -
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); -
No idea; but you need to provide enough to help people to understand the problem. Remember, we have never seen your code before so we cannot guess what each part is supposed to do or how it fits together. Having a blank
main
method in the code you showed above just serves to confuse.Veni, vidi, abiit domum
-
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);Your frame is covered by a gray frame thats why paint method do not show anything.