Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help in a simple fan project

 
Roger Fed
Ranch Hand
Posts: 82
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello every one i need help in this simple program
I encounter two problems when running this program
first, the close button doesn't work although i write a line to handle this

second, when i maximize the window the fan doesn't fit the window
I'd be grateful if you help me and i will be very happy i you give me your notes to improve my simple project
I haven't large experience in java but i try to learn
thanks............
this is the code
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15356
39
Android IntelliJ IDE Java Scala Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your code doesn't compile; in line 85 there is a variable fa that is not declared anywhere.

The reason why your code doesn't work properly is this: The Swing toolkit for making GUIs uses threads in a specific way. The most important thread to be aware of is the event dispatch thread, on which Swing will run all painting code and all callbacks to handle events such as button clicks.

Your paint() method never returns - it contains a never ending loop in lines 72 - 98. That means that you block the event dispatching thread forever, so that your program cannot react to events anymore, such as resizing or closing the window.

To make your program run smoothly, you must always make sure that things that run on the event dispatch thread return as quickly as possible. You must put the code from lines 72 - 98 somewhere else, and not inside the paint() method or another method that runs on the event dispatch thread.
 
Roger Fed
Ranch Hand
Posts: 82
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm very sorry this line included by mistake
thank you for your help
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic