File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

simple painting... really confusing...

 
Jhedzkie Skies
Ranch Hand
Posts: 118
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 44
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10976
11
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jhedzkie Skies
Ranch Hand
Posts: 118
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic