Reputation: 177
Why does this not work? It shows me the GUI but not the paint. How would I change this into two classes?
import java.awt.Graphics;
import javax.swing.JFrame;
public class runpaintgui extends JFrame{
public static void main(String[] args){
JFrame frame = new JFrame();
frame.setSize(5000,2000);
frame.setResizable(false);
frame.setTitle("game");
frame.setVisible(true);
}
public void paint(Graphics g){
super.paint(g);
g.drawString("adsf",40,45);
g.draw3DRect(50, 30, 600, 700, true);
repaint();
}
}
Upvotes: 1
Views: 104
Reputation: 8825
You are creating a generic JFrame
in this line:
JFrame frame = new JFrame();
What you want to probably do is:
JFrame frame = new runpaintgui();
Then your paint()
method will be called.
Upvotes: 5
Reputation: 69494
You have to instantiate your class and not the JFrame
class.
change:
JFrame frame = new JFrame();
to
runpaintgui frame = new runpaintgui();
Then your paint()
method will be called.
And do not call repaint()
in paint
. Because repaint()
calls paint
.
Upvotes: 5