import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.*;
public class sdsad extends JFrame {
static JButton item,item2;
public sdsad (){
this.setLayout(new FlowLayout());
item= new JButton("一");
this.add(item);
item.addMouseListener( new clickAction());
item2= new JButton("二");
this.add(item2);
item2.addMouseListener(new clickAction());
this.setVisible(true);
this.setBounds(30, 30, 300, 300);
}
public static void main(String a[]){
new sdsad();
}
}
class clickAction implements MouseListener{
public void mouseClicked(MouseEvent e){
System.out.println("你点击的按钮上的文字是"+((JButton) (e.getSource())).getText() );
((JButton)e.getSource()).setBackground(Color.blue);
}
public void mouseEntered(MouseEvent e) {}
public void mouseExited(MouseEvent e) {}
public void mousePressed(MouseEvent e) {}
public void mouseReleased(MouseEvent e) {}
}