Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Swing Graphics help  RSS feed

 
Jose Parrilla
Greenhorn
Posts: 5
Java Python Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Greg Charles
Sheriff
Posts: 3014
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jose, welcome to Java Ranch!

In the future, please use code tags when posting code samples to the forum. That makes the code much easier to read. I've added them for you here.

The problem here is you've asked for help, but you haven't asked a question. Does this code not compile, does it crash at run time, or it just doesn't do what you expect it to do? You need to give us some idea what help you need.
 
Jose Parrilla
Greenhorn
Posts: 5
Java Python Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anyone test this code on and tell me if the window that pops up takes a screenshot of your screen. When I run this its suposed to show a rectangle and "Hello World" in the window instead when I run it the window shows the rectangle and the text but it takes a screenshot of the background(eclipse) and places it on the window as if I set an ImageIcon with JLabel.
 
Jose Parrilla
Greenhorn
Posts: 5
Java Python Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Greg! Im new here and I also just posted my problem.
 
Rob Camick
Ranch Hand
Posts: 2753
11
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The big problem is that you don't invoke super.paint(g) at the start of the paint() method. So you are breaking the default painting functionality.

However this is not the final solution:

Don't override the paint() method of a JFrame.

Instead, custom painting is done by overriding the paintComponent() method of a JPanel. Then you add the panel to the frame.


This is not the only problem with your code. Read the section from the Swing tutorial on Custom Painting for more information and examples that will show you how to better structure your code to follow Swing standards.

That is download the demo code from the tutorial and start with a working example. Then change the painting code but keep the structure of the program.

 
Jose Parrilla
Greenhorn
Posts: 5
Java Python Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, Rob that fixed the problem.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!