Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Auto Update JLabel on JButton Press?

  1. #1
    Member
    Join Date
    Jan 2012
    Posts
    107
    My Mood
    Grumpy
    Thanks
    6
    Thanked 2 Times in 1 Post

    Default Auto Update JLabel on JButton Press?

            gen = new JButton("Generate");
            add(gen);
            gen.addActionListener(new ActionListener() {
     
                public void actionPerformed(ActionEvent e)
                {
            	    Random randomGenerator = new Random();
            	    for (int idx = 1; idx <= 1; ++idx){
            	      int randomInt = randomGenerator.nextInt(999);
     
            		test = new JLabel(""+randomInt+"");
            		add(test);
     
            	    Random randomGenerator2 = new Random();
            	    for (int idx2 = 1; idx <= 1; ++idx){
            	      int randomInt2 = randomGenerator.nextInt(999);
     
            		test = new JLabel(""+randomInt2+"");
            		add(test);
     
            	    Random randomGenerator3 = new Random();
            	    for (int idx3 = 1; idx <= 1; ++idx){
            	      int randomInt3 = randomGenerator.nextInt(9999);
     
            		test = new JLabel(""+randomInt3+"");
            		add(test);
            	    }
            	    }
            	    }
     
                }});;
            };
    }

    Really need Some help.


  2. #2
    Member
    Join Date
    Mar 2011
    Posts
    82
    My Mood
    Daring
    Thanks
    17
    Thanked 1 Time in 1 Post

    Default Re: Auto Update JLabel on JButton Press?

    please explain what are you up to?

  3. #3
    Member
    Join Date
    Jan 2012
    Posts
    107
    My Mood
    Grumpy
    Thanks
    6
    Thanked 2 Times in 1 Post

    Default Re: Auto Update JLabel on JButton Press?

    When i Press the button it dose not show it until i minimize and bring back up

Similar Threads

  1. Creating an Applet program using JTextFields, JLabel, Jbutton.
    By Maxly in forum Java Theory & Questions
    Replies: 1
    Last Post: March 9th, 2012, 01:39 PM
  2. JButton Auto-changing Reference Variable
    By bgroenks96 in forum What's Wrong With My Code?
    Replies: 6
    Last Post: June 19th, 2011, 10:57 PM
  3. Cannot update Jlabel in JApplet
    By rin in forum Java Applets
    Replies: 2
    Last Post: April 17th, 2010, 08:21 AM
  4. JApplet containing JButton and a JLabel
    By JuneM in forum AWT / Java Swing
    Replies: 3
    Last Post: March 26th, 2010, 08:32 AM
  5. Auto contrast and auto brightness
    By oxxxis in forum Java Theory & Questions
    Replies: 0
    Last Post: January 21st, 2010, 02:00 PM