TruthSeeker
11-26-04, 04:32 PM
Yep... yeah... :D
I have to design a hangman game.
I got a menu and a start window, but I've been trying to open another file from within my main file and I haven't been able to find a method that does that. Any thoughts?
Details:
One of my MenuItems is "newGame" and I'm trying to make a method in which when I press "newGame" the computer go get the file which opens a new game...
Also, the code seems fine, but I cannot see any menus nor a title.... :confused:
import java.io.*;
import java.awt.*;
import java.awt.event.*;
public class GameMain extends Frame implements ActionListener, WindowListener{
private HangmanMenus hangman;
private MenuItem newGame, statistics, exit;
private MenuItem player1, random, difficulty;
private MenuItem credits;
private File game;
public static void main(String[] args){
Frame f= new GameMain();
f.setSize(500,500);
f.setVisible(true);
}
public void GameMain(){
setTitle("Hangman");
setLayout(new FlowLayout());
MenuBar menu= new MenuBar();
//File Menu
Menu fileMenu= new Menu("File");
newGame= new Menu("New Game");
fileMenu.add(newGame);
newGame.addActionListener(this);
statistics= new Menu("Statistics");
fileMenu.add(statistics);
statistics.addActionListener(this);
exit= new Menu("Quit");
fileMenu.add(exit);
exit.addActionListener(this);
menu.add(fileMenu);
//Options Menu
Menu optionsMenu= new Menu("Options");
player1= new Menu("Player1");
optionsMenu.add(player1);
player1.addActionListener(this);
random= new Menu("Random");
optionsMenu.add(random);
random.addActionListener(this);
difficulty= new Menu("Difficulty");
optionsMenu.add(difficulty);
difficulty.addActionListener(this);
menu.add(optionsMenu);
//About Menu
Menu about= new Menu("About");
credits= new Menu("Credits");
about.add(credits);
credits.addActionListener(this);
menu.add(about);
//Add Menus
setMenuBar(menu);
this.addWindowListener(this);
hangman= new HangmanMenus();
}
public void actionPerformed(ActionEvent event){
/*
if (event.getSource()==newGame)
HangmanMenus.newGame();
if (event.getSource()==statistics)
HangmanMenus.statistics()*/
if (event.getSource()==exit)
HangmanMenus.exit();
/*if (event.getSource()==player1)
HangmanMenus.player1();
if (event.getSource()==random)
HangmanMenus.random();
if (event.getSource()==difficulty)
HangmanMenus.difficulty();
if (event.getSource()==credits)
HangmanMenus.credits();*/
}
/*public void paint(Graphics g){
hangman.display(g);
}*/
public void windowClosing(WindowEvent event){
System.exit(0);
}
public void windowIconified(WindowEvent e){
}
public void windowOpened(WindowEvent e){
}
public void windowClosed(WindowEvent e){
}
public void windowDeiconified(WindowEvent e){
}
public void windowActivated(WindowEvent e){
}
public void windowDeactivated(WindowEvent e){
}
static class HangmanMenus{
public static void exit(){
System.exit(0);
}
public static void newGame(){
game = new File("M:\Comp132\Game.java");
start= game.getPath();
}
}
}
I have to design a hangman game.
I got a menu and a start window, but I've been trying to open another file from within my main file and I haven't been able to find a method that does that. Any thoughts?
Details:
One of my MenuItems is "newGame" and I'm trying to make a method in which when I press "newGame" the computer go get the file which opens a new game...
Also, the code seems fine, but I cannot see any menus nor a title.... :confused:
import java.io.*;
import java.awt.*;
import java.awt.event.*;
public class GameMain extends Frame implements ActionListener, WindowListener{
private HangmanMenus hangman;
private MenuItem newGame, statistics, exit;
private MenuItem player1, random, difficulty;
private MenuItem credits;
private File game;
public static void main(String[] args){
Frame f= new GameMain();
f.setSize(500,500);
f.setVisible(true);
}
public void GameMain(){
setTitle("Hangman");
setLayout(new FlowLayout());
MenuBar menu= new MenuBar();
//File Menu
Menu fileMenu= new Menu("File");
newGame= new Menu("New Game");
fileMenu.add(newGame);
newGame.addActionListener(this);
statistics= new Menu("Statistics");
fileMenu.add(statistics);
statistics.addActionListener(this);
exit= new Menu("Quit");
fileMenu.add(exit);
exit.addActionListener(this);
menu.add(fileMenu);
//Options Menu
Menu optionsMenu= new Menu("Options");
player1= new Menu("Player1");
optionsMenu.add(player1);
player1.addActionListener(this);
random= new Menu("Random");
optionsMenu.add(random);
random.addActionListener(this);
difficulty= new Menu("Difficulty");
optionsMenu.add(difficulty);
difficulty.addActionListener(this);
menu.add(optionsMenu);
//About Menu
Menu about= new Menu("About");
credits= new Menu("Credits");
about.add(credits);
credits.addActionListener(this);
menu.add(about);
//Add Menus
setMenuBar(menu);
this.addWindowListener(this);
hangman= new HangmanMenus();
}
public void actionPerformed(ActionEvent event){
/*
if (event.getSource()==newGame)
HangmanMenus.newGame();
if (event.getSource()==statistics)
HangmanMenus.statistics()*/
if (event.getSource()==exit)
HangmanMenus.exit();
/*if (event.getSource()==player1)
HangmanMenus.player1();
if (event.getSource()==random)
HangmanMenus.random();
if (event.getSource()==difficulty)
HangmanMenus.difficulty();
if (event.getSource()==credits)
HangmanMenus.credits();*/
}
/*public void paint(Graphics g){
hangman.display(g);
}*/
public void windowClosing(WindowEvent event){
System.exit(0);
}
public void windowIconified(WindowEvent e){
}
public void windowOpened(WindowEvent e){
}
public void windowClosed(WindowEvent e){
}
public void windowDeiconified(WindowEvent e){
}
public void windowActivated(WindowEvent e){
}
public void windowDeactivated(WindowEvent e){
}
static class HangmanMenus{
public static void exit(){
System.exit(0);
}
public static void newGame(){
game = new File("M:\Comp132\Game.java");
start= game.getPath();
}
}
}