File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes Help in a simple fan project Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Help in a simple fan project" Watch "Help in a simple fan project" New topic

Help in a simple fan project

Roger Fed
Ranch Hand

Joined: Oct 17, 2010
Posts: 82

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
this is the code

I Hear I Forget, I See I Remember, I Do I Understand.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 15092

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.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Roger Fed
Ranch Hand

Joined: Oct 17, 2010
Posts: 82

I'm very sorry this line included by mistake
thank you for your help
I agree. Here's the link:
subject: Help in a simple fan project
It's not a secret anymore!