【发布时间】:2015-11-02 09:38:42
【问题描述】:
我遇到了麻烦...
与我上次发布的帖子不同,我在 Google 上搜索过,但没有任何帮助。
为什么我在这里得到:非法前向引用错误,我该如何修复它?
public class guihanging extends javax.swing.JFrame {
int re;
String [] A = new String[10];
String word;
String dash = "";
int picture = 2;
String letter = "qw";
int startOver;
int qq=0;
int ww=0;
int ee=0;
int rr=0;
int tt=0;
int yy=0;
int uu=0;
int ii=0;
int oo=0;
int pp=0;
int aa=0;
int ss=0;
int dd=0;
int ff=0;
int gg=0;
int hh=0;
int jj=0;
int kk=0;
int ll=0;
int zz=0;
int xx=0;
int cc=0;
int vv=0;
int bb=0;
int nn=0;
int mm=0;
public guihanging() {
initComponents();
{
A[0]="rob";
A[1]= "welcome";
A[2]= "carbohydrates";
A[3]= "resiprocity";
A[4]="fatty";
A[5]="baggy";
A[6]="laptop";
A[7]="personalcomputer";
A[8]="monitor";
A[9]="mouse";
}
}
public void letters()
{System.out.println("");}
{
int wordleng = word.length();
for (int i2 = 0; i2 < wordleng; i2++)
{
int position = word.indexOf(letter);
if (position >= 0)
{
String before = word.substring(0,position);
String after = word.substring(position+1);
word = before + "@" + after;
int dashPosition = position * 2;
String dashBefore = dash.substring(0,dashPosition);
String dashAfter = dash.substring(dashPosition + 1);
dash = dashBefore + letter + dashAfter;
lblWord.setText(dash);//error
}
else
{
lblPicture.setIcon(new javax.swing.ImageIcon(getClass().getResource("/pictures/"+picture+".png")));// error
picture++;
if (picture == 7)
{
JOptionPane.showConfirmDialog(rootPane, "Unluck, You just did a burpee!!"+"/n"+"do you want to start again?");
if (true)
{
re = (int) (Math.random ()*10);
word = "aaabcqdefghiqjklmnopqrstuvwxyz"; //A[re];
for (int i1 = 0; wordleng < 10; i1++)
{
dash = dash + "_ ";
}
lblWord.setText(dash);/error
}
}
}
}
}
错误都是由标签引起的
编辑留下这个
private void btnStartActionPerformed(java.awt.event.ActionEvent evt) {
re = (int) (Math.random ()*10);
word = A[re];
int wordleng = word.length();
for (int i1 = 0; i1 < wordleng; i1++)
{
dash = dash + "_ ";
}
lblWord.setText(dash)
【问题讨论】:
-
哪一行报错了?
-
什么是错误以及从哪里...并为您共享代码 lblword...
-
抱歉漏掉了,这是 lblWord 的唯一代码,它仍处于项目的开始阶段。我是个大菜鸟