Question

JAVA: Create a window screen to allow user to pick one and run that chosen ....

JAVA: Create a window screen to allow user to pick one and run that chosen . So I have 2 games that already have been already created, now I just need to make up a window screen selection that have 2 options that allows the user to pick one and that will open the game that they chose so they can continue playing that game. So pretty much, just a file runner application that support user input.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

// GameChooser.java this is the main program to run

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class GameChooser extends JFrame implements ActionListener
{
   public static void main(String[] args)
   {
       GameChooser f=new GameChooser(); //create our Frame
   }
  
   GameChooser()
   {
       Button b1 =new Button("Game1"); //create buttons
       Button b2 =new Button("Game2");                
       b1.addActionListener(this); // add event handler to button
       b2.addActionListener(this);
       add(b1);   // add button to Frame
       add(b2);
      
       // exit application when close button clicked
       setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
       setSize(400,400); // Frame/window size
       setTitle("Choose Games"); // frame title
       setLayout(new FlowLayout()); // simple flowlayout for frame
       setVisible(true);        // show frame
   }

   public void actionPerformed(ActionEvent e)
   {
       if (e.getActionCommand() == "Game1") // button text is Game1
       {
       JOptionPane.showMessageDialog(null, "Game1 clicked"); //show msgBox
       Game1.run();   // call game1
       }
       else if (e.getActionCommand() == "Game2")    // button text is Game2
       {
       JOptionPane.showMessageDialog(null, "Game2 clicked");
       Game2.run();   // call game2
       }
   }
}

// --------------------------------- end of file GameChooser.java


// Game1.java
public class Game1 {
  
   static void run()
   {
       //put your game1 code here  
       System.out.println("this is game 1");
   }
}

// --------------------------------- end of file Game1.java

// Game2.java

public class Game2 {
  
   static void run()
   {              
       //put your game2 code here
       System.out.println("this is game 2");
   }
}

// --------------------------------- end of file Game2.java


Add a comment
Know the answer?
Add Answer to:
JAVA: Create a window screen to allow user to pick one and run that chosen ....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Select one favorite application of yours (in e-commence, education, games, and so on). Design a Java...

    Select one favorite application of yours (in e-commence, education, games, and so on). Design a Java FxGUI for a "customer" to access the application of your design. the application of your design. 1. Makes sure you have sufficient components (2 or more buttons, text fields/areas, a selection list, 1 or more images and other optional components of your choice). In addition, add an "account" information so that a customer/user may access or utilize the application. Your GUI application shall also...

  • java code. James needs to create a computer text based game where some user has to...

    java code. James needs to create a computer text based game where some user has to enter as many words with the given letters as the given word. A good start would be writing a method that checks if a method has the same letters as the other. include pseudo code+ Input-Listen and Silent have the same word that's all information I have is a Anagram program that need to be done.ASAP just help me with the pseudo code of...

  • In the last assignment, you created a card class. Modify the card class so the setValue()...

    In the last assignment, you created a card class. Modify the card class so the setValue() method does not allow a card’s value to be less than 1 or higher than 13. If the argument to setValue() is out of range, assign 1 to the card’s value. You also created a PickTwoCards application that randomly selects two playing cards and displays their values. In that application, all card objects were arbitrarily assigned a suit represented by a single character, but...

  • JAVASCRIPT Create a simple web page that contains a JavaScript form that will allow the user...

    JAVASCRIPT Create a simple web page that contains a JavaScript form that will allow the user to answer 7 trivia questions. Your trivia game should contain: 2 text boxes 2 select dropdowns 2 multiple choice questions (using radio buttons, 4 options min) 1 choose-all-that-apply (checkboxes, 4 options min, one answer should be "None of the above"). No part-points for semi-correct answers. The questions can cover any topic you wish - but please keep it professional and easy enough that the...

  • I need to create a Tic Tac Toe program in C++. These are the requirements Write...

    I need to create a Tic Tac Toe program in C++. These are the requirements Write a program that allows the computer to play TicTacToe against a human player or allow two human players to play one another. Implement the following conditions: The player that wins the current game goes first in the next round, and their symbol is X. The other player will be O. Keep track of the number of games played, wins, and draws for each player....

  • PLEASE INCLUDE SAW-PROMPTS FOR 2 PLAYERS NAMES(VALIDATE NAMES). SHOW MENU (PLAYER MUST SELECT FROM MENU B4...

    PLEASE INCLUDE SAW-PROMPTS FOR 2 PLAYERS NAMES(VALIDATE NAMES). SHOW MENU (PLAYER MUST SELECT FROM MENU B4 THE GAME STARTS 1=PLAY GAME, 2=SHOW GAME RULES, 3=SHOW PLAYER STATISTICS, AND 4=EXIT GAME WITH A GOODBYE MESSAGE.) PLAYERS NEED OPTION TO SHOW STATS(IN A DIFFERNT WINDOW-FOR OPTION 3)-GAME SHOULD BE rock, paper, scissor and SAW!! PLEASE USE A JAVA GRAPHICAL USER INTERFACE. MUST HAVE ROCK, PAPER, SCISSORS, AND SAW PLEASE This project requires students to create a design for a “Rock, Paper, Scissors,...

  • JAVA Beginnings of a paper-rock-scissors game. Paper-rock-scissors is a game often used to make decisions. There...

    JAVA Beginnings of a paper-rock-scissors game. Paper-rock-scissors is a game often used to make decisions. There are two players. Each player secretly chooses either, paper, rock or scissors. At the count of three, each player reveals what they have chosen. The winner of the game is determined this way: paper beats rock (because paper covers rock) rock beats scissors (because rock crushes scissors) scissors beat paper (because scissors cut paper) If the two players choose the same item, it is...

  • Write a Java application program that plays a number guessing game with the user. In the...

    Write a Java application program that plays a number guessing game with the user. In the starter code that you are given to help you begin the project, you will find the following lines of code: Random generator = args.length == 0 ? new Random() :                    new Random(Integer.parseInt(args[0])); int secret = generator.nextInt(100); You must keep these lines of code in your program. If you delete these lines, or if you change thse lines in any way, then your program...

  • Please program this in Visual Basic 6. You have chosen to create an electronic version of the sliding tile puzzle game....

    Please program this in Visual Basic 6. You have chosen to create an electronic version of the sliding tile puzzle game. The object of the game is to slide the tiles so that they end up in the required order. The images shown below are examples of the two different versions of this puzzle (numeric and graphical) Puzzle Board-Numeric Puzzle Board-Graphical File Options Help Elapsed Time File Options Help Elapsed Time 00:02:12 00:04:20 5 6 7 8 9 10 11...

  • Overview In this exercise you are going to recreate the classic game of hangman. Your program...

    Overview In this exercise you are going to recreate the classic game of hangman. Your program will randomly pick from a pool of words for the user who will guess letters in order to figure out the word. The user will have a limited number of wrong guesses to complete the puzzle or lose the round. Though if the user answers before running out of wrong answers, they win. Requirements Rules The program will use 10 to 15 words as...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT