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' 클래스의 인스턴스 변수 일 필요가있을 것입니다. –