JavaSwing图形界面编程之JApplet(六)

来源:互联网 发布:html导航页面源码 编辑:程序博客网 时间:2024/06/09 09:07


package three.day.applet;


import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;


import javax.swing.JApplet;
import javax.swing.JLabel;
import javax.swing.JTextField;




public class MouseListenerDemo01 extends JApplet implements MouseListener,MouseMotionListener
{
//int x,y;
JLabel lbX = new JLabel("X:");
JLabel lbY = new JLabel("Y:");
JLabel lb3 = new JLabel();
JTextField tfX = new JTextField(5);
JTextField tfY = new JTextField(5);
Container cp = getContentPane();
public void init()
{
cp.setLayout(new FlowLayout(FlowLayout.CENTER,5,5));
cp.add(lbX);
cp.add(tfX);
cp.add(lbY);
cp.add(tfY);
cp.add(lb3);
addMouseListener(this);
addMouseMotionListener(this);
}
@Override
public void mouseDragged(MouseEvent arg0) {
lb3.setText("拖动鼠标");
}
@Override
public void mouseMoved(MouseEvent e) {
tfX.setText(String.valueOf(e.getX()));
tfY.setText(String.valueOf(e.getY()));
}
@Override
public void mouseClicked(MouseEvent arg0) {
lb3.setText("鼠标单击");
}
@Override
public void mouseEntered(MouseEvent arg0) {
lb3.setText("鼠标进入窗口");
}
@Override
public void mouseExited(MouseEvent arg0) {
lb3.setText("鼠标走出窗口");
}
@Override
public void mousePressed(MouseEvent arg0) {
lb3.setText("鼠标按下");
}
@Override
public void mouseReleased(MouseEvent arg0) {
lb3.setText("鼠标按钮松开");
}


}