Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

**I need help with a Monopoly program for Java. We have to use GUI, Here are the instructions:** Write a GUI-based program that displays a

**I need help with a Monopoly program for Java. We have to use GUI, Here are the instructions:**

Write a GUI-based program that displays a Monopoly game. Add labels for the four train stations, the free space and each of the property spaces. Add buttons for all the Chance cells and set the text of these to a question mark. When the user clicks on one of the buttons, set its text to a message of your choice, chosen randomly from four messages. On the jail spot, create a drop-down list with the choices, "Just Visiting" or "In Jail". If just visiting, display a message, "Good to have a visitor." If in jail, display a message, "Crime doesn't pay!"

I'm having trouble putting one property into one square. I started with the Mediteranean Avenue, and once you look at my code you can see it is only in the bottom row, and I know why it does, it's because it is in the case/ switch. I would like to know how to do this in one square for my program correctly.

Here is my code so far:

public class Monopoly extends JFrame {

public static void main(String[] args) {

Monopoly a = new Monopoly();

a.setVisible(true);

a.setSize(500, 500);

}

public Monopoly() {

try {

// Setup the Layout

setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);

GridBagLayout thisLayout = new GridBagLayout();

thisLayout.rowWeights = new double[] { 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1 };

thisLayout.columnWeights = new double[] { 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1 };

getContentPane().setLayout(thisLayout);

// Default Grid values

int gridX = 0;

int gridY = 0;

// Add Panels for Each of the four sides

for (int j = 0; j < 4; j++) {

for (int i = 0; i < 11; i++) {

JPanel tempPanel = new JPanel();

switch (j) {

case 0:// Top

gridX = i;

gridY = 0;

break;

case 1:// Left

gridX = 0;

gridY = i;

break;

case 2:// Right

gridX = 10;

gridY = i;

break;

case 3:// Bottom

gridX = i;

gridY = 10;

tempPanel.setLayout(new GridBagLayout());

GridBagConstraints c = new GridBagConstraints();

JLabel p1 = new JLabel("Mediteranean Avenue");

tempPanel.add(p1);

break;

}

getContentPane().add(tempPanel,

new GridBagConstraints(gridX,gridY, 1, 1,

0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, // Fill

new Insets(0, 0, 0, 0), 0, 0));

tempPanel.setBorder(BorderFactory.createLineBorder(Color.BLACK));

JButton button;

}

}

JPanel innerPanel = new JPanel();

getContentPane().add(innerPanel, new GridBagConstraints(1, 1, 10, 10, 0.0, 0.0, GridBagConstraints.CENTER,

GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));

innerPanel.setLayout(new GridBagLayout());

JLabel jb = new JLabel("Monolopy");

jb.setVerticalAlignment(SwingConstants.CENTER);

jb.setFont(new Font(jb.getFont().getName(), jb.getFont().getStyle(), 40));

innerPanel.add(jb);

}

catch (Exception e) {

e.printStackTrace();

}

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

c. Determine the confidence intervals of the linearised parameters.

Answered: 1 week ago

Question

Determine the amplitude and period of each function.

Answered: 1 week ago

Question

What is the relationship between humans and nature?

Answered: 1 week ago