Solved

Expecting Statement or Type

Posted on 1997-11-24
5
262 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
  • 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
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…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

911 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now