Java Graphics Disappear
I am trying to place some simple graphics on a JFrame window using the Graphics2D class. The graphics rarely remain on the window more than 1/10 of a second. Here is the body of the main method:
JFrame win;
Container contentPane;
Graphics2D g;
win = new JFrame();
win.setSize(300, 200);
win.setLocation(100, 100);
win.setVisible(true);
contentPane = win.getContentPane();
g = (Graphics2D)contentPane.getGraphics();
g.setColor(Color.BLUE);
g.drawRect(50, 50, 100, 30);
g.setColor(Color.RED);
g.fillRect(175, 50, 100, 30);
win.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
I also tried outputting a line instead of rectangles. I am using the Eclipse IDE; but I have also tried it with the command prompt, which worked correctly maybe half of the time, better than with Eclipse. I've also copied code directly from a textbook, and it did not work.
Thanks a lot.
Davy

