I have two graphics methods in my program. One for the menu and one for the game. I have previously written all of my code in one graphics with a bunch of nested ifs. Now I am trying to separate the two. Is there a way to call the gameGraphics method when the game is running, and then returning to the graphics method when you return to then menu?
here is my code:
// The "SpaceSpamEvolution" class.
import java.applet.*;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class SpaceSpamEvolution extends Applet implements KeyListener, ActionListener
{
Timer time;
int screen; // 1 = menu, 2 = game
int select = 1; // select from the menu 1 = play, 2 = change diffuculty, 3 = change color (maybe)
int difficulty = 1; // 1 = easy, 2 = medium, 3 = difficult
int gameDiff ; // gameDiff = difficulty
// Place instance variables here
public void init ()
{
// Place the body of the initialization method here
} // init method
public void paint (Graphics g)
{
g.setColor(Color.red);
g.fillRect (10,10,10,10);
// Place the body of the drawing method here
} // paint method
public void keyPressed (KeyEvent e){
int key = e.getKeyCode ();
if (key == KeyEvent.VK_ENTER && screen == 1){
if (select == 1){
gameDiff = difficulty;
game (gameDiff);
}
}
if (key == KeyEvent.VK_RIGHT && screen == 1){
difficulty += 1;
if (difficulty == 4){
difficulty = 1;
}
}
if (key == KeyEvent.VK_LEFT && screen == 1){
difficulty -= 1;
if (difficulty == 0){
difficulty = 3;
}
}
}
public void keyReleased (KeyEvent e){}
public void keyTyped (KeyEvent e){}
public void game (int gameDiff){
int delaytime;
time = new Timer ((2000 - (500*gameDiff)), this);
}
public void gameGraphics (Graphics z){
z.setColor (Color.blue);
z.fillRect (50,50,50,50);
}
public void actionPerformed (ActionEvent e){}
} // SpaceSpamEvolution class
Thanks for any help.