我有一个任务,我必须单击面板 1 中的按钮 1 并更改面板 2 中按钮 2 上的信息,但是我不知道如何传递信息。
我以为我可以将方法 b() 中的信息从 panel2 传递回一个,但这不起作用。
我很困惑,不知道如何推进该计划。任何帮助表示赞赏。
面板1
public class MyJPanel1 extends JPanel implements ActionListener {
    Student st1 = new student("Fred","Fonseca",44);
    JButton j = new JButton(st1.getInfo());
    JButton b1 = new JButton("..");
    public myJPanel1() {
        super();
        setBackground(Color.yellow);
        // the whatsUp of this student has to shown in the other panel
        j.addActionListener(this); 
        add(j);         
    }   
    public void actionPerformed(ActionEvent event) {         
        Object obj = event.getSource();
        //=====================================                            
            if (obj == j){
                b1.setText(st1.whatsUp()); // Output on JButton in JPanel2 
            }
        }
    }
 }
面板2
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class myJPanel2 extends JPanel {
    JButton j1 = new JButton("");
    public void b(JButton b1) {
        JButton j1 = b1;            
    }   
    public myJPanel2() {
        super();
        setBackground(Color.pink);
        setLayout(new GridLayout(3,1));
        add(j1);
        // j1.setText(b1);
    }
 }