我想通过按下 JButton 来更改 JPanel。好吧,我可以这样做一次,但问题是当我想回到以前的 JPanel 时。这是我的代码:
public class MindCreations {
public static void main(String[] args){
Adj0 object1= new Adj0();
object1.setSize(500, 600);
object1.setVisible(true);
object1.setLocation(700,300);
} }
public class Adj0 extends JFrame{
public Adj0(){
super("MindCreations");
this.setLayout(null);
adj0panel object9=new adj0panel();
add(object9.adj0panel());
Isa object10=new Isa();
add(object10.Isa());
} }
public class adj0panel {
private JButton quarto;
private FlowLayout layout;
public JPanel adj0panel(){
final JPanel panel=new JPanel();
JLabel jl=new JLabel();
panel.setLayout(layout);
quarto= new JButton("Tabela ISA");
quarto.setBounds(50,490,400,20);
jl.setIcon(new ImageIcon("2.png"));
jl.setBounds(40, 50, 413, 300);
panel.add(jl);
panel.add(quarto);
quarto.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent event){
Isa object3=new Isa();
panel.setVisible(false);
}
});
return panel;
}
}
public class Isa {
public JPanel Isa(){
final JPanel panel1=new JPanel();
panel1.setLayout(layout);
panel1.setBounds(0, 0, 500, 600);
panel1.setBackground(Color.WHITE);
panel1.setVisible(true);
JButton retroceder=new JButton("Retroceder");
retroceder.setBounds(300, 460, 90, 20);
retroceder.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent event){
adj0panel object4=new adj0panel();
panel1.setVisible(false);
}}
);
panel1.add(retroceder);
return panel1;
}}
我想按下按钮“retroceder”,我想从 adj0panel 类转到 JPanel。对不起,这个问题很长,我是这方面的初学者。如果有任何其他方法可以更改 JPanel,请告诉我。谢谢