Link to home
Start Free TrialLog in
Avatar of pyramid
pyramid

asked on

Expecting Statement or Type

Hi java Gods!

I am getting several errors specfically an expecting statement error on the subclass message and a type identifier error on the "String.valueOf() line"

Any suggestions?

(I am new at Java)

Thanks.....

Here is the code:

import java.awt.*;
public class Spots extends java.applet.Applet  {

final int MAXSPOTS = 10;
int xspots[ ] = new int[MAXSPOTS];
int yspots[ ] = new int[MAXSPOTS];
int currspots = 0;

public void init( ) {
setBackground(Color.white);
}
public boolean mouseDown(Event evt, int x, int y) {
if (currspots < MAXSPOTS)
   addspots(x,y);
else
returnclass message;
return true;
}
void addspots(int x, int y) {
xspots[currspots] = x;
yspots[currspots] = y;
currspots++;
repaint( );
}
public void paint(Graphics g) {
g.setColor(Color.blue);
for (int i= 0; i<currspots; i++) {
g.fillOval(xspots[i] -10, yspots[i] -10,20,20);
    }
}
public class message extends Spots {
String message = new String( );
Color g = new Color(250,0,0);
set Font = (new Font("Helvetica",Font.BOLD,36));
g.drawString(String.valueOf(message),5,30);
        }
}
ASKER CERTIFIED SOLUTION
Avatar of rembo
rembo

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of pyramid
pyramid

ASKER

Hi.

I already have that part of the code working.

I am trying to put a test in the code that will give me a message in a template. When I reach over the limit of spots it will write on the applet "Too Many Spots".

any suggestions?
Avatar of pyramid

ASKER

Perhaps I can use import to bring new class in and activate it

any comment??
Here's a new version that should do what you want:

 import java.awt.*;
 public class Spots extends java.applet.Applet {
        final int MAXSPOTS = 10;
        int xspots[ ] = new int[MAXSPOTS];
        int yspots[ ] = new int[MAXSPOTS];
        int currspots = 0;
        boolean over = false;
        Color errColor;
        Font errFont;
        String errMsg;
        int errX = 0, errY = 0;


 public void init( ) {
        setBackground(Color.white);
 }

 public boolean mouseDown(Event evt, int x, int y) {
        if (currspots < MAXSPOTS)
                addspots(x,y);
    else {
                errX = x;
                errY = y;
                error("Too many spots!");
        }

        return true;
 }

 public void error(String s)
 {
        errMsg = s;
        errColor = new Color(250,0,0);
        errFont = (new Font("Helvetica",Font.BOLD,36));
        over = true;
        repaint();
 }

 void addspots(int x, int y) {
        xspots[currspots] = x;
        yspots[currspots] = y;
        currspots++;
        repaint( );
 }

 public void paint(Graphics g) {
        g.setColor(Color.blue);
        for (int i= 0; i<currspots; i++) {
                g.fillOval(xspots[i] -10, yspots[i] -10,20,20);
    }

        if (over) {
                g.setColor(errColor);
                g.setFont(errFont);
                g.drawString(errMsg, errX, errY);
        }
 }


}


Avatar of pyramid

ASKER

Thank you for helping me! Your code was very enlightening. I knew there was an issue of how Java used boolean. It did confuse me.

Again

Thanks.....