发布网友
共2个回答
热心网友
//是这个么
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
public class Dom1 extends JFrame {
public JLabel l;
JButton b = new JButton("button");
public Dom1() {
Handle h = new Handle();
h.dom=this;
l = new JLabel("aaa");
b.setActionCommand("but1");
b.addActionListener(h);
this.add(l, BorderLayout.NORTH);
this.add(b, BorderLayout.CENTER);
setVisible(true);
this.setSize(300, 200);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public static void main(String[] args) {
new Dom1();
}
}
class Handle implements ActionListener {
Dom1 dom;
@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource()==dom.b)
JOptionPane.showMessageDialog(dom, "单击了button");
}
}
参考资料:还有其他问题的话,给我发百度消息
热心网友
希望你再吧,问题描述清楚些;晚上再来看你的问题!