Results 1 to 5 of 5
Thread: wrong source code
- 02-16-2009, 02:01 PM #1
Member
- Join Date
- Apr 2008
- Posts
- 16
- Rep Power
- 0
wrong source code
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
public class PlayBalloon extends Applet implements ActionListener {
private Button grow, shrink, left, right;
private Balloon myBalloon;
public void init() {
grow = new Button("Grow");
add(grow);
grow.addActionListener(this);
shrink = new Button("Shrink");
add(shrink);
grow.addActionListener("this");
left = new Button("Left");
add(left);
left.addActionListener(this);
right = new Button("Right");
add(right);
right.addActionListener(this);
myBalloon = new Balloon();
}
public void actionPerformed(ActionEvent event) {
if (event.getSource() == grow)
myBalloon.grow();
if (event.getSource() == shrink)
myBalloon.shrink();
if (event.getSource() == left)
myBalloon.left();
if (event.getSource() == right)
myBalloon.right();
repaint();
}
public void paint(Graphics g) {
myBalloon.display(g);
}
}
class Balloon {
private int diameter = 10;
private int xCoord = 20, yCoord = 50;
public void display(Graphics g) {
g.drawOval(xCoord, yCoord, diameter, diameter);
}
public void left() {
xCoord = xCoord - 10;
}
public void right() {
xCoord = xCoord + 10;
}
public void grow() {
diameter = diameter + 5;
}
public void shrink() {
diameter = diameter - 5;
}
}
error line 16, how to edit?
- 02-16-2009, 04:35 PM #2
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
What's the error you get there? Seems you have copied this code and don't know what's exactly happen. And I don't think that anyone wants to edit this code for you here in our community.
Post your complete error message and ask your question more clearly.
- 02-16-2009, 05:05 PM #3
Member
- Join Date
- Apr 2008
- Posts
- 16
- Rep Power
- 0
error line 16 shrink.addActionListener("this");
it mention
addActionListener(java.awt.event.ActionListener) in java.awt.Button can not be applied to (java.lang.String)
how to solve it?
-
The error message is telling you exactly what's wrong. You're passing a String to the addActionListener method when it's expecting an ActionListener object. Quotes around "this" make it a String. No quotes makes it refer to the current object. So get rid of the quotes.
- 02-17-2009, 03:46 AM #5
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Simply,
andthisare completely two things."this"
Similar Threads
-
What's wrong with this code?
By Doctor Cactus in forum New To JavaReplies: 4Last Post: 11-29-2008, 05:44 PM -
MavenJava - browse source code of all open source projects online
By jirkacelak in forum Java SoftwareReplies: 1Last Post: 11-28-2008, 06:27 PM -
What is wrong with this code
By rosh72851 in forum New To JavaReplies: 13Last Post: 10-31-2008, 01:50 AM -
what's wrong with this code?
By agenteleven in forum Advanced JavaReplies: 5Last Post: 10-07-2008, 11:26 AM -
Need a source code
By vissu007 in forum New To JavaReplies: 1Last Post: 07-05-2007, 07:08 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks