Which part don't you understand?
create instances of the ActionListener classes:
For example: AClass ac = new AClass();
Use those instances in the calls to the Timer constructor
... new...
Type: Posts; User: Norm
Which part don't you understand?
create instances of the ActionListener classes:
For example: AClass ac = new AClass();
Use those instances in the calls to the Timer constructor
... new...
The code needs to create instances of the classes and use them in the Timer constructors.
Where is the separate listener for the second timer? You can't makeup names for listener methods. This method is not used for anything:
public void actionPerformed2(ActionEvent e)
You should...
The second timer MUST have its own action listener method. It should not share a listener.
In its listener showMsg can be set false.
If showMsg is true the message should be drawn
If showMsg is false the message should not be drawn
showMsg will stay true until the one sec timer's listener method sets it false
You'll have to...
What is the second part?
Drawing an empty String seems a waste of time.
You don't need the == true with a boolean variable. The variable itself has a value of true or false.
if(showMsg)
A boolean is simpler.
NOTE: The code does not need to test if true and then test if false
if(condition) {
// here when true
}else{
// here when false
}
Use the if statement to skip doing the draw to "clear" the message.
The way to tell a method what to do could be by setting a boolean:
boolean showMsg = true; // used to tell paint when to draw a...
Would NOT drawing the String be the same as clearing the string? Control the drawing of the String with a if statement.
There should NOT be code to start a thread every time the paint() method is...
Where are any of the techniques that were talked about? I don't see anything in this code that attempts to clear the message after some time.
If you want more help: Make a small simple program that compiles, executes and shows the problem.
Talking about techniques isn't working. We need code for testing.
Make a small simple program that compiles, executes and shows the problem.
Not at all. I was only talking about code in the paint() method.
If you draw the same message two times, the first with a different color than the background and the second with the same color as the background, I'd think you'd see the results of the first drawing...
If you don't call the drawString() method the String won't be drawn.
If you do call drawString() the String will be drawn (It will be visible if the color is different from the background color)
To clear the message, don't draw it when the paint() method is called.
Use a Timer.
Show message
Start timer for desired time
when timer calls its listener, clear message