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

My Frame is not repainting itself after SWING conversion  RSS feed

 
Derril Filemon
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Guys,
PLEASE HELP!!!
Hope you can help me out... been sitting with this problem for a few days now
I'm a java rookie.
I'm trying to convert this 3D AWT calculator to Swing. So far i managed to change all the AWT components to Swing components. But the problem i have is that everytime i start the application i get a gray screen .The moment i slide my mouse over the gray screen, the buttons start appearing one by one.. what am i doing wrong ???.. the code i'm talking about is attatached to this message. i would really appreciate some help with this. The calculator has 9 classes in it's package..

===============================================
CLASS 1
===============================================



======================================================
CLASS 2
======================================================



=============================================================================
CLASS 3
==============================================================================


==========================================================================================
CLASS 4
==========================================================================================


===========================================================================================
CLASS 5
===========================================================================================



================================================================================
CLASS 6
=================================================================================




==================================================================================
CLASS 7
==================================================================================




===================================================================================
CLASS 8
===================================================================================


====================================================================================
CLASS 9
=====================================================================================








 
Rob Spoor
Sheriff
Posts: 20893
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please Use Code Tags. In the current form, it's impossible to read your post. Also, try to focus on the problem: http://faq.javaranch.com/java/IsolateTheProblem
 
Campbell Ritchie
Sheriff
Posts: 53734
127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Unfortunately, the code quoted is too long to go through. Even after adding code tags as Rob suggested, it is difficult to understand. You have other problems; you have something null which oughtn't to be.
 
Rob Spoor
Sheriff
Posts: 20893
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I do see one problem: you forget to call super.paint(g) in your paint methods.
 
Rob Camick
Ranch Hand
Posts: 2752
11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Prime wrote:I do see one problem: you forget to call super.paint(g) in your paint methods.


Then that would be two problems since custom painting should be done in the paintComponent() method, in which case you need to call super.paintComponent(...).

This is one of the differences between AWT and Swing.
 
Rob Spoor
Sheriff
Posts: 20893
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know, but even if you do override paint it will still work if you call super.paint(g). The biggest difference is that any painting in paintComponent will be covered by the painting of the children etc, whereas the painting in paint will cover all other painting.
 
Rob Camick
Ranch Hand
Posts: 2752
11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Prime wrote:I know, but even if you do override paint it will still work if you call super.paint(g). The biggest difference is that any painting in paintComponent will be covered by the painting of the children etc, whereas the painting in paint will cover all other painting.


Which is fine if it is done as a concious decision.

Along the same line I just noticed that the update() method is also overriden. Again this is an AWT trick and should NOT be done with Swing.

I also see some code attempting to draw 3D Borders. I did not look at the code in detail, but this is something that should probably be converted to use Swing Borders. This could result in problems if you don't override the paintComponent(...) method.

Also, references to the Canvas class should be replaced with JPanels so painting is done properly.

So within the context of converting from AWT to Swing I believe proper Swing techniques should be mentioned otherwise old AWT tricks are carried forward which will ultimately lead to problems down the road.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!