Help - draw objects doesn't appear on JFrame

i got this code from a book...
import javax.swing.*;
import java.awt.*;
class Ch5SampleGraphics {
public static void main( String[] args ) {
JFrame win;
Container contentPane;
Graphics g;
win = new JFrame("My First Rectangle");
win.setSize(300, 200);
win.setLocation(100,100);
win.setVisible(true);
contentPane = win.getContentPane();
g = contentPane.getGraphics();
g.drawRect(50,50,100,30);
the problem is when i run the app, the frame doesn't always show the rect drawn. sometimes it shows it, but usualy not. if it does show the rect, once i click on minimize, then reopen it from the taskbar, the rect will disappear again and will never show up.
can anyone help me? i've been searching for answers but to no avail. thanks 4 reading, hope someone will offer some help.

an intoduction to oop with java
Jesus wept. The code's about as un-object-oriented as you could possibly make it.
Looking at his sample chapter on the book's web page all I see is main() methods with linear code in and just simple number crunching with primitive types. No objects to speak of at all.
I'm sticking with my "throw the book away" advice :o)

Similar Messages

Maybe you are looking for

  • HT3702 Why does it read my apple ID has been disabled when I try to download

    When I try to download an album from the iTunes store, I get a message that my apple ID has been disabled. I have a balance on my account,so I'm not sure whats going on.

  • What Compressor codec should I use for footage recorded on a Canon T3i, edited on FCP 6, and intended for Vimeo?

    I am looking for help! My planned workflow is as follows: Footage recorded on Canon Rebel T3i  --->  Edited on Final Cut Pro 6 (sequence compression is apparently H.264 according to the browser)  --->  Compressed with Compressor (ver 3.0.5) in origin

  • Down payment issue

    one of Vendor  has a down payment which is a debit balance on their account, however other invoices that are due came into payment proposal to issue a check.  Customer had to manually block the invoice documents so payment would not generate.  Does n

  • Issue in OA Adapter

    hi I am trying to invoke OE_ORDER_PUB.PROCESS_ORDER API using OA Adapter. Its a simple BPEL process that takes data from the console and calls Order API. I am tryng to test it from em console but unable to expand TableType variables to populate data

  • PB won't automatically sleep ...

    unless I do it manually. Power adapter settings are set to put the computer to sleep automatically in 15 min. and the display in 5 min. The display always sleeps correctly, but not the computer. I checked to see if anything (to my limited knowledge)