Dillinger4
Nov 10th, 2000, 03:10 PM
Im having i little of a problem compiling this code which
i scapped from suns Java tutoral site any suggestions or coments on what im doing wrong would really be cool.
I understand the code for the most part but evertime i compile i keep getting 3 errors.
1) illegal start of expression
public void init(){
^
2) ClickMe should be declared abstract; it does not define
MouseClicked(java.atw.event.MouseEvent)
3) cannot resolve symbol
Spot spot = null;
^
It seems to be that they are importing the entire
package ie "import java.atw.*;" so then is
java.atw.event.MouseEvent a package memeber of
"java.awt.event.*" ?
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
public class ClickMe extends Applet implements MouseListener {
private Spot spot = null;
private static final int RADIUS = 7;
public void init() {
addMouseListener(this);
}
public void paint(Graphics g) {
// draw a black border and a white background
g.setColor(Color.white);
g.fillRect(0, 0, getSize().width - 1, getSize().height - 1);
g.setColor(Color.black);
g.drawRect(0, 0, getSize().width - 1, getSize().height - 1);
// draw the spot
g.setColor(Color.red);
if (spot != null) {
g.fillOval(spot.x - RADIUS,
spot.y - RADIUS,
RADIUS * 2, RADIUS * 2);
}
}
public void mousePressed(MouseEvent event) {
if (spot == null) {
spot = new Spot(RADIUS);
}
spot.x = event.getX();
spot.y = event.getY();
repaint();
}
public void mouseClicked(MouseEvent event) {}
public void mouseReleased(MouseEvent event) {}
public void mouseEntered(MouseEvent event) {}
public void mouseExited(MouseEvent event) {}
}
---------------------------------------------------------
// Spot class in another file
public class Spot {
//instance variables
public int size;
public int x, y;
//constructor
public Spot(int intSize) {
size = intSize;
x = -1;
y = -1;
}
}
i scapped from suns Java tutoral site any suggestions or coments on what im doing wrong would really be cool.
I understand the code for the most part but evertime i compile i keep getting 3 errors.
1) illegal start of expression
public void init(){
^
2) ClickMe should be declared abstract; it does not define
MouseClicked(java.atw.event.MouseEvent)
3) cannot resolve symbol
Spot spot = null;
^
It seems to be that they are importing the entire
package ie "import java.atw.*;" so then is
java.atw.event.MouseEvent a package memeber of
"java.awt.event.*" ?
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
public class ClickMe extends Applet implements MouseListener {
private Spot spot = null;
private static final int RADIUS = 7;
public void init() {
addMouseListener(this);
}
public void paint(Graphics g) {
// draw a black border and a white background
g.setColor(Color.white);
g.fillRect(0, 0, getSize().width - 1, getSize().height - 1);
g.setColor(Color.black);
g.drawRect(0, 0, getSize().width - 1, getSize().height - 1);
// draw the spot
g.setColor(Color.red);
if (spot != null) {
g.fillOval(spot.x - RADIUS,
spot.y - RADIUS,
RADIUS * 2, RADIUS * 2);
}
}
public void mousePressed(MouseEvent event) {
if (spot == null) {
spot = new Spot(RADIUS);
}
spot.x = event.getX();
spot.y = event.getY();
repaint();
}
public void mouseClicked(MouseEvent event) {}
public void mouseReleased(MouseEvent event) {}
public void mouseEntered(MouseEvent event) {}
public void mouseExited(MouseEvent event) {}
}
---------------------------------------------------------
// Spot class in another file
public class Spot {
//instance variables
public int size;
public int x, y;
//constructor
public Spot(int intSize) {
size = intSize;
x = -1;
y = -1;
}
}