I need to create a class GameUi.java that does the following: Game game; JFrame
ID: 3708064 • Letter: I
Question
I need to create a class GameUi.java that does the following:
Game game;
JFrame frame;
JPanel aiOnePanel;
JPanel tablePanel;
JPanel aiTwoPanel;
JPanel hpPanel;
JPanel aiThreePanel;
JPanel northPanel;
JPanel scorePanel;
JPanel bidPanel;
JMenuBar menuBar;
JMenu gameMenu;
JMenu helpMenu;
JMenuItem newGameMenuItem;
JMenuItem exitMenuItem;
JMenuItem aboutMenuItem;
JMenuItem rulesMenuItem;
a) Set member variable of type class Game to the parameter passed in
b) Call method initComponents()
a) Set the size of the JFrame
b) Set the default close operation of the JFrame
c) Use default layout manager BorderLayout
i) JMenu Game should be added to the JMenuBar
ii) JMenuItems New Game and Exit should be added to the JMenu Game
iii) JMenu Help should be added to the JMenuBar
iv) JMenuItems About and Game Rules should be added to the JMenu Help
e) JMenuBar should be set on the JFrame
i) the instance of class Player stored in class Game, member variable table, at the second position of the ArrayList
ii) An integer representing the position of the Player object in the ArrayList
iii) Example: aiOnePanel = new AiPlayerUi(game.getTable().get(Constants.POSITION_2), Constants.POSITION_2);
i) the instance of class Player stored in class Game, member variable table, at the second position of the ArrayList
ii) An integer representing the position of the Player object in the ArrayList
i) the instance of class Player stored in class Game, member variable table, at the second position of the ArrayList
ii) An integer representing the position of the Player object in the ArrayList
i) the instance of class Player stored in class Game, member variable table, at the second position of the ArrayList
j) Instantiate member variable northPanel and set the size of the JPanel using the default layout manager FlowLayout
i) Set the size of the JPanel
ii) Add a border to the JPanel
i) Set the size of the JPanel
ii) Add a border to the JPanel
m) Resize aiPanelTwo so it will fit in the northPanel with bidPanel and scorePanel
i) scorePanel
ii) aiTwoPanel
iii) bidPanel
i) Set the size of the JPanel
ii) Add a border to the JPanel
p) Add the JPanels to the JFrame in their appropriate locations based on using layout manager BorderLayout
q) Set the visibility of the JFrame (hint: this should ALWAYS be the last step on a UI)
4. Write an inner class to create an ActionListener that is registered to the JMenuItem with the text Exit; it should
a) Display a JOptionPane message confirming the user wants to exit using method showConfirmDialog()
b) If yes, exit the application by calling method System.exit() passing the value of 0 as an argument
c) If no, do not exit the application
5. Write an inner class to create an ActionListener that is registered to the JMenuItem with the text About using method showMessageDialog(); it should
i) Application name and version
ii) Date of development
6. Write an inner class to create an ActionListener that is registered to the JMenuItem with the text Game Rules using method showMessageDialog(); it should
i) Rules of the game as shown in Figure 6 below (displaying something simple like "game rules" is enough)
1. Add member variables:Game game;
JFrame frame;
JPanel aiOnePanel;
JPanel tablePanel;
JPanel aiTwoPanel;
JPanel hpPanel;
JPanel aiThreePanel;
JPanel northPanel;
JPanel scorePanel;
JPanel bidPanel;
JMenuBar menuBar;
JMenu gameMenu;
JMenu helpMenu;
JMenuItem newGameMenuItem;
JMenuItem exitMenuItem;
JMenuItem aboutMenuItem;
JMenuItem rulesMenuItem;
2. A custom constructor should be defined that receives a parameter of data type Game classa) Set member variable of type class Game to the parameter passed in
b) Call method initComponents()
3. A method initComponents() should initialize all the components for the UI and be called from the constructora) Set the size of the JFrame
b) Set the default close operation of the JFrame
c) Use default layout manager BorderLayout
d) Set up the JMenuBari) JMenu Game should be added to the JMenuBar
ii) JMenuItems New Game and Exit should be added to the JMenu Game
iii) JMenu Help should be added to the JMenuBar
iv) JMenuItems About and Game Rules should be added to the JMenu Help
e) JMenuBar should be set on the JFrame
f) Instantiate member variable aiOnePanel by calling the constructor for class AiPlayerUi, passing as argumentsi) the instance of class Player stored in class Game, member variable table, at the second position of the ArrayList
ii) An integer representing the position of the Player object in the ArrayList
iii) Example: aiOnePanel = new AiPlayerUi(game.getTable().get(Constants.POSITION_2), Constants.POSITION_2);
g) Instantiate member variable aiTwoPanel by calling the constructor for class AiPlayerUi, passing as argumentsi) the instance of class Player stored in class Game, member variable table, at the second position of the ArrayList
ii) An integer representing the position of the Player object in the ArrayList
h) Instantiate member variable aiThreePanel by calling the constructor for class AiPlayerUi, passing as argumentsi) the instance of class Player stored in class Game, member variable table, at the second position of the ArrayList
ii) An integer representing the position of the Player object in the ArrayList
i) Instantiate member variable humanPanel by calling the constructor for class HumanPlayerUi, passing as an argumenti) the instance of class Player stored in class Game, member variable table, at the second position of the ArrayList
j) Instantiate member variable northPanel and set the size of the JPanel using the default layout manager FlowLayout
k) Instantiate member variable bidPanel and do the followingi) Set the size of the JPanel
ii) Add a border to the JPanel
l) Instantiate member variable scorePanel and do the followingi) Set the size of the JPanel
ii) Add a border to the JPanel
m) Resize aiPanelTwo so it will fit in the northPanel with bidPanel and scorePanel
n) Add to northPaneli) scorePanel
ii) aiTwoPanel
iii) bidPanel
o) Instantiate member variable tablePanel and do the followingi) Set the size of the JPanel
ii) Add a border to the JPanel
p) Add the JPanels to the JFrame in their appropriate locations based on using layout manager BorderLayout
q) Set the visibility of the JFrame (hint: this should ALWAYS be the last step on a UI)
4. Write an inner class to create an ActionListener that is registered to the JMenuItem with the text Exit; it should
a) Display a JOptionPane message confirming the user wants to exit using method showConfirmDialog()
b) If yes, exit the application by calling method System.exit() passing the value of 0 as an argument
c) If no, do not exit the application
5. Write an inner class to create an ActionListener that is registered to the JMenuItem with the text About using method showMessageDialog(); it should
a) Display a JOptionPane message informing the user:i) Application name and version
ii) Date of development
6. Write an inner class to create an ActionListener that is registered to the JMenuItem with the text Game Rules using method showMessageDialog(); it should
a) Display a JOptionPane message informing the user:i) Rules of the game as shown in Figure 6 below (displaying something simple like "game rules" is enough)
Explanation / Answer
package sportshead;
import javax.swing.*;
import java.awt.*;
import java.awt.image.ImageObserver;
import java.awt.image.ImageProducer;
public class screen extends JFrame{
private Image back;
private Image player1;
private Image player2;
private Image goal1;
private Image goal2;
private Image ball;
Player1 p = new Player1();
public screen(){
setTitle("The title");
setSize(1500, 800);
setLocation(0,0);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);
}
public void loadPics(){
player1 = new ImageIcon("C:\Test\player1.png").getImage();
player2 = new ImageIcon("C:\Test\player2.png").getImage();
goal1 = new ImageIcon("C:\Test\goal1.png").getImage();
goal2 = new ImageIcon("C:\Test\goal2.png").getImage();
ball = new ImageIcon("C:\Test\ball.png").getImage();
back = new ImageIcon("C:\Test\Background.jpg").getImage();
repaint();
}
public void paint(Graphics g){
g.drawImage(back, 0, 0, null);
p.paint(g);
g.drawImage(player2, -400, 200, null);
g.drawImage(goal1, 400, 145, null);
g.drawImage(goal2, -500, 140, null);
g.drawImage(ball, -20, -200, null);
g.setColor(Color.BLACK);
g.drawLine(0, 603, 1400, 603);
}
}
package sportshead;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import sun.java2d.pipe.DrawImage;
public class Player1 extends JFrame {
private Image image;
private int x=0;
private int y=0;
public int yMove =200;
public int xMove = 200;
public Player1(){
image = new ImageIcon("C:\Test\player1.png").getImage();
addKeyListener( new KeyList());
}
public void paint(Graphics g) {
g.drawImage(image, xMove, yMove, this);
}
public void moveLeft() {
x = xMove--;
}
public void moveRight() {
y = xMove++;
}
public void moveReset(int value) {
xMove = value;
}
// inner class
private class KeyList extends KeyAdapter {
public void keyPressed(KeyEvent k) {
if (k.getKeyCode() == KeyEvent.VK_LEFT){
moveLeft();
}
if (k.getKeyCode() == KeyEvent.VK_RIGHT){
moveRight();
}
}
}
}
package sportshead;
import javax.swing.*;
import java.awt.*;
import java.awt.event.KeyEvent;
import java.awt.image.ImageObserver;
import java.awt.image.ImageProducer;
public class Main extends JFrame{
public static void main(String [] args){
int i =0;
screen s = new screen();
s.loadPics();
Player1 p = new Player1();
for(i=0;i<50;i+=5){
p.xMove+=i;
p.yMove+=i;
p.repaint();
s.loadPics();
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.