有人可以幫我調試這個請。我試圖回到Java,所以我不是最好的錯誤。這似乎是一個簡單的解決方法,但是我最後一次做Java是作爲高中的新生,所以我不知道該怎麼做。「非法表達式開始」
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.JPanel.*;
import javax.swing.JLabel.*;
import java.util.*;
import java.text.*;
public class CharacterCreator extends JApplet {
public final String[] races = {"Human", "Dwarf"};
public JComboBox<String>charRace = new JComboBox<String>(races);
public static void main(String[]args)
{
public final String[] classes = {"Mage", "Warrior", "Ranger"};
public final JComboBox<String>charClass = new JComboBox<String>(classes);
int[] attPts = new int[7];
JLabel pointPool = new JLabel("" + attPts[0]);
public final JButton STRplus = new JButton("+");
public final JButton STRminus = new JButton("-");
JLabel strValue = new JLabel("" + attPts[1]);
public final JButton CONplus = new JButton("+");
public final JButton CONminus = new JButton("-");
JLabel conValue = new JLabel("" + attPts[2]);
public final JButton DEXplus = new JButton("+");
public final JButton DEXminus = new JButton("-");
JLabel dexValue = new JLabel("" + attPts[3]);
public final JButton INTELplus = new JButton("+");
public final JButton INTELminus = new JButton("-");
JLabel intelValue = new JLabel("" + attPts[4]);
public final String[] bonusAtt = {"Strength", "Constitution", "Dexterity",
"Intelligence"};
public JComboBox<String>humanAtt = new JComboBox<String>(bonusAtt);
}
public CharacterCreator() {
JPanel asPanel = new JPanel();
asPanel.setLayout(new GridLayout(6, 1));
asPanel.add(new JLabel("Strength"));
asPanel.add(new JLabel("Constitution"));
asPanel.add(new JLabel("Dexterity"));
asPanel.add(new JLabel("Intelligence"));
JPanel mpPanel = new JPanel();
mpPanel.setLayout(new GridLayout(6, 1));
mpPanel.add(strValue);
mpPanel.add(conValue);
mpPanel.add(dexValue);
mpPanel.add(intelValue);
JPanel abPanel = new JPanel();
abPanel.setLayout(new GridLayout(6, 2));
abPanel.add(STRplus);
abPanel.add(STRminus);
abPanel.add(CONplus);
abPanel.add(CONminus);
abPanel.add(DEXplus);
abPanel.add(DEXminus);
abPanel.add(INTELplus);
abPanel.add(INTELminus);
JPanel attributes = new JPanel();
attributes.add(new JLabel("Ability Score"), BorderLayout.NORTH);
attributes.add(asPanel, BorderLayout.WEST);
attributes.add(mpPanel, BorderLayout.CENTER);
attributes.add(abPanel, BorderLayout.EAST);
attributes.add(humanAtt, BorderLayout.SOUTH);
JPanel masterPanel = new JPanel();
masterPanel.setLayout(new GridLayout(6, 1));
masterPanel.add(new JLabel("Pick your race"));
masterPanel.add(charRace);
masterPanel.add(new JLabel("Pick your Class"));
masterPanel.add(charClass);
masterPanel.add(new JLabel("Customize your ability points"));
masterPanel.add(attributes);
STRplus.addActionListener((ActionEvent e) -> {
attPts[0] = subPool(attPts[0], attPts[1]);
attPts[1] = increaseAtt(attPts[1]);
});
STRminus.addActionListener((ActionEvent e) -> {
attPts[0] = addPool(attPts[0], attPts[1]);
attPts[1] = decreaseAtt(attPts[1]);
});
CONplus.addActionListener((ActionEvent e) -> {
attPts[0] = subPool(attPts[0], attPts[2]);
attPts[2] = increaseAtt(attPts[2]);
});
CONminus.addActionListener((ActionEvent e) -> {
attPts[0] = addPool(attPts[0], attPts[2]);
attPts[2] = decreaseAtt(attPts[2]);
});
DEXplus.addActionListener((ActionEvent e) -> {
attPts[0] = subPool(attPts[0], attPts[3]);
attPts[3] = increaseAtt(attPts[3]);
});
DEXminus.addActionListener((ActionEvent e) -> {
attPts[0] = addPool(attPts[0], attPts[3]);
attPts[3] = decreaseAtt(attPts[3]);
});
INTELplus.addActionListener((ActionEvent e) -> {
attPts[0] = subPool(attPts[0], attPts[4]);
attPts[4] = increaseAtt(attPts[4]);
});
INTELminus.addActionListener((ActionEvent e) -> {
attPts[0] = addPool(attPts[0], attPts[4]);
attPts[4] = decreaseAtt(attPts[4]);
});
charRace.addItemListener((ItemEvent e) -> {
int[] attPts1 = {32, 8, 8, 8, 8, 8, 8};
if ((charRace.getSelectedIndex()) == 0) {
humanAtt.setVisible(false);
attPts1[1] = (attPts1[1] + 2);
}
if (((charRace.getSelectedIndex()) == 1) || ((charRace.getSelectedIndex()) == 4)) {
humanAtt.setVisible(false);
attPts1[2] = (attPts1[2] + 2);
}
});
}
public int subPool(int pool, int att) {
if (att == 18)
pool = pool - 0;
else {
if (att == 17)
pool = pool - 4;
else {
if (att == 16)
pool = pool - 3;
else {
if (att > 12)
pool = pool - 2;
else
pool = pool - 1;
}
}
}
return pool;
}
public int addPool(int pool, int att) {
if (att == 18)
pool = pool + 4;
else {
if (att == 17)
pool = pool + 3;
else {
if (att > 13)
pool = pool + 2;
else {
if (att > 8)
pool = pool - 2;
else
pool = pool - 0;
}
}
}
return pool;
}
public int increaseAtt(int att) {
if (att < 18)
att++;
return att;
}
public int decreaseAtt(int att) {
if (att > 8)
att = att - 1;
return att;
}
}
它給了我是
Main.java:18: error: illegal start of expression
public final String[] classes = {"Mage", "Warrior", "Ranger"};
^
Main.java:19: error: illegal start of expression
public final JComboBox<String>charClass = new JComboBox<String>(classes);
^
Main.java:25: error: illegal start of expression
public final JButton STRplus = new JButton("+");
^
Main.java:26: error: illegal start of expression
public final JButton STRminus = new JButton("-");
^
Main.java:28: error: illegal start of expression
public final JButton CONplus = new JButton("+");
^
Main.java:29: error: illegal start of expression
public final JButton CONminus = new JButton("-");
^
Main.java:31: error: illegal start of expression
public final JButton DEXplus = new JButton("+");
^
Main.java:32: error: illegal start of expression
public final JButton DEXminus = new JButton("-");
^
Main.java:34: error: illegal start of expression
public final JButton INTELplus = new JButton("+");
^
Main.java:35: error: illegal start of expression
public final JButton INTELminus = new JButton("-");
^
Main.java:38: error: illegal start of expression
public final String[] bonusAtt = {"Strength", "Constitution", "Dexterity",
^
Main.java:40: error: illegal start of expression
public JComboBox<String>humanAtt = new JComboBox<String>(bonusAtt);
如果你能在正確的方向指向我,那將是極大的讚賞
的訪問說明符的方法中都沒有使用,那是你的'主()'方法在做什麼。 – YoungHobbit
'公共靜態無效main()'是一種方法,這意味着訪問說明符是不必要的和非法的,例如方法啓動前的'public static String'和方法內部的'String'。 –