我实在是看不出问题,但是问题却是很大,请高手参详,
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class random extends JApplet implements ActionListener
{
JLabel oneLabel,twoLabel,threeLabel,fourLabel,fiveLabel,
sixLabel,sevenLabel,eightLabel,nineLabel,tenLabel,
elevenLabel,travelLabel;
JTextField oneField,twoField,threeField,fourField,fiveField,
sixField,sevenField,eightField,nineField,tenField,
elevenField,travelField;
JButton DiceButton;
int Dice = 0;
int a[] = new int [13];
public void init ()
{
Container container = getContentPane();
container.setLayout ( new FlowLayout () );
oneLabel = new JLabel ( "出现1的次数:" );
container.add ( oneLabel );
oneField = new JTextField ( 10 );
container.add ( oneField ) ;
oneField.setEditable ( false );
twoLabel = new JLabel ( "出现2的次数:" );
container.add ( twoLabel );
twoField = new JTextField ( 10 );
container.add ( twoField );
twoField.setEditable ( false );
threeLabel = new JLabel ( "出现3的次数:" );
container.add ( threeLabel );
threeField = new JTextField ( 10 );
container.add ( threeField );
threeField.setEditable ( false );
fourLabel = new JLabel ( "出现4的次数:" );
container.add ( fourLabel );
fourField = new JTextField ( 10 );
container.add ( fourField );
fourField.setEditable ( false );
fiveLabel = new JLabel ( "出现5的次数:" );
container.add ( fiveLabel );
fiveField = new JTextField ( 10 );
container.add ( fiveField );
fiveField.setEditable ( false );
sixLabel = new JLabel ( "出现6的次数:" );
container.add ( sixLabel );
sixField = new JTextField ( 10 );
container.add ( sixField );
sixField.setEditable ( false );
sevenLabel = new JLabel ( "出现7的次数:" );
container.add ( sevenLabel );
sevenField = new JTextField ( 10 );
container.add ( sevenField ) ;
sevenField.setEditable ( false );
eightLabel = new JLabel ( "出现8的次数:" );
container.add ( eightLabel );
eightField = new JTextField ( 10 );
container.add ( eightField );
eightField.setEditable ( false );
nineLabel = new JLabel ( "出现9的次数:" );
container.add ( nineLabel );
nineField = new JTextField ( 10 );
container.add ( nineField );
nineField.setEditable ( false );
tenLabel = new JLabel ( "出现10的次数:" );
container.add ( tenLabel );
tenField = new JTextField ( 10 );
container.add ( tenField );
tenField.setEditable ( false );
elevenLabel = new JLabel ( "出现11的次数:" );
container.add ( elevenLabel );
elevenField = new JTextField ( 10 );
container.add ( elevenField );
elevenField.setEditable ( false );
travelLabel = new JLabel ( "出现12的次数:" );
container.add ( travelLabel );
travelField = new JTextField ( 10 );
container.add ( travelField );
travelField.setEditable ( false );
DiceButton = new JButton ( "开始" );
container.add ( DiceButton );
DiceButton.addActionListener ( this );
}
public void actionPerFormed ( ActionEvent actionevent )
{
for ( int i=0;i<3600;i++ )
{
Dice = sumDice ();
a[Dice]++;
}
display (a) ;
}
public int sumDice ( )
{
int die1 = 1 + ( int )( Math.random()*6 ),
die2 = 1 + ( int )( Math.random()*6 ),
sum = die1 + die2;
return sum;
}
public void display (int b[])
{
oneField.setText ( Integer.toString ( b[1] ) );
twoField.setText ( Integer.toString ( b[2] ) );
threeField.setText ( Integer.toString ( b[3] ) );
fourField.setText ( Integer.toString ( b[4] ) );
fiveField.setText ( Integer.toString ( b[5] ) );
sixField.setText ( Integer.toString ( b[6] ) );
sevenField.setText ( Integer.toString ( b[7] ) );
eightField.setText ( Integer.toString ( b[8] ) );
nineField.setText ( Integer.toString ( b[9] ) );
tenField.setText ( Integer.toString ( b[10] ) );
elevenField.setText ( Integer.toString ( b[11] ) );
travelField.setText ( Integer.toString ( b[12] ) );
}
}