所以如果有人會看看下面的代碼,並給我手,我會欠你一輩子。所以這裏是問題所在,如果我將playerCreationSelection
放在自己的課堂上,我的問題就是讓它起作用,在class superClass
之內,我不能爲了我的生活而移動任何東西來使其工作。任何幫助都會很棒,謝謝大家!在主類中重複使用動作偵聽器和jframe
忘了實際發生了什麼問題!所以會發生什麼是它說playerCreationSelection
不是一個符號
public class superClass
{
public static void main(String[] args)
{
playerCreationSeletion gui = new playerCreationSeletion();
}
public class playerCreateSelection extends JFrame implements ActionListener
{
//create label
public JLabel playerCreatedLabel;
public void playerCreationSeletion()
{
setSize(WIDTH,HEIGHT);
WindowDestroyer listener = new WindowDestroyer();
addWindowListener(listener);
Container contentPane = getContentPane();
contentPane.setBackground(Color.DARK_GRAY);
contentPane.setLayout(new FlowLayout());
//create button
JButton playerCreationButton = new JButton("Create New Player");
playerCreationButton.addActionListener(this);
contentPane.add(playerCreationButton);
//create label
playerCreatedLabel = new JLabel("Welcome New Player!");
playerCreatedLabel.setVisible(false);
}
public void actionPerformed(ActionEvent e)
{
String actionCommand = e.getActionCommand();
Container contentPane = getContentPane();
if(actionCommand.equals("Create New Player"))
{
contentPane.setBackground(Color.LIGHT_GRAY);
playerCreatedLabel.setVisible(true);
}
}
}
}
公共類playerCreateSelection需要是公共靜態類playerCreateSelection – MadProgrammer