javaのJPanelを閉じる方法を知りたいです。
前提
画面遷移をさせるために、今のJPanelを閉じて新しいJPanelを開けるように指定させたいです。
java
1import javax.swing.*; 2 3public class sindanmaker extends JFrame implements ActionListener{ 4int syukei = 0; 5//集計する項目を増やす可能性有り 6public static void main(String[] args){ 7sindanmaker zi = new sindanmaker(); 8zi.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 9zi.setBounds(200, 10, 1000, 700); 10zi.setTitle("game"); 11zi.setVisible(true); 12} 13 14public sindanmaker(){ 15//scene1 16JPanel scene1 = new JPanel(); 17JLabel jl = JLabel("質問"); 18JButton button1 = new JButton(); 19JButton button2 = new JButton(); 20JButton button3 = new JButton(); 21JButton button4 = new JButton(); 22button1.addActionListener(this); 23scene1.add(jl); 24scene1.add(button1); 25add(scene1); 26 27//scene2 28JPanel scene2 = new JPanel(); 29 30add(scene2); 31} 32 33//後でoverrideするかも 34public void actionPerformed(ActionEvent e){ 35//if文の中身は最終的にメソッドにして選択肢を並び替える予定 36 37if(e.getSource() == button1){ 38//今の閉じる 39//次の画面開く 40syukei += 1; 41}else if(e.getSource() == button2){ 42//今の画面を閉じる 43//次の画面を開く 44syukei += 2; 45}else if(e.getSource() == button3){ 46//今の画面を閉じる 47//次の画面を開く 48syukei += 3; 49}else if(e.getSource() == button4){ 50//今の画面を閉じる 51//次の画面を開く 52syukei += 4; 53} 54} 55 56}
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。