Java

Moderators: zibadian
Number of threads: 7818
Number of posts: 18218

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
how do i call on a class with (graphics g) Posted by lil programer on 26 Apr 2010 at 4:52 PM
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 ~~~~~~~















Report
Re: how do i call on a class with (graphics g) Posted by dahliah_james on 26 Apr 2010 at 8:50 PM
huh,great job. thanks
Report
Re: how do i call on a class with (graphics g) Posted by silveredge52 on 27 Apr 2010 at 8:55 AM
Hey,
You have outlined an ambitious endeavor. My recommendations are not use the draw functions because their information is not preserved when a window component is automatically redrawn by the "system".

I altered your program to show a simple window frame. However the program is not meant to be a template. GUI programming is pretty involved.

My personal suggestion is to view a TicTacToe program (click on the link) that could provide many insights. I tried the version in the second post, it looked good just need to fix 1 line: public cl*** TicTacToe implements ActionListener {
needs to be: public class TicTacToe implements ActionListener {

A modified version of your original program is attached for download.

regards, se52
Attachment: MASTERMIND.java (3483 Bytes | downloaded 166 times)



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.