The Artima Developer Community
Sponsored Link

Java Answers Forum
New code with bugs, can someone help me

5 replies on 1 page. Most recent reply: Dec 18, 2002 6:33 AM by Dave

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 5 replies on 1 page
Dave

Posts: 4
Nickname: snowsport
Registered: Dec, 2002

New code with bugs, can someone help me Posted: Dec 13, 2002 11:56 AM
Reply to this message Reply
Advertisement
I have to use this code and I am very new at Java. Could someone help me with the bugs in this one? thanks in advance

import java.awt.*;
import java.applet.*;

public class Mystery5 extends Applet{
Image Buffer;
Graphics gBuffer;

public void init(){
Buffer=createImage(size().width,size().height);
gBuffer=Buffer.getGraphics();
}

public boolean mouseDown(Event evt,int x,int y){
drawRB(x,y);
repaint();
return true;
}

public void drawRD(int x, int y){
int red=(int)(Math.random()*255);
int green=(int)(Math.random()*255);
int blue=(int)(Math.random()*255);
Color randomColor=new Color(red,green,blue);
gBuffer.setColor(randomColor);
int diameter=(int)(Math.random()*90)+10;
gBuffer.fillOval(x-diamter/2,y-diameter/2,diameter,diameter);
}

public void update(Graphics g){
paint(g);
}

public void paint(Graphics g){
gBuffer.setColor(Color.black);
gBuffer.drawString("Click the applet to go!", 50,20);
g.drawImage(Buffer,0,0,this);
}
}


Matt Gerrans

Posts: 1153
Nickname: matt
Registered: Feb, 2002

Re: New code with bugs, can someone help me Posted: Dec 13, 2002 2:05 PM
Reply to this message Reply
If you want people to help you, it behooves you to reciprocate by providing well-formatted code (using the "java" tags mentioned under Formatting Your Post at the right, when you are posting and, more importantly explain what bugs you are trying to fix. With this post, you are asking people to read the badly formatted code, figure out what you were trying to do, then figure out what is wrong with it.

Dave

Posts: 4
Nickname: snowsport
Registered: Dec, 2002

Re: New code with bugs, can someone help me Posted: Dec 17, 2002 10:30 AM
Reply to this message Reply
> If you want people to help you, it behooves you to
> reciprocate by providing well-formatted code (using the
> "java" tags mentioned under Formatting Your Post at
> the right, when you are posting and, more importantly
> explain what bugs you are trying to fix. With this
> post, you are asking people to read the badly formatted
> code, figure out what you were trying to do, then
> figure out what is wrong with it.
**********************************************************
Sorry as I said earlier it is all new to me. I apologize..
the errors I get are :
When I compile I recieve these..

Mystery5.java uses or overrides a deprecated API.
recomplie with -deprecation for details

Mystery5.java:27: cannot resolve symbol
symbol: variable diameter
location: class Mystery5
gBuffer fill Oval(x-diamter/2,
^
y-diameter/2,diameter,diamter);

Matt Gerrans

Posts: 1153
Nickname: matt
Registered: Feb, 2002

Re: New code with bugs, can someone help me Posted: Dec 17, 2002 12:09 PM
Reply to this message Reply
Well, as far as compiler errors go, you have a misspelling of "diameter" (diamter) and a call to drawRB(), but a method called drawRD() -- since this method name is pretty close to meaningless, I don't know which is "correct," but either way, they need to match. Fixing these things will get it to compile with the -deprecation option, also changing your size() calls to getSize() calls will allow you to compile without the -deprecation flag.

In case you don't already know, "deprecated" means that the method shouldn't be used any more and has been replaced by some new (and hopefully better) method or way of accomplishing the same task.

Dave

Posts: 4
Nickname: snowsport
Registered: Dec, 2002

Re: New code with bugs, can someone help me Posted: Dec 17, 2002 1:11 PM
Reply to this message Reply
thank you very much Matt

Dave

Posts: 4
Nickname: snowsport
Registered: Dec, 2002

Re: New code with bugs, can someone help me Posted: Dec 18, 2002 6:33 AM
Reply to this message Reply
> Well, as far as compiler errors go, you have a misspelling
> of "diameter" (diamter) and a call to drawRB(), but a
> method called drawRD() -- since this method name is pretty
> close to meaningless, I don't know which is "correct," but
> either way, they need to match. Fixing these things will
> get it to compile with the -deprecation option, also
> changing your size() calls to getSize() calls will allow
> you to compile without the -deprecation flag.
>
> In case you don't already know, "deprecated" means that
> the method shouldn't be used any more and has been
> replaced by some new (and hopefully better) method or way
> of accomplishing the same task.

**Hi Matt,
I made the changes you asked me too. Here was the outcome

Mystery5.java:14: warning:
mouseDown(java.awt.Event,int,int) in java.awt.Component has been deprecated

A .class file was created but I am not sure it will run in a html. Thanks again.

Is there a source where I can look at updated API components?

Flat View: This topic has 5 replies on 1 page
Topic: Yearning to write applications using JMS Previous Topic   Next Topic Topic: Hello, who could help me?

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use