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.
(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.
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?
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.
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.