Solved

Expecting Statement or Type

Posted on 1997-11-24
5
289 Views
Last Modified: 2013-12-03
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);
        }
}
0
Comment
Question by:pyramid
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 4

Accepted Solution

by:
rembo earned 100 total points
ID: 1231139

Well, I see what's wrong, but I'm not sure what you're
really trying to do.

returnclass message;

is not a valid statement.  

Then on 35, you're doing:

g.drawString(String.valueOf(message),5,30);

However, your String is empty.  

When you create a new String, you have to put
something in it.  

Also, why are you extending your applet class?  

I think you want code more like this (It works):

 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);

        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);
   }
}
  }


0
 
LVL 1

Author Comment

by:pyramid
ID: 1231140
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?
0
 
LVL 1

Author Comment

by:pyramid
ID: 1231141
Perhaps I can use import to bring new class in and activate it

any comment??
0
 
LVL 4

Expert Comment

by:rembo
ID: 1231142
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);
        }
 }


}


0
 
LVL 1

Author Comment

by:pyramid
ID: 1231143
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.....
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
The viewer will learn how to implement Singleton Design Pattern in Java.

724 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question