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

Small Refactor

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