math.random problem


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: math.random problem

  1. #1
    Join Date
    Sep 2006
    Posts
    1

    math.random problem

    hey, I'm fairly new to Java programming, so I was wondering if I could get a little bit of help, or direction.

    the following code works fine, but I need to edit it so that the labels are not alphabetic but numeric - so that the labels display 4 digits which are randomly initialized each time. I know I have to use math.random somehow, I'm just not sure how to apply it to my labels and such

    this is the part of the code that I know I have to change, just not sure how exactly:

    Code:
    import java.awt.*;
    import javax.swing.*;
    
    public class AnagramLabels  {
       private Label lab1, lab2, lab3;
    
       public AnagramLabels(ThreeButtons.ThreeButtonFrame w )  {
          lab1 = new Label();
           lab1.setBounds(230, 30, 200, 40);
           lab1.setFont(new Font("",Font.BOLD,30));
           lab1.setText("ABCD");
           w.add(lab1);
           w.repaint();
    
           lab2 = new Label();
           lab2.setBounds(230, 70, 200, 40);
           lab2.setFont(new Font("",Font.BOLD,30));
           lab2.setText("EFGH");
           w.add(lab2);
           w.repaint();
    
           lab3 = new Label();
           lab3.setBounds(230, 110, 200, 40);
           lab3.setFont(new Font("",Font.BOLD,30));
           lab3.setText("TABC");
           w.add(lab3);
           w.repaint();
       }  
       
    }

  2. #2
    Join Date
    Mar 2005
    Location
    Istanbul
    Posts
    10
    Math.random() returns a random number between 0 and 1(0 included,1 not included).

    (int)(Math.random()*10000)

    this phrase gives you 4 digit number.

Similar Threads

  1. Problem with Search
    By Irina in forum ASP.NET
    Replies: 0
    Last Post: 11-29-2002, 10:47 PM
  2. Replies: 0
    Last Post: 12-13-2001, 12:06 PM
  3. a problem with font and language
    By Roseta in forum VB Classic
    Replies: 0
    Last Post: 11-14-2001, 03:24 AM
  4. Arabic problem view
    By Ayman in forum VB Classic
    Replies: 0
    Last Post: 04-03-2000, 01:08 AM
  5. Problem with CryptoAPI and JCE
    By Jason Bock in forum VB Classic
    Replies: 0
    Last Post: 03-21-2000, 06:48 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center