java编码问题

importjava.awt.*;importjava.awt.event.*;publicclassTestMouseEventextendsWindowAdapter... import java.awt.*;
import java.awt.event.*;

public class TestMouseEvent extends WindowAdapter
{
Frame f;
TextArea t1;

public void display()
{
f=new Frame("Test mouse Event");
f.setSize(480,200);
f.setLocation (200,400);
f.setBackground (Color.lightGray);

t1=new TextArea();
t1.setEditable (false);

f.add(t1);
f.addWindowListener (this); //窗体f--注册窗体事件监听器

t1.addMouseListener (new myMouseEvent()); // 文本区控件t1--注册鼠标监听器
t1.addMouseMotionListener (new myMouseEvent()); //文本区控件t1--注册鼠标移动监听器

f.setVisible(true);

}

public void windowClosing(WindowEvent e)
{
System.exit(0);
}

public static void main (String args[])
{

new TestMouseEvent().display();

}

public class myMouseEvent implements MouseListener, MouseMotionListener //内类
{// MouseListener接口中的方法

public void mouseClicked(MouseEvent e){ report(e);} //处理:点击鼠标时

public void mouseEntered (MouseEvent e){report(e);} //处理:移入鼠标时

public void mouseExited (MouseEvent e){report(e);} //处理:移出鼠标时

public void mousePressed (MouseEvent e){ report(e);} //处理:按下鼠标时

public void mouseReleased (MouseEvent e){report(e);} //处理:释放鼠标时

// MouseMotionListener接口中的方法
public void mouseDragged (MouseEvent e){report(e);} //处理:拖动鼠标时

public void mouseMoved (MouseEvent e){report(e);} //处理:移动鼠标时

}

public void report (MouseEvent e)//自定义方法
{
int clickCount=e.getClickCount (); //返回鼠标单击的次数

String position="("+e.getX()+","+e.getY()+")";
String s="mouse cursor\n";

switch (e.getID()) // 根据不同的鼠标事件做出相应的处理
{
case MouseEvent.MOUSE_PRESSED: s+="pressed"; break;

case MouseEvent.MOUSE_RELEASED: s+="released";break;

case MouseEvent.MOUSE_CLICKED: s+="clicked"; break;

case MouseEvent.MOUSE_MOVED: s+="moved"; break;

case MouseEvent.MOUSE_ENTERED: s+="entered"; break;

case MouseEvent.MOUSE_EXITED: s+="exited"; break;

case MouseEvent.MOUSE_DRAGGED: s+="dragged"; break;

}

t1.setFont(new Font("Times New Rome",1, 14));
t1.setText(s+" at:"+position+"\n"+"click count:"+clickCount+"\n");

}

//public static void main(String[] args)
//{
// TestMouseEvent test = new TestMouseEvent();
//}

}

将上面的TestMouseEvent改成Frame和Applet形式。各位大虾,怎么改阿,能给出完整的修改版最好,我那点可怜的java知识早还给老师了,谢谢大家了:)
展开
 我来答
pingia
2010-06-24 · TA获得超过569个赞
知道小有建树答主
回答量:697
采纳率:100%
帮助的人:767万
展开全部
APPLET形式:
public class TestMouseEvent extends JApplet
public void init()
{

setSize(480,200);
setLocation (200,400);
setBackground (Color.lightGray);

t1=new TextArea();
t1.setEditable (false);

add(t1);

t1.addMouseListener (new myMouseEvent()); // 文本区控件t1--注册鼠标监听器
t1.addMouseMotionListener (new myMouseEvent()); //文本区控件t1--注册鼠标移动监听器

setVisible(true);

}

public static void main (String args[])
{

new TestMouseEvent ();

}

frame形式:
public class TestMouseEvent extends JFrame
public void display()
{

setSize(480,200);
setLocation (200,400);
setBackground (Color.lightGray);

t1=new TextArea();
t1.setEditable (false);

add(t1);

t1.addMouseListener (new myMouseEvent()); // 文本区控件t1--注册鼠标监听器
t1.addMouseMotionListener (new myMouseEvent()); //文本区控件t1--注册鼠标移动监听器

setVisible(true);

}
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式