unpredictable java

view full story

http://www.daniweb.com – hey there, I have the following code: import java.awt.*; import javax.swing.*; public class TabelaEShahut extends JPanel{ public static void main(String[] args){ new TabelaEShahut(); } public TabelaEShahut(){ JFrame f = new JFrame(); f.setSize(500, 500); f.setVisible(true); f.setTitle("shah"); f.getContentPane().add(this); } public void paintComponent(Graphics g){ g.setColor(Color.white); g.fillRect(0, 0, 700, 700); g.setColor(Color.red); g.fillRect(50, 50, 400, 400); g.setColor(Color.black); g.fillRect(150, 50, 100, 100); g.fillRect(350, 50, 100, 100); g.fillRect(50, 150, 100, 100); g.fillRect(250, 150, 100, 100); g.fillRect(150, 250, 100, 100); g.fillRect(350, 250, 100, 100); g.fillRect(50, 350, 100, 100); g.fillRect(250, 350, 100, 100); } } I expected this code to work properly and display a four by four chess board on my screen... and it did, indeed, but the problem is that it does not do so everytime i run the code. i can never know if it is going to output the result or not when i run it. initially, it refused to show the board like twenty times but i kept comparing the code with other files i have that i know to have worked and comipling and running the file in question and it suddenly started working - but not everytime i run it. i was wondering what would the problem be and if there is any way i can prevent such unpredictabilities from occuring. you might need to know that i used jGRASP to compile and run the file. thanks a lot to anybody that replies and accept my apology for my long explanations. (General)