面向对象程序设计--Java(第二版) c11_6代码

时间:2022-05-19 12:37:24 阅读: 最新文章 文档下载
说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。
import java.awt.*;

import javax.swing.*; import java.awt.event.*;

public class c11_6 extends JApplet{

int x,y;

JLabel lb1=new JLabel("X:"),lb2=new JLabel("Y:"),lb3=new JLabel(""); JTextField tf1=new JTextField(5),tf2=new JTextField(5);// Container cp=getContentPane();

FlowLayout flow=new FlowLayout(FlowLayout.CENTER,5,5); public void init() { }

class mouseListener implements MouseListener{ public void mouseClicked(MouseEvent e)// {lb3.setText("Clicked the mouse"); } public void mousePressed(MouseEvent e)

{lb3.setText("Pressed the mouse button");} public void mouseEntered(MouseEvent e) {lb3.setText("Mouse entered this area");} public void mouseExited(MouseEvent e)

{lb3.setText("Mouse is not avalible in the sight");} public void mouseReleased(MouseEvent e)// {lb3.setText("Released mouse");} cp.setLayout(flow); cp.add(lb1); cp.add(tf1); cp.add(lb2);

cp.add(tf2); cp.add(lb3);

addMouseListener(new mouseListener());// addMouseMotionListener(new koLis());//

}

class koLis implements MouseMotionListener{ }

public void mouseMoved(MouseEvent e) { }

public void mouseDragged(MouseEvent e) {lb3.setText("Dragged mouse");}

x=e.getX();

y=e.getY();

tf1.setText(String.valueOf(x)); tf2.setText(String.valueOf(y));


}




本文来源:https://www.wddqw.com/doc/60fcc67627284b73f24250e5.html