I was thinking if it would be possible to create a JFrame, and make the title of it to change, such as make the title work as a counter that will display some text like:
The window was opened for 1 second.
The window was opened for 2 second.
The window was opened for 3 second.
The window was opened for 4 second.
The window was opened for 5 second.
The window was opened for 6 second.
The window was opened for 7 second.
Here is the code I have so far:
import javax.swing.JFrame;
class WindowFrame {
public static void main (String args[]){
JFrame myWindow = new JFrame();
// 1. declare and initialise variables
int counter = 1;
// 2. now do the while loop
while(counter < 5000 )
{
System.out.println("counter is equal to " + counter);
// 3. add 1 to the value of counter
counter = counter + 1 ;
}
// 4. the while loop has finished,
//so program continues on to here
System.out.println("Goodbye");
String myTitle = (counter);
myWindow.setTitle( myTitle);
myWindow.setSize(777, 333);
myWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
myWindow.setVisible(true);
}
}
But when I compile there is an error:
WindowFrame.java:24: error: incompatible types
String myTitle = (counter);
^
required: String
found: int
1 error
Is it possible for the requirement of String not to be fulfilled? Instead use an int?