-
Creating a JButton
hi, im trying to create a jbutton where the button will allow the user to redo the program again. this program is to roll two dice and have the sum added up and list the frequencies of the sum of 2-12 poppoing out in 36000 rolls. i have gotten the program itself completed... but i do not know how to implement a jbutton.. can someone help? below is my original code, thanks.
import javax.swing.*; // Program uses JOptionPane
import java.awt.*;
import java.awt.event.*;
public class exercise7_15 extends JApplet implements ActionListener
{
JButton rollButton;
JTextArea outputArea;
public void init()
{
Container container = getContentPane();
rollButton = new JButton("Roll Again");
rollButton.addActionListener(this);
container.add( rollButton );
}
public static void main (String args[])
{
int frequency[] = new int[13];
for (int roll = 1; roll <= 36000; roll++)
++frequency[(1 + (int)(Math.random()*6)) + (1 + (int)(Math.random()*6))];
String output = "Dice Number\tFrequency";
for (int DiceNumber = 0; DiceNumber < frequency.length; DiceNumber++)
output += "\n" + DiceNumber + "\t" + frequency[DiceNumber];
JTextArea outputArea = new JTextArea();
outputArea = new JTextArea();
outputArea.setText(output);
JOptionPane.showMessageDialog(null, outputArea, "Roll Dice 36000 Times", JOptionPane.INFORMATION_MESSAGE);
}
public void actionPerformed(ActionEvent actionEvent)
{
}
}
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