Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

container Repaint problem

 
shukla raghav
Ranch Hand
Posts: 203
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my application i am using the same window and change the components at various button events using remove(),revalidate() and repaint().

in this code i am i have three different methods

1. initialWindow()
2. actionPerformed() in SubmitHandler class (inner class to SCJPTestApplication class)
3. actionPerformed() in BeginTest class (inner class to SCJPTestApplication class)

the initialWindow () method displays the initial window which asks the user to select and submit the chapter from which he/she expects the test. On clicking the submit button on the initial window the actionPerformed method in the SubmitHandler listener class is invoked which removes the current components, revalidates, adds new components (a button called "Begin Test" and a label showing the chapter name selected for the test). DURING THE RUN THE PROGRAM WORKS PERFECTCLY TILL THIS POINT.

Clicking the "Begin Test" button calls the actionPerformed() in the BeginTest class which removes the current components, adds new ones (a non-editable JTextpane holding the current question, few radiobuttons for options, and the submit button) and repaints the JPanel holding the components. The problem is that the window does not get Repainted. I have put several println() statemnts to check on the console if this actionPerformed method in the BeginTest class is executing. On the console it shows complete execution of the actionPerformed method. but the window is not repainted. I dont know why below given is the code.



i have put various println() statements to check on the console if the action
>
 
Maneesh Godbole
Saloon Keeper
Posts: 11092
13
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why reinvent the wheel?
Check out CardLayout
 
shukla raghav
Ranch Hand
Posts: 203
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes you are right, why reinvent the wheel, bbut you see hidden within these problem and queries are immense treasures of knowledge i am a newbee for javax.swing and wish to take up the right approach not a quick-fix approach. i just wish to know the reason why ?
 
Stanislav Lapitsky
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Regards,
Stas
 
shukla raghav
Ranch Hand
Posts: 203
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Stanislav, i hv done that also. but the real problem is something else and i have figured it out. I m using the same button object called "submit" and registering with two different ActionListeners. This is the problem. Its more important to find out the mechanics of ActionListeners to know why does this turn into a DeadLock. Good Question
 
Stanislav Lapitsky
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Create a fields for both listeners and add/remove appropriate one when necessary.

Regards,
Stas
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic