Advertisement
Guest User

ButtonPanel

a guest
Jun 22nd, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.awt.*;
  2. import java.awt.event.ActionEvent;
  3. import java.awt.event.ActionListener;
  4.  
  5. import javax.swing.JButton;
  6. import javax.swing.JPanel;
  7.  
  8. public class ButtonPanel extends JPanel{
  9.  
  10.     public static final int HEIGHT = 100;
  11.     public static final int WIDTH = 300;
  12.     public JButton newG, exitG, rankG;
  13.  
  14.     private JPanel buttonPanel;
  15.  
  16.     public ButtonPanel() {
  17.         newG = new JButton("New Game");
  18.                 exitG = new JButton("Exit");
  19.                 rankG = new JButton("Ranking");
  20.                 newG.addActionListener((ActionListener) this);
  21.                 exitG.addActionListener((ActionListener) this);
  22.                 rankG.addActionListener((ActionListener) this);
  23.                
  24.                 buttonPanel = this;
  25.  
  26.         setLayout(new FlowLayout());
  27.         setPreferredSize(new Dimension(WIDTH, HEIGHT));
  28.         add(newG);
  29.                 add(exitG);
  30.                 add(rankG);
  31.        
  32.     }
  33.  
  34.     class NewGButton extends JButton implements ActionListener {
  35.  
  36.         NewGButton() {
  37.            
  38.             addActionListener(this);
  39.         }
  40.  
  41.         @Override
  42.         public void actionPerformed(ActionEvent e) {
  43.             buttonPanel.setBackground(Color.GREEN);
  44.         }
  45.     }
  46.  
  47.     class ExitGButton extends JButton implements ActionListener {
  48.  
  49.         ExitGButton() {
  50.             addActionListener(this);
  51.         }
  52.  
  53.         @Override
  54.         public void actionPerformed(ActionEvent e) {
  55.            
  56.         }
  57.     }
  58.  
  59.     class RankGButton extends JButton implements ActionListener {
  60.  
  61.         RankGButton() {
  62.             addActionListener(this);
  63.         }
  64.  
  65.         @Override
  66.         public void actionPerformed(ActionEvent e) {
  67.            
  68.         }
  69.     }
  70.  
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement