Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 41 additions & 7 deletions src/MainMenu.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import javax.management.StandardEmitterMBean;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This library is not used anyore in the code (Remove it if you don't need it)

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

Expand All @@ -12,23 +13,54 @@ public class MainMenu extends Screen
*/
MainMenu() {
super();

JPanel gameSelectionPanel = new JPanel();
JPanel gameInfoPanel = new JPanel();

gameSelectionPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(Gui.getMessages().getString("gameSelection")));
gameInfoPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(Gui.getMessages().getString("gameInfo")));

JButton standardGameButton = new JButton(Gui.getMessages().getString("standard"));
JButton duelGameButton = new JButton(Gui.getMessages().getString("duel"));
JButton gameInfoButton = new JButton(Gui.getMessages().getString("help"));
//Construct new Components
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can notice that we use resource bundles instead of typing strings for the names of JLabels and other text field components. The reason we use the resource bundle (e.x. Gui.getMessages().getString("standard") is to use multi-linguar in the program, in other words when a user has the Greek language he/she won't be able to see the text in Greek. So I suggest that you remove any hard coded string you typed and use the strings of the resource bundle. You can check which Strings are available in the bundle in the MessageBundle_en_US.properties file or in any other .properties file.

JLabel title = new JLabel("Memory Game");
JButton standardGameButton = new JButton("Standard");
JButton duelGameButton = new JButton("Duel");
JButton gameInfoButton = new JButton("Help");
//End

//Set properties of new Components
standardGameButton.setBackground(new Color(59, 89, 182));
standardGameButton.setForeground(Color.WHITE);
standardGameButton.setFocusPainted(false);
standardGameButton.setFont(new Font("Tahoma", Font.BOLD, 6));

duelGameButton.setBackground(new Color(59, 89, 182));
duelGameButton.setForeground(Color.WHITE);
duelGameButton.setFocusPainted(false);
duelGameButton.setFont(new Font("Tahoma", Font.BOLD, 6));

gameInfoButton.setBackground(new Color(59, 89, 182));
gameInfoButton.setForeground(Color.WHITE);
gameInfoButton.setFocusPainted(false);
gameInfoButton.setFont(new Font("Tahoma", Font.BOLD, 12));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try and make one Font instance-Object and assign it to the components that use the same Font instead of making new ones each time (ensures code readability)

//End


title.setText("<html><font color=black size=45><b>Memory Game</b></html>");
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't use HTML code just for one text-label, try and replace this with normal java code


//Add Bounds
title.setBounds (575, 45, 500, 70);
standardGameButton.setBounds (385, 200, 255, 60);
standardGameButton.setPreferredSize(new Dimension(255, 60));
duelGameButton.setBounds (770, 200, 255, 60);
duelGameButton.setPreferredSize(new Dimension(255, 60));
gameInfoButton.setBounds(560, 900, 255, 60);

standardGameButton.setFont(getMainFont());
duelGameButton.setFont(getMainFont());
gameInfoButton.setFont(getMainFont());

gameInfoButton.setForeground(Color.BLUE);
gameInfoButton.setPreferredSize(new Dimension(650, 400));
gameInfoButton.setForeground(Color.WHITE);
gameInfoButton.setPreferredSize(new Dimension(255, 60));

gameInfoButton.addActionListener(e -> infoMessage());

Expand All @@ -44,10 +76,12 @@ public class MainMenu extends Screen

GridLayout grid = new GridLayout(2, 0, 10, 20);

gameSelectionPanel.setLayout(grid);
//Added Absolute Positioning
gameSelectionPanel.setLayout(null);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The whole layout seems that is not justified in the middle. Try and make the layout and text be in the middle of the screen.

image

Also please notice that the screen is now too empty, try and make the components a bit bigger

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nikopetr
This is very weird because when I run it on my side I get this

2020-11-10_10-50-15

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess you should test it with different screen sizes as well. Also, make sure to fix the other things mentioned.


gameSelectionPanel.add(standardGameButton);
gameSelectionPanel.add(duelGameButton);
gameSelectionPanel.add(title);
gameInfoPanel.add(gameInfoButton);

getMainFrame().setLayout(grid);
Expand Down