2017-01-26 38 views
-3

所以如果有人會看看下面的代碼,並給我手,我會欠你一輩子。所以這裏是問題所在,如果我將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); 
 
      } 
 
     } 
 
    } 
 
    }

+0

公共類playerCreateSelection需要是公共靜態類playerCreateSelection – MadProgrammer

回答

0

好了,你有一個錯字 「playerCreationSeletion()」。另外,你需要調用這樣的內部類構造函數,並使用setVisible和setSize。

public static void main(String[] args) { 
     playerCreateSelection gui = new superClass().new playerCreateSelection(); 

     gui.setSize(500, 500); 
     gui.setVisible(true); 
    } 

試試看。

+0

可以先試試吧;) – MadProgrammer

+0

好打電話,嘿嘿。 –

相關問題