Meaningless Drivel is fun!*
The moose likes Swing / AWT / SWT and the fly likes AWT Event look for help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "AWT Event look for help" Watch "AWT Event look for help" New topic
Author

AWT Event look for help

Hui Zhao
Ranch Hand

Joined: Jul 09, 2007
Posts: 116
Hi, I want control my graph by select JSlider and Comboxbox such as zoom or so. But the working is obvious wrong.
The problem has two:
(1) when I moved JSlider, the new picture would replace the old picture whatever zoom in or out.
That is my expection. but in my program, many pictures occuried like animation. I guess probably I used repaint(). I don't know how to treat it.
(2) When I choose an item from the Combobox, the whole picture color would be changed because I fired an integer number "id" event to the method in class Drawing.

Thanks
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
(1) when I moved JSlider, the new picture would replace the old picture whatever zoom in or out. That is my expection. but in my program, many pictures occuried like animation
If the enclosing JPanel is opaque then you must make arrangements to fill its entire background each time its paintComponent method id called. An easy way to do this is with a call to super.paintComponent.
(2)When I choose an item from the Combobox, the whole picture color would be changed
You have to tell the Drawing class that you want to change the color it uses.
because I fired an integer number "id" event to the method in class Drawing.
Not exactly. The JComboBox generated an ActionEvent from user interaction and we can monitor this in the listener to find out what the user selected. We can query the comboBox for the user selection and use this information to select a corresponding Color and then tell the Drawing class to change to this new Color.
Hui Zhao
Ranch Hand

Joined: Jul 09, 2007
Posts: 116
very helpful, thank you very much
Hui Zhao
Ranch Hand

Joined: Jul 09, 2007
Posts: 116
Craig, please help me again.
My more complex code, JSlide is still not working.
Hui Zhao
Ranch Hand

Joined: Jul 09, 2007
Posts: 116
I want to pass two 2D array to a defined method in class "Drawing" then to plot a gemeotry. The arrays are initialized by reading a text file.
Do I pass array within init() then pass them with the events?

Thanks
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
Without the TestCell class and the data it makes available I was unable to try your class.
I did observe something that might be causing some trouble. When you call the setScale
method in Drawing it scales the data in xCells and yCells. On the next repaint this data is
re-computed/reset in the getDrawingData method without any scale factor. You might consider
either calling getDrawingData only one time (you could call it again for componentResized
events) or incorporating a scale factor (member variable) in it to do the scaling.

I want to pass two 2D array to a defined method in class "Drawing" then to plot a
gemeotry. The arrays are initialized by reading a text file.
Do I pass array within init() then pass them with the events?

I would try to read the data from the applet on startup, eg, call a method in your applet
from within init that would read the data and then pass the data to the Drawing
class through its constructor. You could use a setData method, especially if you
plan to change the data during runtime.
Hui Zhao
Ranch Hand

Joined: Jul 09, 2007
Posts: 116
Hi, I am ashamed to bother you again.
Because pass a 2D array is really inconvince. The length of arrays are dynamicly generated by call TestCell class. So I used to clone array to avoid recompute and I just use one class. However the clone is wrong, Could you help me look again?

Thanks so so much.
Best Regardsss!

Also I attached with the TestClass code for reference.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: AWT Event look for help
 
Similar Threads
JSlider is not working.
Components size
JSlider is not working.
Events listener are not working.
put an applet into a web page