Skip to content
Snippets Groups Projects
Commit 72f0dcd1 authored by Samita Adhikari's avatar Samita Adhikari
Browse files

Small Refactor

parent 5f16b883
Branches
No related tags found
No related merge requests found
...@@ -13,11 +13,10 @@ public class App { ...@@ -13,11 +13,10 @@ public class App {
public static Menu mainMenu; public static Menu mainMenu;
public static GamePanel gamePanel; public static GamePanel gamePanel;
public static ScoringSystem scoreSystem = new ScoringSystem(); public static ScoringSystem scoreSystem = new ScoringSystem();
public static JFrame frame;
public static void main(String[] args) { public static void main(String[] args) {
frame = new JFrame();
JFrame frame = new JFrame();
frame.setBounds(10, 10, 700, 600); frame.setBounds(10, 10, 700, 600);
frame.setTitle("Brick Breaker"); frame.setTitle("Brick Breaker");
frame.setResizable(false); frame.setResizable(false);
...@@ -29,4 +28,12 @@ public class App { ...@@ -29,4 +28,12 @@ public class App {
frame.setVisible(true); frame.setVisible(true);
} }
public static void createGame() {
App.gamePanel = new GamePanel(frame);
}
public static void createMainMenu() {
App.mainMenu = new Menu(frame);
}
} }
...@@ -101,6 +101,8 @@ public class GamePanel extends JPanel implements ActionListener { ...@@ -101,6 +101,8 @@ public class GamePanel extends JPanel implements ActionListener {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
frame.remove(thisPanel); frame.remove(thisPanel);
if(App.mainMenu == null) App.createMainMenu();
App.mainMenu.show(); App.mainMenu.show();
frame.revalidate(); frame.revalidate();
frame.repaint(); frame.repaint();
......
...@@ -27,6 +27,7 @@ public class Menu extends JPanel { ...@@ -27,6 +27,7 @@ public class Menu extends JPanel {
private JFrame frame; private JFrame frame;
private Timer animationTimer; private Timer animationTimer;
private int textPosition = -200; private int textPosition = -200;
public Menu(JFrame frame) { public Menu(JFrame frame) {
this.frame = frame; this.frame = frame;
initComponents(); initComponents();
...@@ -117,7 +118,7 @@ public class Menu extends JPanel { ...@@ -117,7 +118,7 @@ public class Menu extends JPanel {
guest.setActionCommand("play"); guest.setActionCommand("play");
guest.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR)); guest.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
guest.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); guest.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
guest.setLabel("Play as Guest"); guest.setLabel("Play Now");
guest.addActionListener(new java.awt.event.ActionListener() { guest.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) { public void actionPerformed(java.awt.event.ActionEvent evt) {
guestActionPerformed(evt); guestActionPerformed(evt);
...@@ -150,7 +151,7 @@ public class Menu extends JPanel { ...@@ -150,7 +151,7 @@ public class Menu extends JPanel {
.addGap(301, 301, 301) .addGap(301, 301, 301)
.addComponent(registerButton)) .addComponent(registerButton))
.addGroup(layout.createSequentialGroup() .addGroup(layout.createSequentialGroup()
.addGap(282, 282, 282) .addGap(301, 301, 301)
.addComponent(guest)) .addComponent(guest))
.addGroup(layout.createSequentialGroup() .addGroup(layout.createSequentialGroup()
.addGap(290, 290, 290) .addGap(290, 290, 290)
...@@ -185,7 +186,9 @@ public class Menu extends JPanel { ...@@ -185,7 +186,9 @@ public class Menu extends JPanel {
private void guestActionPerformed(java.awt.event.ActionEvent evt) { private void guestActionPerformed(java.awt.event.ActionEvent evt) {
this.setVisible(false); this.setVisible(false);
if(App.gamePanel == null)
App.createGame();
frame.add(App.gamePanel);
} }
private void highScoreActionPerformed(java.awt.event.ActionEvent evt) { private void highScoreActionPerformed(java.awt.event.ActionEvent evt) {
...@@ -209,7 +212,6 @@ public class Menu extends JPanel { ...@@ -209,7 +212,6 @@ public class Menu extends JPanel {
if(App.user != null) { if(App.user != null) {
this.remove(loginButton); this.remove(loginButton);
this.remove(registerButton); this.remove(registerButton);
this.remove(guest);
} }
frame.add(this); frame.add(this);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment