当前位置: 技术问答>java相关
帮忙看个错,给分
来源: 互联网 发布时间:2015-02-05
本文导语: 原程序如下://* 用鼠标画圆滑的曲线*/ import java.awt.*; import java.applet.*; import java.awt.event.*; public class Test4 extends Applet implements MouseListener,MouseMotionListener { Color c; int k[]; public void init() { ...
原程序如下://* 用鼠标画圆滑的曲线*/
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class Test4 extends Applet implements MouseListener,MouseMotionListener
{
Color c;
int k[];
public void init()
{
addMouseListener(this);
addMouseMotionListener(this);
k = new int[4];
c = new Color(255,0,0);
}
public void paint(Graphics g)
{
g.setColor(c);
g.drawLine(k[0],k[1],k[2],k[3]);
}
public void mousePressed(MouseEvent e)
{
k[0]=e.getX();
k[1]=e.getY();
}
public void mouseDraged(MouseEvent e)
{
k[2]=e.getX();
k[3]=e.getY();
repaint();
k[0]=k[2];
k[1]=k[3];
}
}
编译报错:
-----------Configuration: test4 - JDK version 1.3.1 ---------
E:javaMyProjecttest4Test4.java:7: Test4 should be declared abstract; it does not define mouseDragged(java.awt.event.MouseEvent) in Test4
public class Test4 extends Applet implements MouseListener,MouseMotionListener
^
1 error
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class Test4 extends Applet implements MouseListener,MouseMotionListener
{
Color c;
int k[];
public void init()
{
addMouseListener(this);
addMouseMotionListener(this);
k = new int[4];
c = new Color(255,0,0);
}
public void paint(Graphics g)
{
g.setColor(c);
g.drawLine(k[0],k[1],k[2],k[3]);
}
public void mousePressed(MouseEvent e)
{
k[0]=e.getX();
k[1]=e.getY();
}
public void mouseDraged(MouseEvent e)
{
k[2]=e.getX();
k[3]=e.getY();
repaint();
k[0]=k[2];
k[1]=k[3];
}
}
编译报错:
-----------Configuration: test4 - JDK version 1.3.1 ---------
E:javaMyProjecttest4Test4.java:7: Test4 should be declared abstract; it does not define mouseDragged(java.awt.event.MouseEvent) in Test4
public class Test4 extends Applet implements MouseListener,MouseMotionListener
^
1 error
|
public void mouseDraged(MouseEvent e)
~~~~~~~~~~~~~应为 public void mouseDragged(MouseEvent e)
{
k[2]=e.getX();
k[3]=e.getY();
repaint();
k[0]=k[2];
k[1]=k[3];
}
当然,其他方法也是要实现的
~~~~~~~~~~~~~应为 public void mouseDragged(MouseEvent e)
{
k[2]=e.getX();
k[3]=e.getY();
repaint();
k[0]=k[2];
k[1]=k[3];
}
当然,其他方法也是要实现的
|
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class test4 extends Applet implements MouseListener,MouseMotionListener
{
Color c;
int k[];
public void init()
{
addMouseListener(this);
addMouseMotionListener(this);
k = new int[4];
c = new Color(255,0,0);
}
public void paint(Graphics g)
{
g.setColor(c);
g.drawLine(k[0],k[1],k[2],k[3]);
}
public void mousePressed(MouseEvent e)
{
k[0]=e.getX();
k[1]=e.getY();
}
public void mouseDragged(MouseEvent e)
{
k[2]=e.getX();
k[3]=e.getY();
repaint();
k[0]=k[2];
k[1]=k[3];
}
public void mouseMoved(MouseEvent e)
{
}
public void mouseClicked(MouseEvent e)
{
}
public void mouseReleased(MouseEvent e)
{
}
public void mouseEntered(MouseEvent e)
{
}
public void mouseExited(MouseEvent e)
{
}
}
import java.applet.*;
import java.awt.event.*;
public class test4 extends Applet implements MouseListener,MouseMotionListener
{
Color c;
int k[];
public void init()
{
addMouseListener(this);
addMouseMotionListener(this);
k = new int[4];
c = new Color(255,0,0);
}
public void paint(Graphics g)
{
g.setColor(c);
g.drawLine(k[0],k[1],k[2],k[3]);
}
public void mousePressed(MouseEvent e)
{
k[0]=e.getX();
k[1]=e.getY();
}
public void mouseDragged(MouseEvent e)
{
k[2]=e.getX();
k[3]=e.getY();
repaint();
k[0]=k[2];
k[1]=k[3];
}
public void mouseMoved(MouseEvent e)
{
}
public void mouseClicked(MouseEvent e)
{
}
public void mouseReleased(MouseEvent e)
{
}
public void mouseEntered(MouseEvent e)
{
}
public void mouseExited(MouseEvent e)
{
}
}
|
你实现这两个接口,就要实现它里面的所有方法。
就算为空方法也可以。
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。