import javax.swing.JFrame;
import javax.swing.JButton;
import java.awt.FlowLayout;
import javax.swing.ImageIcon;
import java.awt.event.ActionListener;
import java.awt.event.MouseListener;
import java.awt.event.ActionEvent;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;
class HandleJButton extends JFrame implements ActionListener,MouseListener,MouseMotionListener{
JButton jbutton1=new JButton("上一笔");
ImageIcon imageIcon1=new ImageIcon("G:\\简历
\\Img225634302.JPEG");
JButton jbutton2=new JButton("下一笔",imageIcon1);
ImageIcon imageIcon2=new ImageIcon("G:\\简历
\\zhouxingchi.JPEG");
JButton jbutton3=new JButton("imageIcon2");
FlowLayout flowLayout1=new FlowLayout();
HandleJButton(){
setTitle("按钮演示窗口");
setSize(200,150);
setDefaultCloseOperation("JFrame.EXIT_ON_CLOSE");
this.getContentPane().setLayout(flowLayout1);
jbutton1.addActionListener(this);
jbutton1.addMouseListener(this);
jbutton1.addMouseMotionListener(this);
jbutton2.addActionListener(this);
jbutton2.addMouseListener(this);
jbutton2.addMouseMotionListener(this);
jbutton3.addActionListener(this);
jbutton3.addMouseListener(this);
jbutton3.addMouseMotionListener(this);
this.getContentPane().add(jbutton1);
this.getContentPane().add(jbutton2);
this.getContentPane().add(jbutton3);
show();
}
public void actionPerformed(ActionEvent e){
object source=e.getSource();
if(source==jbutton1){
System.out.println("jbutton1按钮被单击");
}
else if(source==jbutton2){
jbutton1.setEnabled(False);
}
else if(source==jbutton3){
jbutton1.setEnabled(true);
}
}
public void mouseClicked(MouseEvent e){
System.out.println("mouseClicked 事件发生了");
}
public void mouseEntered(MouseEvent e){
System.out.println("mouseEntered 事件发生了");
}
public void mouseExited(MouseEvent e){
System.out.println("mouseExited 事件发生了");
}
public void mouseReleased(MouseEvent e){
System.out.println("mouseReleased 事件发生了");
}
public void mouseDragged(MouseEvent e){
System.out.println("mouseDragged 事件发生了");
}
public void mouseMoved(MouseEvent e){
System.out.println("mouseMoved 事件发生了");
}
public static void main(String[] args){
HandleJButton sjb=new HandleJButton();
}
}
这里就是代码了,不过我还不知API过时什么意思,也不知如何改!并不是我的基础没打好,理论和实践真的很大差别,老是忘这忘那!