-
Notifications
You must be signed in to change notification settings - Fork 2
Improved GUI #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Improved GUI #2
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| import javax.management.StandardEmitterMBean; | ||
| import javax.swing.*; | ||
| import java.awt.*; | ||
|
|
||
|
|
@@ -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 | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| 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)); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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>"); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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()); | ||
|
|
||
|
|
@@ -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); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @nikopetr
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
|
|
||


There was a problem hiding this comment.
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)