当前位置: 技术问答>java相关
请帮忙看看这个程序(在线等)
来源: 互联网 发布时间:2015-07-18
本文导语: 请写出错误原因。 import java.awt.*; import java.applet.*; import java.util.*; public class QixTest extends Applet implements Runnable{ Thread imageThread=null; Random rnd=new Random(); Rectangle bounceRect; Rectangle colorBounce; BouncyPoint endPoint1,endPo...
请写出错误原因。
import java.awt.*;
import java.applet.*;
import java.util.*;
public class QixTest extends Applet implements Runnable{
Thread imageThread=null;
Random rnd=new Random();
Rectangle bounceRect;
Rectangle colorBounce;
BouncyPoint endPoint1,endPoint2;
BouncyPoint R_Bouncer,G_Bouncer,B_Bouncer;
int x1,x2,y1,y2;
public void init(){
bounceRect=getBounds();
bounceRect.x=0;
bounceRect.y=0;
}
public void start(){
sowSeed();
if(imageThread==null){
imageThread=new Thread(this);
imageThread.start();
}
public void stop()
{
if((imageThread!=null)&&imageThread.isAlive())
{
imageThread.stop();
}
imageThread=null;
}
public void run()
{
int i=0;
Thread me=Thread.currentThread();
me.sePriority(Thread.MIN_PRIORITY);
while(imageThread==me)
{
repaint();
try{
Thread.sleep(10);
}catch(InterruptedExpection e){}
i++;
if(i==1000){
sowSeed();
i=0;
}
}
}
public void update(Graphics g){
endPoint1.carryOnBouncing();
endPoint2.carryOnBouncing();
R_Bouncer.carryOnBouncing();
G_Bouncer.carryOnBouncing();
B_Bouncer.carryOnBouncing();
g.setColor(new Color(R_Bouncer.x,G_Bouncer.x,B_Bouncer.x));
g.drawLine(endPoint.x,endPoint.y,endPoint2.x,endPoint2.y);
}
public void sowSeed(){
x1=4+((rnd.nextInt()&1023)%(bounceRect.width-8));
x2=4+((rnd.nextInt()&1023)%(bounceRect.width-8));
y1=4+((rnd.nextInt()&1023)%(bounceRect.height-8));
y2=4+((rnd.nextInt()&1023)%(bounceRect.height-8));
endPoint1=new BouncyPoint(bounceRect,x1,y1,-1.0,1,5);
colorBounce=new Rectangle(0,0,255,255);
R_Bouncer=new BouncyPoint(colorBounce,200,0,-1.0,0.0);
B_Bouncer=new BouncyPoint(colorBounce,200,0,-2.0,0.0);
}
class BouncyPoint extends Point{
Rectangle boundingBox;
double x_direction;
double y_direction;
BouncyPoint(Rectangle limits,int startx,int starty,double dx,double dy)
{
super(startx,starty);
boundingBox=limits;
x_direction=dx;
y_direction=dy;
}
public void carryOnBouncing()
{
x+=(int)x_direction;
if(!boundingBox.contains(x,y)){
y-=(int)y_direction;
y_direction=-y_direction;
}
}
}
--------------------Configuration: Example3 - JDK version 1.4 --------------------
C:JCreatorMyProjectsApplet.javaQixTest.java:23: illegal start of expression
public void stop()
^
C:JCreatorMyProjectsApplet.javaQixTest.java:67: ';' expected
}
^
C:JCreatorMyProjectsApplet.javaQixTest.java:87: '}' expected
}
^
C:JCreatorMyProjectsApplet.javaQixTest.java:9: cannot resolve symbol
symbol : class BouncyPoint
location: class QixTest
BouncyPoint endPoint1,endPoint2;
^
C:JCreatorMyProjectsApplet.javaQixTest.java:10: cannot resolve symbol
symbol : class BouncyPoint
location: class QixTest
BouncyPoint R_Bouncer,G_Bouncer,B_Bouncer;
^
C:JCreatorMyProjectsApplet.javaQixTest.java:4: QixTest should be declared abstract; it does not define run() in QixTest
public class QixTest extends Applet implements Runnable{
^
C:JCreatorMyProjectsApplet.javaQixTest.java:18: cannot resolve symbol
symbol : method sowSeed ()
location: class QixTest
sowSeed();
^
7 errors
Process completed.
import java.awt.*;
import java.applet.*;
import java.util.*;
public class QixTest extends Applet implements Runnable{
Thread imageThread=null;
Random rnd=new Random();
Rectangle bounceRect;
Rectangle colorBounce;
BouncyPoint endPoint1,endPoint2;
BouncyPoint R_Bouncer,G_Bouncer,B_Bouncer;
int x1,x2,y1,y2;
public void init(){
bounceRect=getBounds();
bounceRect.x=0;
bounceRect.y=0;
}
public void start(){
sowSeed();
if(imageThread==null){
imageThread=new Thread(this);
imageThread.start();
}
public void stop()
{
if((imageThread!=null)&&imageThread.isAlive())
{
imageThread.stop();
}
imageThread=null;
}
public void run()
{
int i=0;
Thread me=Thread.currentThread();
me.sePriority(Thread.MIN_PRIORITY);
while(imageThread==me)
{
repaint();
try{
Thread.sleep(10);
}catch(InterruptedExpection e){}
i++;
if(i==1000){
sowSeed();
i=0;
}
}
}
public void update(Graphics g){
endPoint1.carryOnBouncing();
endPoint2.carryOnBouncing();
R_Bouncer.carryOnBouncing();
G_Bouncer.carryOnBouncing();
B_Bouncer.carryOnBouncing();
g.setColor(new Color(R_Bouncer.x,G_Bouncer.x,B_Bouncer.x));
g.drawLine(endPoint.x,endPoint.y,endPoint2.x,endPoint2.y);
}
public void sowSeed(){
x1=4+((rnd.nextInt()&1023)%(bounceRect.width-8));
x2=4+((rnd.nextInt()&1023)%(bounceRect.width-8));
y1=4+((rnd.nextInt()&1023)%(bounceRect.height-8));
y2=4+((rnd.nextInt()&1023)%(bounceRect.height-8));
endPoint1=new BouncyPoint(bounceRect,x1,y1,-1.0,1,5);
colorBounce=new Rectangle(0,0,255,255);
R_Bouncer=new BouncyPoint(colorBounce,200,0,-1.0,0.0);
B_Bouncer=new BouncyPoint(colorBounce,200,0,-2.0,0.0);
}
class BouncyPoint extends Point{
Rectangle boundingBox;
double x_direction;
double y_direction;
BouncyPoint(Rectangle limits,int startx,int starty,double dx,double dy)
{
super(startx,starty);
boundingBox=limits;
x_direction=dx;
y_direction=dy;
}
public void carryOnBouncing()
{
x+=(int)x_direction;
if(!boundingBox.contains(x,y)){
y-=(int)y_direction;
y_direction=-y_direction;
}
}
}
--------------------Configuration: Example3 - JDK version 1.4 --------------------
C:JCreatorMyProjectsApplet.javaQixTest.java:23: illegal start of expression
public void stop()
^
C:JCreatorMyProjectsApplet.javaQixTest.java:67: ';' expected
}
^
C:JCreatorMyProjectsApplet.javaQixTest.java:87: '}' expected
}
^
C:JCreatorMyProjectsApplet.javaQixTest.java:9: cannot resolve symbol
symbol : class BouncyPoint
location: class QixTest
BouncyPoint endPoint1,endPoint2;
^
C:JCreatorMyProjectsApplet.javaQixTest.java:10: cannot resolve symbol
symbol : class BouncyPoint
location: class QixTest
BouncyPoint R_Bouncer,G_Bouncer,B_Bouncer;
^
C:JCreatorMyProjectsApplet.javaQixTest.java:4: QixTest should be declared abstract; it does not define run() in QixTest
public class QixTest extends Applet implements Runnable{
^
C:JCreatorMyProjectsApplet.javaQixTest.java:18: cannot resolve symbol
symbol : method sowSeed ()
location: class QixTest
sowSeed();
^
7 errors
Process completed.
|
import java.awt.*;
import java.applet.*;
import java.util.*;
import java.io.*;
public class QixTest extends Applet implements Runnable{
Thread imageThread=null;
Random rnd=new Random();
Rectangle bounceRect;
Rectangle colorBounce;
BouncyPoint endPoint;//加这1个变量
BouncyPoint endPoint1,endPoint2;
BouncyPoint R_Bouncer,G_Bouncer,B_Bouncer;
int x1,x2,y1,y2;
public void init(){
bounceRect=getBounds();
bounceRect.x=0;
bounceRect.y=0;
}
public void start(){
sowSeed();
if(imageThread==null){
imageThread=new Thread(this);
imageThread.start();
}
}
public void stop()
{
if((imageThread!=null)&&imageThread.isAlive())
{
imageThread.stop();
}
imageThread=null;
}
public void run()
{
int i=0;
Thread me=Thread.currentThread();
//me.sePriority(Thread.MIN_PRIORITY);
while(imageThread==me)
{
repaint();
try{
Thread.sleep(10);
}catch(InterruptedException e){}//Expection 写错了
i++;
if(i==1000){
sowSeed();
i=0;
}
}
}
public void update(Graphics g){
endPoint1.carryOnBouncing();
endPoint2.carryOnBouncing();
R_Bouncer.carryOnBouncing();
G_Bouncer.carryOnBouncing();
B_Bouncer.carryOnBouncing();
g.setColor(new Color(R_Bouncer.x,G_Bouncer.x,B_Bouncer.x));
g.drawLine(endPoint.x,endPoint.y,endPoint2.x,endPoint2.y);//
}
public void sowSeed(){
x1=4+((rnd.nextInt()&1023)%(bounceRect.width-8));
x2=4+((rnd.nextInt()&1023)%(bounceRect.width-8));
y1=4+((rnd.nextInt()&1023)%(bounceRect.height-8));
y2=4+((rnd.nextInt()&1023)%(bounceRect.height-8));
endPoint1=new BouncyPoint(bounceRect,x1,y1,-1.0,1,5);//还剩下一个错误了,你自己差一下这,好象是你的参数不对。
colorBounce=new Rectangle(0,0,255,255);
R_Bouncer=new BouncyPoint(colorBounce,200,0,-1.0,0.0);
B_Bouncer=new BouncyPoint(colorBounce,200,0,-2.0,0.0);
}
class BouncyPoint extends Point{
Rectangle boundingBox;
double x_direction;
double y_direction;
BouncyPoint(Rectangle limits,int startx,int starty,double dx,double dy)
{
super(startx,starty);
boundingBox=limits;
x_direction=dx;
y_direction=dy;
}
public void carryOnBouncing()
{
x+=(int)x_direction;
if(!boundingBox.contains(x,y)){
y-=(int)y_direction;
y_direction=-y_direction;
}
}
}
}//少一个}
你看看吧,就剩下一个错误了,我在程序里面注释了你看看吧,可能是参数不对。
import java.applet.*;
import java.util.*;
import java.io.*;
public class QixTest extends Applet implements Runnable{
Thread imageThread=null;
Random rnd=new Random();
Rectangle bounceRect;
Rectangle colorBounce;
BouncyPoint endPoint;//加这1个变量
BouncyPoint endPoint1,endPoint2;
BouncyPoint R_Bouncer,G_Bouncer,B_Bouncer;
int x1,x2,y1,y2;
public void init(){
bounceRect=getBounds();
bounceRect.x=0;
bounceRect.y=0;
}
public void start(){
sowSeed();
if(imageThread==null){
imageThread=new Thread(this);
imageThread.start();
}
}
public void stop()
{
if((imageThread!=null)&&imageThread.isAlive())
{
imageThread.stop();
}
imageThread=null;
}
public void run()
{
int i=0;
Thread me=Thread.currentThread();
//me.sePriority(Thread.MIN_PRIORITY);
while(imageThread==me)
{
repaint();
try{
Thread.sleep(10);
}catch(InterruptedException e){}//Expection 写错了
i++;
if(i==1000){
sowSeed();
i=0;
}
}
}
public void update(Graphics g){
endPoint1.carryOnBouncing();
endPoint2.carryOnBouncing();
R_Bouncer.carryOnBouncing();
G_Bouncer.carryOnBouncing();
B_Bouncer.carryOnBouncing();
g.setColor(new Color(R_Bouncer.x,G_Bouncer.x,B_Bouncer.x));
g.drawLine(endPoint.x,endPoint.y,endPoint2.x,endPoint2.y);//
}
public void sowSeed(){
x1=4+((rnd.nextInt()&1023)%(bounceRect.width-8));
x2=4+((rnd.nextInt()&1023)%(bounceRect.width-8));
y1=4+((rnd.nextInt()&1023)%(bounceRect.height-8));
y2=4+((rnd.nextInt()&1023)%(bounceRect.height-8));
endPoint1=new BouncyPoint(bounceRect,x1,y1,-1.0,1,5);//还剩下一个错误了,你自己差一下这,好象是你的参数不对。
colorBounce=new Rectangle(0,0,255,255);
R_Bouncer=new BouncyPoint(colorBounce,200,0,-1.0,0.0);
B_Bouncer=new BouncyPoint(colorBounce,200,0,-2.0,0.0);
}
class BouncyPoint extends Point{
Rectangle boundingBox;
double x_direction;
double y_direction;
BouncyPoint(Rectangle limits,int startx,int starty,double dx,double dy)
{
super(startx,starty);
boundingBox=limits;
x_direction=dx;
y_direction=dy;
}
public void carryOnBouncing()
{
x+=(int)x_direction;
if(!boundingBox.contains(x,y)){
y-=(int)y_direction;
y_direction=-y_direction;
}
}
}
}//少一个}
你看看吧,就剩下一个错误了,我在程序里面注释了你看看吧,可能是参数不对。
|
BouncyPoint(x1,y1,-1.0,1,5);
BouncyPoint(Rectangle limits,int startx,int starty,double dx,double dy)
你看看,你在程序里定义的构造器和你用的BouncyPoint(x1,y1,-1.0,1,5);
参数类型也不对啊,
问题终于找到了,累死我了。这下知道怎么做了吧。
如果你一定要用BouncyPoint(x1,y1,-1.0,1,5);这样的构造器初始化你的类,那就要在BouncyPoint类里面自己在加一个如你BouncyPoint(x1,y1,-1.0,1,5);这样形式的构造器
BouncyPoint(Rectangle limits,int startx,int starty,double dx,double dy)
你看看,你在程序里定义的构造器和你用的BouncyPoint(x1,y1,-1.0,1,5);
参数类型也不对啊,
问题终于找到了,累死我了。这下知道怎么做了吧。
如果你一定要用BouncyPoint(x1,y1,-1.0,1,5);这样的构造器初始化你的类,那就要在BouncyPoint类里面自己在加一个如你BouncyPoint(x1,y1,-1.0,1,5);这样形式的构造器
|
public void start(){
sowSeed();
if(imageThread==null){
imageThread=new Thread(this);
imageThread.start();
//这儿少了一个}
}
sowSeed();
if(imageThread==null){
imageThread=new Thread(this);
imageThread.start();
//这儿少了一个}
}