im trying to create the game mastermind and in my version, i split the many parts of my code into separate classes so it would be a
little easier to work with, several of my classes use g.drawstring for animation and positioning purposes,(got the idea from c++ gotoxy) but when i try to call some of these classes it gives me an (java.awt.Graphics) can not be applied to () error. what should i do?.
below is the mainmenu class i am trying to call and the mastermind class that is calling it.
~~~~~~~~~~~~~~~~~~~MAINMENU~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
import java.awt.Graphics;
import javax.swing.*;
import java.awt.*;
public class mainmenu
{
public void mainmenu(Graphics g)
{
int Position=0;int row=0;
for(row=30;row>=0 ;row=row-1)
{
for( Position=20;Position>=0;Position=Position-57)
{ g.drawString("*********************************************************",row+0,0);
}
}
~~~~~~~~~~~~~~~~~~~~~~~~~~MASTERMIND~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
import java.awt.Graphics;
import java.util.Scanner;
import javax.swing.*;
import java.awt.*;
import java.util.Random;
public class MASTERMIND {
public static void mastermind ( String [] args){
Scanner reader = new Scanner(System.in);
/* like i said there are alot of parts to it */
starter s = new starter();
mainmenu m = new mainmenu();
window w = new window();
endscreen e = new endscreen();
endscreen2 q = new endscreen2();
easy x = new easy();
Easy_game_instructions k = new Easy_game_instructions();
Hard_game_instructions h = new Hard_game_instructions();
endcreditz p = new endcreditz();
instructionscreen i = new instructionscreen();
winningscreen b = new winningscreen();
easy_game y = new easy_game();
hard_game u = new hard_game();
quitpfz a = new quitpfz();
int userselection=0;
s.starter();
while ((userselection!=5))
{
m.mainmenu(); /*<=< THIS IS WHERE THE ERROR IS */
switch(userselection)
{
case 1:i.instructionscreen();break;
case 2:y.easy_game();break;
case 3:u.hard_game();break;
case 4:p.endcreditz();break;
case 5:b.winningscreen();
}
}
}
}
~~~~~~ any help would be greatly appreciated, thank you ~~~~~~~
how do i call on a class with (graphics g)
Started by ToXsiK, Apr 27 2010 04:20 PM
3 replies to this topic
#1
Posted 27 April 2010 - 04:20 PM
|
|
|
#2
Posted 27 April 2010 - 10:15 PM
You normally would do m.mainmenu(m.getGraphics);
But i think mainmenu should extend JPanel or somethign else then. Not 100% sure tho.
But i think mainmenu should extend JPanel or somethign else then. Not 100% sure tho.
#3
Posted 28 April 2010 - 05:18 AM
You need to extend the JPanel class and override the 'public void paintComponent(Graphics g)' method.
You put all your 'drawing' code into the paintComponent() method.
A little more infos
You put all your 'drawing' code into the paintComponent() method.
A little more infos
#4
Posted 28 April 2010 - 06:30 AM
Oh, also. In Java all classes MUST begin with a capital letter. It's in the naming conventions --> http://java.sun.com/...tions.doc8.html


Sign In
Create Account

Back to top









