-
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.
-
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);
-
then just do myLabel.setText("" + randomNUmber);
Similar Threads
-
Replies: 3
Last Post: 03-21-2007, 03:28 PM
-
Replies: 2
Last Post: 04-18-2005, 03:22 PM
-
Replies: 2
Last Post: 04-30-2003, 05:52 PM
-
By Allan Huang in forum Java
Replies: 0
Last Post: 02-20-2002, 12:05 AM
-
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
Forum Rules
|
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
|
Bookmarks