看看这个程序,40分 what is the problem?当然是画的框不对!高手快来! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 在init()方法里加上addMouseListener(this); import java.awt.*;import javax.swing.*;import java.awt.event.*;import java.awt.image.*;public class TMouseMotion extends JApplet implements MouseListener{ int x,y; int o_x,o_y; int flag; int s_x; int s_y; int width; int height; public void init() { CustomListener ct=new CustomListener(this); this.addMouseMotionListener(ct); addMouseListener(this);//You missed this line } public void update(Graphics g) { paint(g); } public void paint(Graphics gdraw) { BufferedImage bufimg=new BufferedImage(getWidth(),getHeight(),BufferedImage.TYPE_INT_ARGB); Graphics g=bufimg.getGraphics(); g.setColor(this.getBackground()); g.fillRect(0,0,getWidth(),getHeight()); g.setColor(Color.blue); g.drawString("drag/move mouse......",5,20); g.setColor(Color.red); if(flag==1) { g.drawString("don't move!drag the mouse",5,85); g.drawString("cursor coordinates:"+x+","+y,5,95); } else if(flag==2) { g.drawString("don't drag!move the mouse",5,85); g.drawString("cursor coordinates:"+x+","+y,5,95); } g.setColor(Color.blue); g.drawRect(s_x,s_y,width,height); gdraw.drawImage(bufimg,0,0,null); } public void mousePressed(MouseEvent e) { o_x=e.getX(); o_y=e.getY(); } public void mouseReleased(MouseEvent e) { o_x=0; o_y=0; } public void mouseClicked(MouseEvent e) { } public void mouseEntered(MouseEvent e) { } public void mouseExited(MouseEvent e) { }}class CustomListener implements MouseMotionListener{ TMouseMotion tm; public CustomListener(TMouseMotion tm) { this.tm=tm; } public void mouseMoved(MouseEvent e) { tm.flag=2; tm.x=e.getX(); tm.y=e.getY(); tm.repaint(); } public void mouseDragged(MouseEvent e) { tm.flag=1; tm.x=e.getX(); tm.y=e.getY(); if(tm.x>=tm.o_x && tm.y<=tm.o_y) { tm.s_x=tm.o_x; tm.s_y=tm.y; tm.width=tm.x-tm.o_x; tm.height=tm.o_y-tm.y; } if(tm.x>=tm.o_x && tm.y>=tm.o_y) { tm.s_x=tm.o_x; tm.s_y=tm.o_y; tm.width=tm.x-tm.o_x; tm.height=tm.y-tm.o_y; } if(tm.x<=tm.o_x && tm.y>=tm.o_y) { tm.s_x=tm.x; tm.s_y=tm.o_y; tm.width=tm.o_x-tm.x; tm.height=tm.y-tm.o_y; } if(tm.x<=tm.o_x && tm.y<=tm.o_y) { tm.s_x=tm.x; tm.s_y=tm.y; tm.width=tm.o_x-tm.x; tm.height=tm.o_y-tm.y; } tm.repaint(); }} 在init中少了 addMouseListener(this); hash一个一位数 关于SimpleDateFormat的format。。。 serialVersionUID问题 *.java文件中,编译时按照什么顺序,查找已有类 JSP中出现的一点错误,请帮帮我! java中接口是否可以成为其他类的属性 求教!!! 点页面上的链接,下载一个文件,文件保存好了之后,能否关掉这个页面? jbuilder6出问题了,请帮帮我,急!在线等!! 神那--救救我吧,一个句很短的源码,且编译不通过,还不知道为什么? 有没有OA(办公网)的演示版下载或参考? 请问Vector类在哪个包里?
addMouseListener(this);
import javax.swing.*;
import java.awt.event.*;
import java.awt.image.*;
public class TMouseMotion extends JApplet implements MouseListener
{
int x,y;
int o_x,o_y;
int flag;
int s_x;
int s_y;
int width;
int height;
public void init()
{
CustomListener ct=new CustomListener(this);
this.addMouseMotionListener(ct);
addMouseListener(this);//You missed this line
}
public void update(Graphics g)
{
paint(g);
}
public void paint(Graphics gdraw)
{
BufferedImage bufimg=new BufferedImage(getWidth(),getHeight(),BufferedImage.TYPE_INT_ARGB);
Graphics g=bufimg.getGraphics();
g.setColor(this.getBackground());
g.fillRect(0,0,getWidth(),getHeight());
g.setColor(Color.blue);
g.drawString("drag/move mouse......",5,20);
g.setColor(Color.red);
if(flag==1)
{
g.drawString("don't move!drag the mouse",5,85);
g.drawString("cursor coordinates:"+x+","+y,5,95);
}
else if(flag==2)
{
g.drawString("don't drag!move the mouse",5,85);
g.drawString("cursor coordinates:"+x+","+y,5,95);
}
g.setColor(Color.blue);
g.drawRect(s_x,s_y,width,height);
gdraw.drawImage(bufimg,0,0,null);
} public void mousePressed(MouseEvent e)
{
o_x=e.getX();
o_y=e.getY();
}
public void mouseReleased(MouseEvent e)
{
o_x=0;
o_y=0;
}
public void mouseClicked(MouseEvent e)
{
}
public void mouseEntered(MouseEvent e)
{
}
public void mouseExited(MouseEvent e)
{
}
}
class CustomListener implements MouseMotionListener
{
TMouseMotion tm;
public CustomListener(TMouseMotion tm)
{
this.tm=tm;
}
public void mouseMoved(MouseEvent e)
{
tm.flag=2;
tm.x=e.getX();
tm.y=e.getY();
tm.repaint();
}
public void mouseDragged(MouseEvent e)
{
tm.flag=1;
tm.x=e.getX();
tm.y=e.getY();
if(tm.x>=tm.o_x && tm.y<=tm.o_y)
{
tm.s_x=tm.o_x;
tm.s_y=tm.y;
tm.width=tm.x-tm.o_x;
tm.height=tm.o_y-tm.y;
}
if(tm.x>=tm.o_x && tm.y>=tm.o_y)
{
tm.s_x=tm.o_x;
tm.s_y=tm.o_y;
tm.width=tm.x-tm.o_x;
tm.height=tm.y-tm.o_y;
}
if(tm.x<=tm.o_x && tm.y>=tm.o_y)
{
tm.s_x=tm.x;
tm.s_y=tm.o_y;
tm.width=tm.o_x-tm.x;
tm.height=tm.y-tm.o_y;
}
if(tm.x<=tm.o_x && tm.y<=tm.o_y)
{
tm.s_x=tm.x;
tm.s_y=tm.y;
tm.width=tm.o_x-tm.x;
tm.height=tm.o_y-tm.y;
} tm.repaint(); }}
addMouseListener(this);