It's not a secret anymore!
The moose likes Swing / AWT / SWT and the fly likes simple painting... really confusing... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "simple painting... really confusing..." Watch "simple painting... really confusing..." New topic

simple painting... really confusing...

Jhedzkie Skies
Ranch Hand

Joined: Oct 28, 2009
Posts: 118
hi there. i am trying to do a gantt chart off java.awt.Graphics...

i found a very simple class for paint

that is used with an applet...

now, i am trying to do it inside a JFrame. but, i am really confused on how to do it.

i tried to get make the same output that the applet displays but this time inside the JFrame. but it only shows up the frame without the painted rects.

please help..
Bartek Myszkowski
Ranch Hand

Joined: Feb 03, 2009
Posts: 44
first idea I've got:
in the last sourcecode attached, in line 7 You have method called rawr() where You add components to JFrame but You never invoke this method so it's never added to JFrame - am I right?
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10825

Please use real words. "rly" is not a word.

Overall you are doing good.

1) Like Bartek said, you are never invoking the rawr(). After the line where you set the close operation would be suitable.
2) The setVisible should logically be the last line in your mail. In general, initialize, set attributes like icon,title etc, add children and make visible is the way to go.
3) You do not need the repaint. When you add any child to the parent before the call to visible, it draws itself. No need to explicitly invoke the repaint.
4) You got one duplicated call to setVisible in the rawr. You dont need that either, as you are going to make it visible from your main.

You also need to build and show the GUI on the EDT. Typically one should use the SwingUtilities#invokeLater. I will leave it as a search exercise for you to figure out why it needs to be done this way.

[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Jhedzkie Skies
Ranch Hand

Joined: Oct 28, 2009
Posts: 118
oh hi. thank you both very much, i get it now. what i am doing wrong.

it shouldn't be a method. that should be the constructor.. to be like

also, i did tried to implement the swing utilities and its working good.

thank you again.
I agree. Here's the link:
subject: simple painting... really confusing...
It's not a secret anymore!