Advertisement
Guest User

Untitled

a guest
Mar 19th, 2019
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.93 KB | None | 0 0
  1. import javax.swing.*;
  2. import java.awt.*;
  3. import javax.swing.JPanel.*;
  4. import javax.swing.JFrame.*;
  5. import java.awt.event.*;
  6.  
  7.  
  8. /**
  9. * Write a description of class chasingBombs here.
  10. *
  11. * @author (your name)
  12. * @version (a version number or a date)
  13. */
  14. public class chasingBombs extends JFrame
  15. {
  16. private JFrame frame = new JFrame("Chasing Bombs");
  17.  
  18. private int ROWS = 2;
  19. private int COLS = 5;
  20. private int GAP = 4;
  21. private int NUM = ROWS * COLS;
  22. private int x;
  23.  
  24. private int score = 0;
  25.  
  26. private JPanel panelLeft = new JPanel(new GridLayout(ROWS, COLS, GAP, GAP));
  27. private JPanel panelMiddle = new JPanel();
  28. private JPanel panelRight = new JPanel();
  29.  
  30. private JLabel [] gamePanel = new JLabel[NUM];
  31. private JLabel scoreBoard = new JLabel(String.valueOf(score));
  32.  
  33. private JButton startButton = new JButton("Start a Game");
  34. private JButton exitButton = new JButton("Exit");
  35. private JButton easy = new JButton("Easy");
  36. private JButton intermediate = new JButton ("Intermediate");
  37. private JButton difficult = new JButton ("Difficult");
  38.  
  39. /**
  40. * Constructor for objects of class chasingBombs
  41. */
  42. public chasingBombs()
  43. {
  44. makeFrame();
  45. }
  46.  
  47. /**
  48. * An example of a method - replace this comment with your own
  49. *
  50. * @param y a sample parameter for a method
  51. * @return the sum of x and y
  52. */
  53. public void makeFrame()
  54. {
  55. frame.setSize(1000,500);
  56. frame.setVisible(true);
  57. frame.setLayout(new GridLayout());
  58.  
  59. leftSetup();
  60. middleSetup();
  61. rightSetup();
  62. }
  63.  
  64. public void leftSetup()
  65. {
  66. frame.add(panelLeft);
  67. panelLeft.setBackground(Color.BLUE);
  68.  
  69. for(x = 0; x < NUM; x++){
  70. gamePanel[x] = new JLabel();
  71. gamePanel[x].setOpaque(true);
  72. gamePanel[x].setBackground(Color.PINK);
  73. gamePanel[x].addMouseListener(new MouseAdapter()
  74. {
  75. @Override
  76. public void mouseReleased(MouseEvent e)
  77. {
  78. System.out.println("Panel Clicked");
  79. }
  80. });
  81. panelLeft.add(gamePanel[x]);
  82. }
  83. }
  84.  
  85. public void middleSetup()
  86. {
  87. frame.add(panelMiddle);
  88. panelMiddle.setBackground(Color.RED);
  89.  
  90. panelMiddle.add(startButton);
  91. panelMiddle.add(exitButton);
  92. panelMiddle.add(scoreBoard);
  93. }
  94.  
  95. public void rightSetup()
  96. {
  97. frame.add(panelRight);
  98. panelRight.setBackground(Color.GREEN);
  99.  
  100. panelRight.add(easy);
  101. panelRight.add(intermediate);
  102. panelRight.add(difficult);
  103. }
  104.  
  105. public void onClick()
  106. {
  107. this.setBackground(Color.GRAY);
  108. }
  109. public void gameplay()
  110. {
  111.  
  112. }
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement