The Artima Developer Community
Sponsored Link

Java Answers Forum
problem with graphic method

2 replies on 1 page. Most recent reply: Jul 6, 2002 12:20 AM by Brian Walsh

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
Brian Walsh

Posts: 2
Nickname: calv1n
Registered: Jul, 2002

problem with graphic method Posted: Jul 5, 2002 8:40 PM
Reply to this message Reply
Advertisement
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.*;
 
public class Guest extends Applet
{
 
 
 
   public int place;
   public int  gender ;
   public String owner;
   public int placeX;
   public int placeY;
   public int width = 50;
   public int x = 54, y = 73;
   public int 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)
   {
 
   }
 
 
   public int 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;
 
   }
 
 
   public int 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;
 
 
 
 
public class Diner extends Applet
{
   //-----------------------------------------------------------------
   //  Creates some bank accounts and requests various services.
   //-----------------------------------------------------------------
   public void 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

Tool completed with exit code 1

Thank you for your help!!!!


Matt Gerrans

Posts: 1153
Nickname: matt
Registered: Feb, 2002

Re: problem with graphic method Posted: Jul 5, 2002 9:36 PM
Reply to this message Reply
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).

Brian Walsh

Posts: 2
Nickname: calv1n
Registered: Jul, 2002

Re: problem with graphic method Posted: Jul 6, 2002 12:20 AM
Reply to this message Reply
Thanks for the help...it works well, plus I changed the methods to reflect the changes you suggested, thanks again!!

Flat View: This topic has 2 replies on 1 page
Topic: I (Java beginner) NEED HELP with Server & Client Code!!!! Previous Topic   Next Topic Topic: Loop Program Crashes.Why?

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use