I just edited my post - seems I came up with the same thing somehow :-). I will put a bit more thinking into what I did (and you suggested) and will go from there :-). Thanks a lot!
Thanks for the quick reply. I am a complete novice (read only 3 chapters from a Java book) in this so my questions may seem weird. I know I need to read more before going into "difficult" things like this but just want to try to see how it works and then will understand it completely :-)
I changed to JApplet and JTextField.
OK, the "Instead of adding components to the applet, add them to a JPanel and then add the panel instance to the applet using the JApplet#getContentPane()#add method" part first:
1. I added "private JPanel myPanel;" in line 5
2. I replaced lines 25, 26 and 27 with "myPanel.add(inputLabel); myPanel.add(sizeVariable); myPanel.add(doButton);
The "You should be overriding the paintComponent(Graphics g) method of the JPanel instead of paint " I kind of understand as "I should not be adding anything to the paint method of the JApplet itself but instead to the paintComponent method of the JPanel. I tried and added this at the end of my code:
Then "TestPanelClass myPanel = new TestPanelClass();" before the add() operations and "getContentPane().add(myPanel);" after the add operations of line 25-27;
This compiles and I see the red circle. But I do not know how to use all this in the actionPerformed part of the program...
edit: I think I got this :-). I declared the variable size at the begining of the class and then in actionPerformed was calling redraw() and in the declaration of my class the size was used to set the color of the circle. I don't understand exactly what I did but it looks promising.
I am trying to write a program that reads the number from a TextField and draws a circle with that size and color depending on the size (e.g. if size is between 10 and 20 - make it red, otherwise green). I was able to display the input box and a button to perform the action:
But a few problems show up:
1. if I add a
everything but the input box disappears.
2. I am not sure how to "draw" from within the actionPerformed context as it is not like the paint(Graphics page) as I don't "have" a page :-)