Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6554527
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:42:39+00:00 2026-05-25T12:42:39+00:00

–EDIT– I have got a welcome window consisting of two JLabels. It has a

  • 0

–EDIT–
I have got a welcome window consisting of two JLabels. It has a link to a timer counting from 3 to 0. After that time, a new window, “UsedBefore”, containing JLabel and radio buttons should automatically appear in the place of the previous one. When I run the “Launcher”, the first window shows up with counter displaying 3,2,1,0 and then nothing happens.

I think the problem lies in poor referencing, but I’m not sure. I’ve got “Launcher” class:

public static void main(String[] args) {

    javax.swing.SwingUtilities.invokeLater(new Runnable() {

        public void run() {
            Welcome window = new Welcome();
            window.setVisible(true);
        }
    });

} // end main

Where I launch the “Welcome” window:

public Welcome() {
    init();
}

public void init() {

    // here I'm adding stuff to the window and then I have:     

    setLayout(cardLayout);
    add(big, "1welcome");
//  UsedBefore.MakeUsedBeforeWindow(); // ???
    new MyTimer(this).start();

} // end init

this goes to MyTimer which does the countdown and:

 welcome.showNextWindow(); // private Welcome welcome;

we go back to the “Welcome” class:

public void showNextWindow() {
    cardLayout.next(this);
}

public static void main(String[] args) {
    java.awt.EventQueue.invokeLater(new Runnable() {
        public void run() {
            createAndShowGUI();
        }
    });
}

private static void createAndShowGUI() {
    JFrame frame = new JFrame("My Frame");
    frame.getContentPane().add(new Welcome());
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(550, 450);
    frame.setResizable(false);
    frame.pack();
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
}

and finally the “UsedBefore” class:

public UsedBefore() {           
        super(new BorderLayout());
        init();         
    }

    public void MakeUsedBeforeWindow() {            

        String q = "Have you used GUI before?";
        JPanel area = new JPanel(new BorderLayout());
        add(area, "2usedBefore?");
        area.setBackground(Color.white);
        JLabel textLabel = new JLabel("<html><div style=\"text-align: center;\">"
                + q + "</html>", SwingConstants.CENTER);
        textLabel.setForeground(Color.green);
        Font font = new Font("SansSerif", Font.PLAIN, 30);
        textLabel.setFont(font);
        textLabel.setBorder(new EmptyBorder(0, 0, 250, 0)); //top, left, bottom, right
        area.add(textLabel, SwingConstants.CENTER);
        add(area, "2usedBefore?");          
    }

with its main:

        public static void main(String[] args) {
        //Schedule a job for the event-dispatching thread:
        //creating and showing this application's GUI.
        javax.swing.SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                createAndShowGUI();
            }
        });
    }

public static void createAndShowGUI() {
        //Create and set up the window.
        JFrame frame = new JFrame("RadioButtons");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        //Create and set up the content pane - not sure how to do it
//          JComponent newContentPane = new UsedBefore();
//          newContentPane.setOpaque(true); //content panes must be opaque
//          frame.setContentPane(newContentPane);
//          frame.getContentPane().add(new UsedBefore());

        //Display the window.
        frame.setSize(550, 450);
        frame.setResizable(false);
        frame.pack();
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
        }

That’s quite a journey. Sorry for a lot of code, I hope the path is clear. Once I’ve got 1->2->3 links right, I should be able to do the rest of them, so any help is appreciated. Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T12:42:39+00:00Added an answer on May 25, 2026 at 12:42 pm

    I suggest a slightly different approach. Why not building JPanel instead of Windows and adding/removing these JPanel at the desire time.

    Ex (here welcome panel is shown first with its decreasing counter and when the counter reach 0, other panel is shown):

    public class T extends JFrame {
    
    private int couterValue = 3;
    private JPanel welcome;
    private JLabel counter;
    
    private JPanel other;
    private Timer timer;
    
    public T() {
        setDefaultCloseOperation(EXIT_ON_CLOSE);
    
        buildWelcomePanel();
        buildOtherPanel();
    
        add(welcome);
        setSize(550, 450);
        setLocationRelativeTo(null);
        setVisible(true);
    
        timer = new Timer();
        timer.schedule(new TimerTask() {
    
            @Override
            public void run() {
                if (couterValue == 0) {
                    timer.cancel();
                    // Switch the panels as the counter reached 0
                    remove(welcome);
                    add(other);
                    validate();
                } else {
                    counter.setText(couterValue + ""); // Update the UI counter
                    couterValue--;
                }
            }
        }, 0, 1000);
    
    }
    
    private void buildWelcomePanel() {
        welcome = new JPanel();
        counter = new JLabel();
        welcome.add(counter);
    }
    
    private void buildOtherPanel() {
        other = new JPanel();
        JLabel otherStuff = new JLabel("Anything else ...");
        other.add(otherStuff);
    }
    
    public static void main(String[] args) {
        new T();
    }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got the following login script.. <?php $name = $_POST[name]; $password = $_POST[password]; $query
So to start, I have an array of XML files. These files need to
Have a webpage that will be viewed by mainly IE users, so CSS3 is
Welcome to Spring Roo. For assistance press CTRL+SPACE or type hint then hit ENTER.
I am reading some og tags from sites but I can't seem to decode
I have a simple restful service that transforms a JAXB-anntotated beans to response XML
i have this code: <?php $valid_ext = array(pdf, doc); $args = array( 'post_type' =>
My "em dash" character is shown differently on two servers. When I visit Server
i have a text file with the following data: Calculated Concentrations 30.55 73.48 298.25
My NSXMLParser breaks on this string: <title>AAA &#8211; BCDEFGQWERTYUIO</title> I parsed it in this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.