DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2006
    Posts
    1

    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
    Posts
    107
    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");

    ...

    myButton.addActionListener(this);

  3. #3
    Join Date
    Mar 2005
    Location
    UK, London
    Posts
    150
    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

Bookmarks

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


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links