I wrote a program to display a rectangle within a window, but it won't show. Is it because I didn't call the paint() method?
Sorry for indentation, I am using a text editor
import javax.swing.*; import java.awt.Graphics; public class myGame { public int x = 20; public int y = 20; myGame(){ JFrame f = new JFrame("The most advanced game in the world"); f.setSize(500,500); f.setVisible(true); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } public void paintComponent (Graphics g){ g.drawString("Hello",20,50); g.drawRect(50,50,x,y); g.fillRect(50,50,x,y); } public static void main(String[] args) { new myGame(); } }
Thanks for any and all help!