把addWindowListener(new MyWindowAdapter(this));
addMouseMotionListener(new MyMouseMotionAdapter(this));
换成this.addWindowListener(new MyWindowAdapter());
this.addMouseMotionListener(new MyMouseMotionAdapter());
addMouseMotionListener(new MyMouseMotionAdapter(this));
换成this.addWindowListener(new MyWindowAdapter());
this.addMouseMotionListener(new MyMouseMotionAdapter());
解决方案 »
- 求解Java代码this.addKeyListener(MP);这句话什么意思和执行过程,详细代码如下,新手求解
- 一道调度问题
- 求日期正则表达式
- 问2个java问题,已经问了不少人了
- 一个表单问题 路过的帮忙
- 超级菜鸟问题,FileInputStream为什么找不到跟class文件放在同一目录下的文件
- 有人说internet环境下的socket连接不稳定,是真的吗?
- java读文本文件的问题?
- java其实也并不好用
- 用Marven启动项目之后登陆就报这个错 PWC6033: Unable to compile class for JSP
- 怎样在swing里面实现数据库的即时模糊查询
- 十万火急:如何让任务栏图标闪烁
temp.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent evt) {
System.exit(0);
}
});
import java.awt.event.*;
class MyFrame extends Frame
{
public String msg = "have a good time";
MousePanel mousePanel;
public MyFrame()
{
addWindowListener(new MyWindowAdapter(this));
mousePanel = new MousePanel();
mousePanel.addMouseMotionListener(new MyMouseMotionAdapter(this));
add(mousePanel);
}class MousePanel extends Panel
{
public MousePanel()
{ }
public void paint(Graphics g)
{
g.drawString(msg,10,10);
g.drawString("have a good time",20,20);
}
}public static void main(String argc[])
{
MyFrame temp = new MyFrame();
temp.setSize(new Dimension(300,300));
temp.setTitle("hava a good time");
temp.setVisible(true);
}
}class MyWindowAdapter extends WindowAdapter
{
MyFrame myframe;
public MyWindowAdapter(MyFrame temp)
{
myframe = temp;
}
public void windowClosing(WindowEvent event)
{
//myframe.setVisible(false);
System.exit(0);
}
}
class MyMouseMotionAdapter extends MouseMotionAdapter
{
MyFrame myframe;
MyMouseMotionAdapter(MyFrame tempFrame)
{
this.myframe = tempFrame;
}
public void mouseMoved(MouseEvent me)
{
this.myframe.msg = "x is " + me.getX() + "y is " + me.getY();
this.myframe.mousePanel.repaint();
}
}