DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2006

    Java Beginner Problem

    I am doing a homework and stuck. After reading several tutorials, I still have no idea of how to do it. There is no tutorial that teach exactly what I am doing. The comments highlighted below is the code that I have to write.

    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;

    // Random is-a JApplet, using certain Event Listener
    public class Randomizer
    JLabel myLabel;
    JButton myButton;

    public void init()

    // Create a JLabel with initial value: "1-100"

    // Set JLabel horizontally aligned

    // Create a JButton with word "Randomize" on it

    // set GridLayout

    // add the label in the container

    // add the button in the container

    // associate the any listener with current object


    public int generateRandomNumber() {
    int val = (int)(100*Math.random() + 1); // Range 1-100
    return val;

    public void actionPerformed (ActionEvent e)
    // update the displaying text (the random number) on the jlabel


    I am not asking you to do all the code for me. I just want some hints. Anyone can give me hints to do it? Any help is appreciated.
    Last edited by TheDictator; 04-28-2006 at 11:56 AM.

  2. #2
    Join Date
    Oct 2005
    those comments tell you exactly how to do it.

    where are you stuck?

    first off you might want to extend JApplet

    myLabel = new JLabel("1-100");

    myButton = new JButton("Randomize");



  3. #3
    Join Date
    Mar 2005
    UK, London
    then just do myLabel.setText("" + randomNUmber);

Similar Threads

  1. Replies: 3
    Last Post: 03-21-2007, 03:28 PM
  2. java problem
    By Morgan in forum Java
    Replies: 2
    Last Post: 04-18-2005, 03:22 PM
  3. java problem
    By KateP in forum Java
    Replies: 2
    Last Post: 04-30-2003, 05:52 PM
  4. Replies: 0
    Last Post: 02-20-2002, 12:05 AM
  5. problem with java frames URGENT!!!!
    By ramanand in forum Java
    Replies: 0
    Last Post: 10-17-2000, 05:34 AM

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
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

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

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.