This week's book giveaway is in the General Computing forum.
We're giving away four copies of Learning Regular Expressions and have Ben Forta on-line!
See this thread for details.
Win a copy of Learning Regular Expressions this week in the General Computing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Need help on two compile errors  RSS feed

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am getting two errors: (1) line 198 'class' or 'interface' expected public void update(Graphics g)
^
(2) Game.java:241: cannot resolve symbol
symbol : method checkBox (java.awt.Point)
location: class Game myApp.checkBox(e.getPoint());
My code is as follows, sorry kinda long trying to meet a deadline:

[This message has been edited by Cindy Glass (edited October 09, 2001).]
 
Ranch Hand
Posts: 1067
2
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have too many curly brackets. You have "closed" your class so your method is outside your class.
(I did that without even having to count your curly brackets.)
[This message has been edited by christopher foran (edited October 09, 2001).]
 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here ya go. This is the fixed code. Just a coupla things.
1) rect wasn't decalared for the class - see lines 18 and 24
2) class Game was missing a closing brace.
import javax.swing.*;
import java.awt.*;
import java.awt.Graphics;
import java.awt.event.*;
public class Game extends JApplet{
int grid;
int move [];
int x;
int y;
int i;
int value;
int end = 0;
int hits;
int misses;
int total;
Rectangle [] rect;
public void init()
{
total = 0;
grid = 0;
rect = new Rectangle [9];
rect [0] = new Rectangle (0, 0, 100, 100); // a0
rect [1] = new Rectangle (100, 0, 100, 100); // a1
rect [2] = new Rectangle (200, 0, 100, 100); // a2
rect [3] = new Rectangle (0, 100, 100, 100); // b0
rect [4] = new Rectangle (100, 100, 100, 100); // b1
rect [5] = new Rectangle (200, 100, 100, 100); // b2
rect [6] = new Rectangle (0, 200, 100, 100); // c0
rect [7] = new Rectangle (100, 100, 100, 100); // c1
rect [8] = new Rectangle (200, 200, 100, 100); // c2
move = new int [9];
for (i = 0; i < 9; i++)
{
move[i] = 0;
}
MouseClickedListener myListener = new MouseClickedListener(this);
this.addMouseListener(myListener);
}
public void paint(Graphics g)
{ // set the color for the grid
g.setColor(Color.black);
g.drawRect(0,0,0,300);
g.drawLine(300, 0, 300, 300);
g.drawLine(0,0,300,0);
g.drawLine(0,300,300,300);
g.drawLine(0,200,300,200);
g.drawLine(0,100,300,100);
g.drawLine(100,0,100,300);
g.drawLine(200,0,200,300);
if (grid == 1 && move [grid] == 1)
{
g.setColor(Color.black);
// fill the rectangle with the color black
g.fillOval(30,30,25,25);
}
if (grid == 1 && move [grid] == 2)
{
g.setColor(Color.red);
// fill the rectangle with the color red
g.fillOval(30,30,25,25);
}
if (grid == 2 && move [grid] == 1)
{
g.setColor(Color.black);
g.fillOval(30,30,25,25);
}
if (grid == 2 && move [grid] == 2)
{
g.setColor(Color.red);
g.fillOval(130,25,25,25);
}
if (grid == 3 && move [grid] == 1)
{
g.setColor(Color.black);
g.fillOval(230,25,25,25);
}
if (grid == 3 && move [grid] == 2)
{
g.setColor(Color.red);
g.fillOval(230,25,25,25);
}
if (grid == 4 && move [grid] == 1)
{
g.setColor(Color.black);
g.fillOval(25,125,25,25);
}
if (grid == 4 && move [grid] == 2)
{
g.setColor(Color.red);
g.fillOval(25,125,25,25);
}
if (grid == 5 && move [grid] == 1)
{
g.setColor(Color.black);
g.fillOval(125,125,25,25);
}
if (grid == 5 && move [grid] == 2)
{
g.setColor(Color.red);
g.fillOval(125,125,25,25);
}
if (grid == 6 && move [grid] == 1)
{
g.setColor(Color.black);
g.fillOval(225,125,25,25);
}
if (grid == 6 && move [grid] == 2)
{
g.setColor(Color.red);
g.fillOval(225,125,25,25);
}
if (grid == 7 && move [grid] == 1)
{
g.setColor(Color.black);
g.fillOval(25,225,25,25);
}
if (grid == 7 && move [grid] == 2)
{
g.setColor(Color.red);
g.fillOval(125,225,25,25);
}
if (grid == 8 && move [grid] == 1)
{
g.setColor(Color.black);
g.fillOval(125,225,25,25);
}
if (grid == 9 && move [grid] == 2)
{
g.setColor(Color.red);
g.fillOval(125,25,25,25);
}
if (grid == 9 && move [grid] == 1)
{
g.setColor(Color.black);
g.fillOval(225,225,25,25);
}
if (grid == 9 && move [grid] == 2)
{
g.setColor(Color.red);
g.fillOval(25,25,25,25);
}
total++;
}
public void update(Graphics g)
{
// fill the rectangle with the color light grey
g.clearRect(0, 0, getWidth(), getHeight());
paint(g);
}
public void checkBox(Point p)
{
for (i = 0; i < 9; i++)
{
value = 1 + (int) (Math.random() * 2);
System.out.println (" value is " + value);
if (rect[i].contains(p))
grid = i + 1;
if (rect[i].contains(p) && move [grid] > 0)
move [grid] = value;
}
}

class MouseClickedListener extends MouseAdapter
{ // Instance Variable of the Applet class
Game myApp;
// Constructor of the MouseClickedListener
MouseClickedListener(Game myApp)
{
this.myApp = myApp;
}
public void mouseClicked(MouseEvent e)
{
myApp.checkBox(e.getPoint());
myApp.repaint();
//myApp.total++;
}
}
}
See ya. Hope you meet your deadline.
 
capp luckett
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a BUNCH!!!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!