| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 416 人关注过本帖
标题:为什么这个程序就是运行不了?
只看楼主 加入收藏
光明左使
Rank: 1
等 级:新手上路
帖 子:66
专家分:0
注 册:2006-8-16
收藏
 问题点数:0 回复次数:4 
为什么这个程序就是运行不了?

我实在是看不出问题,但是问题却是很大,请高手参详,
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] ) );
}
}



搜索更多相关主题的帖子: 运行 
2006-10-09 21:33
无理取闹
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:53
帖 子:4264
专家分:0
注 册:2006-7-26
收藏
得分:0 
什么问题?说清楚

win32汇编
病毒 加密
目前兴趣所在
2006-10-09 21:37
光明左使
Rank: 1
等 级:新手上路
帖 子:66
专家分:0
注 册:2006-8-16
收藏
得分:0 

好你就是说在引用了this之后,就出现了故障,我也说不清


以剑论道,以道搏剑,快意恩仇,却是何等的孤独!!
2006-10-09 22:12
无理取闹
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:53
帖 子:4264
专家分:0
注 册:2006-7-26
收藏
得分:0 
不说清楚也没法帮你了

win32汇编
病毒 加密
目前兴趣所在
2006-10-09 22:14
999hits
Rank: 1
等 级:新手上路
威 望:1
帖 子:227
专家分:0
注 册:2005-10-2
收藏
得分:0 
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import javax.swing.*;
public class JRandom extends JApplet implements ActionListener
{
JLabel label[]=new JLabel[12];
JTextField field[]=new JTextField[12];
JButton DiceButton;
int Dice=0;
int a[] = new int [12];
public void init()
{
Container container=this.getContentPane();
container.setLayout(new FlowLayout());
for(int i=0;i<12;i++)
{
label[i]=new JLabel("出现"+(i+1)+"的次数:");
container.add(label[i]);
field[i]=new JTextField(12);
container.add(field[i]) ;
field[i].setEditable(false);
}
DiceButton=new JButton("开始");
container.add(DiceButton);
DiceButton.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==DiceButton)
{
for(int i=0;i<3600;i++)
{
Dice=sumDice();
a[Dice]++;
display(a) ;
}

}
}
public int sumDice()
{
int die1=(int)(Math.random()*6);
int die2=(int)(Math.random()*7);
int sum=die1+die2;

return sum;
}
public void display(int b[])
{
for(int i=0;i<12;i++)
{
field[i].setText(Integer.toString(b[i]));
}
}

}
//<applet code=copyTest width=300 height=200></applet>
兄台的代码我看着实在难受,所以就改了一下;
主要毛病就是获取随机数的时候数组a[]越界了,因为你是从2开始的;
还有一点就是,我喜欢用数组循环赋值,仅供参考,你也可以用你的方法,就是麻烦了点

J3D的摸瞎人
2006-10-10 07:55
快速回复:为什么这个程序就是运行不了?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017015 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved