Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Making a JFrame's Title Dynamic

843806Sep 24 2007 — edited Sep 25 2007
I want to have a little spinning thing in the title of the window/frame, but I always get "null" for some reason. Taking out the sleeps don't work. :( You'll see what I mean when you look at the source.

I apologise for the messed up code, the forums are weird and what happened to the code tags?? I marked the important stuff concerning this question with "<"s.
import java.awt.Color;
import javax.swing.*;
public class Main extends JFrame { 
public static void main(String [] cheese) throws InterruptedException {
new Main(); // Create a new instance of main.
}
JPanel panel_backround = new JPanel(); // This panel is used for a grey backround.
String loading_animation;
public Main() throws InterruptedException {
this.setSize(640, 480); // I like these dimensions for the window.
this.setLocationRelativeTo(null); // Start in the center of screen.
this.setResizable(false); //Do not allow resizing ***this will change later
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Exit when the X is pressed
this.setTitle("Loading... " + loading_animation); // I want this dynamic <<<<<<<<<<<<<<<
panel_backround.setBackground(Color.LIGHT_GRAY); //sets a light grey backround ***consider making this an image later.
this.add(panel_backround); // Add the grey panel to the frame.
this.setVisible(true); // make the window visible.

for(int cnt = 0; cnt < 50; cnt++ ) { // my amazing for loop <<<<<<<<<<<<<<<<<<
loading_animation = "-";
Thread.sleep(500);
loading_animation = "\\";
Thread.sleep(500);
loading_animation = "|";
Thread.sleep(500);
loading_animation = "/";
Thread.sleep(500);
}
}
}
{code}
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 23 2007
Added on Sep 24 2007
3 comments
463 views