private int orgX;
private int orgY;
放到DrawLine类里
private int orgY;
放到DrawLine类里
解决方案 »
- long n=13356332255; 这句话居然都能出错,我服了,各位帮忙看看啊
- java 键盘输入问题
- 谁帮我看看程序有什么错误
- JAVA如何动态从LINUX下获取文件!
- 怎样屏蔽键盘上的键(在线等,急)
- 高分求sample
- 编译通过,但之后有java.lang.NoClassDefFoundError错误!
- 如何判断一个线程是否结束?
- 请问把.class文件反编译为.java文件的工具有什么???能恢复到原来的.java文件吗???
- 需要VisualAge for Java的企业版?
- 用正则表达式替换SQL语句中的to_char问题
- 请问是不是 winxp 里自带的 IE6 不支持 Applet ?
改成这样
f.getGraphics().drawLine(orgX,orgY,e.getX(),e.getY());
---------------------------
System.out.println("this is Dragged :"+e.getX()+" "+e.getY()); //此处的 orgX和 orgY 总是零,为什么?
+ "; this is Dragged :"+e.getX()+" "+e.getY());
private int orgX;
private int orgY;
在MouseLi 类中
public void mouseDragged(MouseEvent e) 也在 MouseLi类中 为什么 访问 orgX和orgY都 是零??
* Created on 2005-2-21
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package test;import java.awt.*;
import java.awt.event.*;public class DrawLine
{
private static int orgX;
private static int orgY;
Frame f = new Frame("画图");
public DrawLine(){
f.setSize(300,300);
f.setVisible(true);
f.addMouseListener(new MouseLi());
f.addMouseMotionListener(new MouseLi() );
}
class MouseLi implements MouseListener,MouseMotionListener
{ public void mousePressed(MouseEvent e)
{
orgX=e.getX();
orgY=e.getY();
System.out.println(""+orgX+" "+orgY);
}
public void mouseReleased(MouseEvent e)
{
//f.getGraphics().setColor(Color.red);
f.getGraphics().drawLine(orgX,orgY,e.getX(),e.getY());
}
public void mouseDragged(MouseEvent e)
{
System.out.println("this is Dragged :"+orgX+" "+orgY); //此处的 orgX和 orgY 总是零,为什么?
f.getGraphics().drawLine(orgX,orgY,e.getX(),e.getY());
f.getGraphics().clearRect(orgX,orgY,300,300);
}
public void mouseExited(MouseEvent e){}
public void mouseEntered(MouseEvent e){}
public void mouseClicked(MouseEvent e){}
public void mouseMoved(MouseEvent e){}
}
public static void main(String[] args){
DrawLine ll = new DrawLine();
}
}