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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T06:37:35+00:00 2026-05-14T06:37:35+00:00

in what way can this be programmed. a UI box that displays random number

  • 0

in what way can this be programmed.

a UI box that displays random number between min and max value for 2 seconds then shows blank for 2 seconds then shows another random numer for 2 seconds then shows blank for 10 seonds and then repeats the cycle infitely until form closed. Font of the text to be configurable.

any help at all will be appreciated.

UPDATE after feedback

this is my progress so far. simple jpanel. now how do i add random number and timer

import javax.swing.JFrame;  
import javax.swing.JPanel;   
public class RandomSlide {  

public static void main(String[]args)  
{  
//Create a JPanel  
JPanel panel=new JPanel();  

//Create a JFrame that we will use to add the JPanel  
JFrame frame=new JFrame("Create a JPanel");  
//ADD JPanel INTO JFrame  
frame.add(panel);  
//Set default close operation for JFrame  
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);   
//Set JFrame size to :  
//WIDTH : 400 pixels  
//HEIGHT : 400 pixels  
frame.setSize(400,400);  
//Make JFrame visible. So we can see it  
frame.setVisible(true);  
 }  
 }  
  • 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-14T06:37:35+00:00Added an answer on May 14, 2026 at 6:37 am

    Here is some code that will get you rolling.
    Note that you could just extend a JLabel instead of JPanel. I used JPanel based on your question. Also, note that you may use timer.setDelay() API to change the timing. Also, you could stop the timer by a stop() call.

    package answer;
    
    import java.awt.Font;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.util.Random;
    
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.Timer;
    
    public class RandomPanel extends JPanel implements ActionListener {
        private static final int TWO_SECONDS=2000;
        private static final int MAX=99999;
        private static final int MIN=0;
        private Timer timer = new javax.swing.Timer(TWO_SECONDS, this);
    
        private JLabel msgLabel;
        Random generator = new Random();
        public RandomPanel(Font f){
            msgLabel = new JLabel();
            msgLabel.setFont(f);
            msgLabel.setText(rand());
            add(msgLabel);
        }
    
        @Override
        public void actionPerformed(ActionEvent e) {
                msgLabel.setText(msgLabel.getText().equals("")?rand():"");
        }
    
        private String rand() {
            //generate random beteween MIN & MAX
            return Integer.toString((int) (MIN + Math.random() * ( MAX - MIN) + 0.5));
        }
        public void start(){
            timer.start();
        }
    
        /**
         * Rudimentary test
         * @param args
         */
        public static void main(String[] args) {
            JFrame frame = new JFrame();
            RandomPanel randomPanel = new RandomPanel(new Font("Serif", Font.BOLD, 50));
            frame.getContentPane().add(randomPanel);
            frame.setSize(400,300);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setVisible(true);
            randomPanel.start();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Any way I can get this working? I have a block of code: <p><a
is there any way I can reproduce this ruby function: def Password.hash(password,salt) Digest::SHA512.hexdigest(#{password}:#{salt}) end
Is there any way I can add this to my plugin? $this->_helper->viewRenderer->setNoRender();
Is there a way I can get this array walk with my anonymous function
The best way I can think of to ask this is by example... In
This is the best way I can think of phrasing this question, given this
I know I can use this way to find the most frequent element in
I'll try to explain this problem the best way i can with code: double
Okay I'll try describe this the best way I can. I have a chat
I have the following code. My intention that this custom object can be cast

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.