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 8826869
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T07:14:56+00:00 2026-06-14T07:14:56+00:00

I’m trying to write a Java applet that will display a user-inputted String, it

  • 0

I’m trying to write a Java applet that will display a user-inputted String, it should then flash the string by switching between that and another one. I’m trying to use a thread to do this, but I’m new to those and Applets, I don’t know what to do from here on out.

here’s what I have so far:

public class FlashingLabel extends JApplet implements Runnable
{
String blank;
String input;
JLabel label; 
Thread t;



public void init() 
{
    input = JOptionPane.showInputDialog(null, "Enter String", "Flashing Label",   JOptionPane.QUESTION_MESSAGE);
    blank=" ";

    t=new Thread(this);
    t.start();
}

public void run() 
{
    while(true)
    {
        label=new JLabel(blank);
        add(label);
        this.repaint();
        label=new JLabel(input);
        add(label);
        this.repaint();
    }
}
}
  • 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-06-14T07:14:57+00:00Added an answer on June 14, 2026 at 7:14 am
    • Never do anything within the Event Dispatching Thread that will block it (long running tasks or IO), it will make your application look like it’s hung.
    • Never create or update any UI component from any thread other then the Event Dispatching Thread
    • There’s no need create new JLabels each time you want to update the message, simple use JLabel#setText. You’re code is currently adding two new labels on each loop through

    For you’re needs, a simple javax.swing.Timer will perform the task you are trying to achieve.

    public class FlashApplet extends JApplet {
    
        @Override
        public void init() {
            EventQueue.invokeLater(new Runnable() {
                @Override
                public void run() {
                    try {
                        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
                    } catch (ClassNotFoundException ex) {
                    } catch (InstantiationException ex) {
                    } catch (IllegalAccessException ex) {
                    } catch (UnsupportedLookAndFeelException ex) {
                    }
    
                    setLayout(new BorderLayout());
                    add(new FlashPane());
    
                }
            });
        }
    
        @Override
        public void start() {
        }
    
        public static class FlashPane extends JPanel {
    
            protected static final String[] MESSAGES = {"Bad Boys", "What you gonna do"};
    
            private Timer flashTimer;
            private JLabel label;
            private int messageIndex = -1;
    
            public FlashPane() {
                setLayout(new BorderLayout());
                add((label = new JLabel()));
                label.setHorizontalAlignment(JLabel.CENTER);
    
                flashTimer = new Timer(500, new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        messageIndex++;
                        if (messageIndex >= MESSAGES.length) {
                            messageIndex = 0;
                        }
                        label.setText(MESSAGES[messageIndex]);
                    }
                });
                flashTimer.setRepeats(true);
                flashTimer.setCoalesce(true);
                flashTimer.setInitialDelay(0);
                flashTimer.start();
            }
    
        }
    
    }
    

    You might like to have a read through Concurrency in Swing

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm trying to create an if statement in PHP that prevents a single post
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.