• Post Reply Bookmark Topic Watch Topic
  • New Topic

Something wrong - Paint?

 
Stephen Donovn
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all

Hope someone can help. Totally new to Java.

I'm running the code below which compiles ok using latest version of Java and on Sublime. The problem when it complies the output screen is blank and I can only see the text by adjusting the size of the box with my mouse - and then it colours in black. Code and screenshot below. Is there something wrong with the paint/graf part of the code?

Appreciate any help.

Thanks

Steve
Screenshot 1.png
[Thumbnail for Screenshot 1.png]
Screenshot 2.png
[Thumbnail for Screenshot 2.png]
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch!

In future, while posting code, please UseCodeTags. I have added them this time for you. As you can see the tags make the code much more easier to read and understand.

The recommended way of custom painting in Swing is by overriding the paintComponent(Graphics g); More on it here http://docs.oracle.com/javase/tutorial/uiswing/painting/
Also, the first call inside this method should be to invoke super.paintComponent(g);
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok. Just noticed this. You are trying to paint on the JFrame instance itself. The recommended way is to subclass a JPanel, override the paintComponent and add this panel to the JFrame
 
Campbell Ritchie
Marshal
Posts: 52580
119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome again. This discussion would fit better into our GUIs forum, so I shall move it.
 
Stephen Donovn
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks the replies. I'm week 4 into my course so appreciate the help. Will try what's been suggested.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!