• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

AWT Event look for help

 
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
(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
Posts: 117
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
very helpful, thank you very much
 
Hui Zhao
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Craig, please help me again.
My more complex code, JSlide is still not working.
 
Hui Zhao
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 117
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic