Create a user interface that uses the gridlayout manager

Assignment Help Programming Languages
Reference no: EM13167208

(1) The Model Classes:

Define and compile the following two classes that will represent seats in a stadium:

public class Seat {
public static int[] PRICING = {74, 47, 32, 19};

private byte section;
private char row;
private byte number;

public Seat(byte s, char r, byte n) {
section = s;
row = r;
number = n;
}

public byte getSection() { return section; }
public char getRow() { return row; }
public byte getNumber() { return number; }
public int getPrice() { return PRICING[section-1]; }
}

public class Stadium {
public static int ROWS = 27;


public static int COLUMNS = 35;
private static String[] SEAT_NUMBERS = {


};

private static String[] SEAT_ROWS = {

1498_GridLayout manager.png

};

private static String[] SEAT_SECTIONS = {

2281_GridLayout manager1.png

};

private Seat[][] seats;

 

823_GridLayout manager2.png

public Stadium() {
seats = new Seat[ROWS][COLUMNS];

for (int r=0; r< ROWS; r++) {

String secString = SEAT_SECTIONS[r];
String rowString = SEAT_ROWS[r];
String numString = SEAT_NUMBERS[r];
for (int c=0; c< COLUMNS; c++) {
byte section = (byte)Character.digit(secString.charAt(c),10);
char row = (char)rowString.charAt(c);
byte number = (byte)Character.digit(numString.charAt(c),10);
if (!Character.isLetter(row))
seats[r][c] = null;
else
seats[r][c] = new Seat(section, row, number);
}
}
}

public Seat[][] getSeats() { return seats; }
public Seat getSeat(int row, int col) { return seats[row][col]; }
}

When creating a new Stadium, the constructor above will fill a 27x35 two-dimensional array of Seat objects, where each Seat has a number, row and section. There are locations in the stadium where no seat resides ... therefore in the 2D array, there will be some null locations.

(2) The StadiumPanel Class:

Create a subclass of JPanel called StadiumPanel which will display a 2D array of JButtons as follows:

1001_GridLayout manager3.png

The constructor for this class should take a single Stadium parameter and then, using a GridLayout, arrange a 2D array of JButtons as shown above. If there is a Seat at the given row and column of the Stadium, add a JButton at that location in the grid. If there is no Seat (i.e., there is a null in the array) at that location, then add a blank JLabel instead of a JButton at that location in the grid. The background of the StadiumPanel should be white and all JButtons should be colored according to the Seat section that they represent. Section 1 should be red, section 2 green, section 3 blue and section 4 yellow (as shown above). Add the following to the end of your StadiumPanel class to make sure that it displays properly as the window is resized:

Save and compile the following BoardPanel class which represents a fixed-size JPanel:

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

public class BoardPanel extends JPanel {
static int WIDTH = 633, HEIGHT = 462;
public int getWidth() { return WIDTH; }
public int getHeight() { return HEIGHT; }
public Dimension getSize() { return new Dimension(WIDTH, HEIGHT); }
public Dimension getSize(Dimension rv) {
rv.width = WIDTH; rv.height = HEIGHT; return rv;}
public void setBounds(Rectangle r) {
super.setBounds(new Rectangle(r.x, r.y, WIDTH, HEIGHT));
}
public void setBounds(int x, int y, int w, int h) {
super.setBounds(x,y,WIDTH,HEIGHT);
}
public Dimension getMaximumSize() { return new Dimension(WIDTH, HEIGHT); }
public Dimension getMinimumSize() { return new Dimension(WIDTH, HEIGHT); }
public Dimension getPreferredSize() { return new Dimension(WIDTH, HEIGHT); }
public void setSize(Dimension d) { }
public void setSize(int x, int y) { }
}

Change StadiumPanel to be a subclass of BoardPanel. Re-run the code to make sure that it no longer re-sizes as the window re-sizes.

(3) The StadiumApp Class:

Now you will create a StadiumApp class which represents the window shown on the next page. The window must use a GridBagLayout manager. The window has exactly 5 components:

1. a StadiumPanel
2. a JPanel that must use a GridLayout to display the section, row, number and price of a seat.
3. a JPanel that must use a GridLayout to display the price, HST and Total Cost for all selected seats.
4. a Purchase button
5. an Administrator button

Note that you MUST use the layout managers described above, otherwise you WILL NOT receive any marks for this part of the assignment. The window shown has a size of 840 x 505. The window may look weird when re-sized, but that is ok. Once you get it arranged nicely, use setResizable(false) to disable window re-sizing behavior. You may need to then adjust the window size to 840 x 494 or something like that to adjust for the margins which changes when you made it non-resizable. 

575_GridLayout manager4.png

(4) Finishing Touches:

Add a MouseListener to each of the JButtons that represent a seat. Write the mouseEntered(MouseEvent e) and mouseExited(MouseEvent e) methods so that when the mouse hovers over a seat, the section, row, number and price of that seat is displayed in the Seat Information panel on the window. When the mouse leaves a seat, then those text fields should become blank again.

Add a private selected attribute to the Seat class along with public isSelected() and setSelected(boolean s) methods.

Add an ActionListener to each seat's JButton so that when pressed, the Seat clicked on becomes selected. Selected seats should be shown as Color.GRAY. You may want to write an update() method that simply goes through all seats and sets their color to either GRAY (if selected) or their default color as before. Then just call the update() from the ActionListener after you set the seat to be selected or unselected.

In the update() method that you wrote, go through all seats and total up the price for all currently selected seats and show the selected seats combined price in the SELECTED SEAT PRICING panel along with the HST and total Cost. These fields should ALWAYS reflect the totals for currently selected seats (see picture on next page).

304_GridLayout manager5.png

Reference no: EM13167208

Questions Cloud

Enzyme effectively in its metabolic rate : The concentration of an enzyme within a cell is extremely low realtive to other material present, yet functions effectively in its metabolic rate. How can enzyme function and never seem to run out?
How much energy is required to heat the ice : A piece of ice weighs 35.0 g. how much energy is required to heat the ice from a solid at -5.0 degrees C to liquid water at 65.0 degrees C?
Theories of law and schools of jurisprudence : Your text lists and explains eight “theories of law and schools of jurisprudence.” Which of the theories do you think was most influential in the creation of the U.S. legal system, and why?
Nutrition-dieting and organic food : The Omnivore’s Dilemma touches on several specific topics that are a part of our national dialogue on food: nutrition, dieting, and organic food. This dialogue underscores the bigger picture of our need to maintain good health and wellness to live a ..
Create a user interface that uses the gridlayout manager : Define and compile the following two classes that will represent seats in a stadium and When creating a new Stadium, the constructor above will fill a 27x35 two-dimensional array of Seat objects, where each Seat has a number, row and section.
Describing the sensory and perceptual processes-experiment : Explain the outcome of this experiment by identifying and describing the sensory and perceptual processes involved. Be sure to discuss perceptual set?
Explain what specific property of diethyl ether is exploited : what specific property of diethyl ether is exploited here and why is it important to prevent the overheating of the reaction mixture?
What is the apparent order with respect to the dye : A reaction is begun with a reaction mixture containing the following: [dye] = 1.0 x 10-4 M [bleach] = 0.10 M When [dye] = 8.0 x 10-5 M the rate is determined to be 3.74 x 10-7 M/min. When [dye] = 4.0 x 10-5 M the rate is determined to be 1.71 10-7..
Explain net ionic equation at the equivalence point : At the equivalence point all carbonate has been converted to bicarbonate NEt ionic equation before the equivalence point: Net ionic equation at the equivalence point

Reviews

Write a Review

Programming Languages Questions & Answers

  Write a haskell program to calculates a balanced partition

Write a program in Haskell which calculates a balanced partition of N items where each item has a value between 0 and K such that the difference b/w the sum of the values of first partition,

  Create an application to run in the amazon ec2 service

In this project you will create an application to run in the Amazon EC2 service and you will also create a client that can run on local machine and access your application.

  Explain the process to develop a web page locally

Explain the process to develop a Web page locally

  Write functions

These 14 questions covers java class, Array, link list , generic class.

  Programming assignment

If the user wants to read the input from a file, then the output will also go into a different file . If the user wants to read the input interactively, then the output will go to the screen .

  Write a prolog program using swi proglog

Write a Prolog program using swi proglog

  Create a custom application using eclipse

Create a custom Application Using Eclipse Android Development

  Create a application using the mvc architecture

create a application using the MVC architecture. No scripting elements are allowed in JSP pages.

  Develops bespoke solutions for the rubber industry

Develops bespoke solutions for the rubber industry

  Design a program that models the worms behavior

Design a program that models the worm's behavior.

  Writing a class

Build a class for a type called Fraction

  Design a program that assigns seats on an airplane

Write a program that allows an instructor to keep a grade book and also design and implement a program that assigns seats on an airplane.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd