好像我完全不明白这些东西是如何工作的......我有一个扩展 JPanel 并实现 Actionlistener 的类,然后我想将它添加到扩展 JFrame 的类中......我无法做到工作.....
public class testPanel extends JFrame implements ActionListener{
JButton someBtn;
public testPanel(JButton someBtn){
    this.someBtn = someBtn;
    add(someBtn);
    someBtn.addActionListener(this);
}
@Override
public void actionPerformed(ActionEvent e){
    if(e.getSource() == someBtn)
        System.out.println("this worked");
}
}
二级文件
public class JavaApplication3 extends JFrame{
/**
 * @param args the command line arguments
 */
JButton button;
public JavaApplication3(){
    super("blah");
    JFrame p = new testPanel(button);
    add(p);
    pack();
    setVisible(true);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
    // TODO code application logic here
    new JavaApplication3();
}
}