1
私はポーズメニュークラスPausePanel
を作成したゲームをコーディングしています。そのクラスでは、MainPanel
という別のクラスのJFrame
を設定できるようにしたいのですが、その方法を作成するときはいつも、別のエラーや問題が発生します。JFrameの可視性を別のクラスから変更する
Game
PausePanel
の初期化が表示されます。- クラス
PausePanel
が表示されています。なぜなら、私はコードの助けを必要としているからです。 クラス
MainPanel
にはJFrame
が表示されています。public class Game extends JFrame{ //Contains the game's panel public static void main(String[] args){ Game g1 = new Game(); g1.play(); } public Game(){ setVisible(true); //other stuff } //other methods private class Keys extends KeyAdapter { @Override public void keyPressed(KeyEvent e){ if (e.getKeyCode() == KeyEvent.VK_ESCAPE){ setVisible(false); MainPanel.pause(); PausePanel pp = new PausePanel(); pp.setBackground(Color.BLACK); pp.setPreferredSize(new Dimension(WIDTH,HEIGHT)); pp.setLayout(null); }}} public class PausePanel extends JFrame{ //Title Screen public PausePanel(){ //other stuff } private class ButtonListener implements ActionListener{ public void actionPerformed(ActionEvent e) { if (e.getSource().equals(continu)){ visibility(true); <------The issue } }}} public class MainPanel extends JPanel{ //Actual game private JPanel jp = new JPanel(); public MainPanel(){ //stuff } public void visibility(boolean b){ <----This is the method I'd like to be able to use jp.setVisible(b); } }
を行うことはできません。 'PausePanel'インスタンスに' MainPanel'のインスタンス( 'mp'と呼ぶ)を用意して、' mp.visibility(true) 'を行う必要があります。物事があるように、 'mp'はおそらく' Game'クラスのインスタンス変数である必要があります。 –