This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
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


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "simple painting... really confusing..." Watch "simple painting... really confusing..." New topic
Author

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: 9993
    
    7

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: http://aspose.com/file-tools
 
subject: simple painting... really confusing...
 
Similar Threads
Rectangle Not coming+swing
JAVA GUI Problem
Tree and drawing within the same panel
need help with graphics problem
JPanel and setOpaque method