I was wondering if I could get help with the ColorCheck method I built I think I am having problems with me putting the "Graphics page" between it's parathesis. If I did'nt when I would compile it would'nt recognize page.setColor in Guest.java. But when I would compile my second program it says I can't apply the Graphics page to Colorcheck (). So I don't know what to do....
-Here is the following in this order:
Code for Guest.java (program to set up methods)
Code for Diner.java (program to envoke methods)
Compile error for Diner.java
import java.applet.Applet;
import java.awt.*;
publicclass Guest extends Applet
{
publicint place;
publicint gender ;
public String owner;
publicint placeX;
publicint placeY;
publicint width = 50;
publicint x = 54, y = 73;
publicint tableWidth = 79, tableHeight = 140;
//-----------------------------------------------------------------
// Sets up the account by defining its owner, account number,
// and initial balance.
//-----------------------------------------------------------------
public Guest (String owner, int gender, double place)
{
}
publicint colorCheck (Graphics page)//draws circle according to sex
{
switch (gender)
{
case 1: //male
{
page.setColor (Color.blue);
page.fillOval (placeX, placeY, width, width);
page.setColor (Color.black);
page.drawString (owner, placeX, placeY);
break;
}
case 2://female
{
page.setColor (Color.pink);
page.fillOval (placeX, placeY, width, width);
page.setColor (Color.black);
page.drawString ( owner, placeX, placeY);
break;
}
}
return gender;
}
publicint PlaceCheck ()//draws place according to variable "place."
{
switch (place)
{
case 1: //place 1
{
placeX = 39;
placeY = 90;
break;
}
case 2://place 2
{
placeX = 39;
placeY = 140;
break;
}
case 3: //place 3
{
placeX = 148;
placeY = 90;
break;
}
case 4: //place 4
{
placeX = 148;
placeY = 140;
break;
}
}
return gender;
}
}
-------------
import java.applet.Applet;
import java.awt.*;
import Guest;
publicclass Diner extends Applet
{
//-----------------------------------------------------------------
// Creates some bank accounts and requests various services.
//-----------------------------------------------------------------
publicvoid paint (Graphics page)
{
Guest Webly= new Guest ("Webly", 2, 1);
Guest Brian = new Guest ("Brian", 1, 2);
Guest Mom = new Guest ("Mom", 2, 3);
//-----------------------------------------------------------------
// Makes a Table
//-----------------------------------------------------------------
page.setColor (Color.black);
page.drawRect ( 54, 73, 79,140 );
Webly.PlaceCheck();
Webly.colorCheck();
}
}
--------
C:\Documents and Settings\Administrator\Desktop\Schoolie\Spring 2002\CS161\Workbench\Diner.java:32: colorCheck(java.awt.Graphics) in Guest cannot be applied to () Webly.colorCheck(); ^ 1 error
Tool completed with exit code 1 C:\Documents and Settings\Administrator\Desktop\Schoolie\Spring 2002\CS161\Workbench\Diner.java:32: colorCheck(java.awt.Graphics) in Guest cannot be applied to () Webly.colorCheck(); ^ 1 error
It looks like you wrote the method colorCheck(java.awt.Graphics), but you are trying to call an overloaded version of the method that takes no parameters, so you probably just need to change "Webly.colorCheck();" to "Webly.colorCheck(page);"
Also, a couple of style and design tips: You should probably make all your instance variables private, instead of public. The first character of local variable names are usually not capitalized; this capitalization is usually reserved for class names. This convention applies to all the method names and instance variable names (that the first letter is lowercase).