Solved

Expecting Statement or Type

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
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 will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

705 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

19 Experts available now in Live!

Get 1:1 Help Now