Guest User

Untitled

a guest
Dec 23rd, 2020
33
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import javax.swing.*;
  2. import javax.swing.event.ListDataListener;
  3. import java.awt.*;
  4. import java.awt.event.*;
  5.  
  6. public class GUI {
  7.     private int clicks = 0;
  8.     private JLabel label = new JLabel("Number of clicks:  0     ");
  9.     private JFrame frame = new JFrame();
  10.     private String[] listOfGhost = new String[] {"Not selected", "Spirit", "Wraith", "Phantom", "Poltergeist", "Banshee", "Jinn", "Mare", "Revenant", "Shade", "Demon", "Yurei", "Oni"};
  11.  
  12.     public GUI() {
  13.  
  14.         // the clickable button
  15.         //JButton button = new JButton("Click Me");
  16.         //button.addActionListener(this);
  17.  
  18.         // the panel with the button and text
  19.         JPanel panel = new JPanel();
  20.         panel.setBorder(BorderFactory.createEmptyBorder(100, 100, 100, 100));
  21.         panel.setLayout(new GridLayout(0, 1));
  22.         //panel.add(button);
  23.         //panel.add(reset);
  24.         //panel.add(ghost);
  25.         panel.add(label);
  26.  
  27.         // set up the frame and display it
  28.         frame.add(panel, BorderLayout.WEST);
  29.         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  30.         frame.setTitle("GUI");
  31.         frame.pack();
  32.         frame.setVisible(true);
  33.     }
  34.  
  35.     JButton button = new JButton(new AbstractAction("Click Me") {
  36.         @Override
  37.         public void actionPerformed( ActionEvent e ) {
  38.             clicks++;
  39.             label.setText("Number of clicks:  " + clicks);
  40.         }
  41.     });
  42.  
  43.     JButton reset = new JButton(new AbstractAction("Reset") {
  44.         @Override
  45.         public void actionPerformed( ActionEvent e ) {
  46.             clicks = 0;
  47.             label.setText("Number of clicks:  " + clicks);
  48.         }
  49.     });
  50.  
  51.     //JComboBox<String> ghost = new JComboBox<String>(new AbstractAction("lol") {});
  52.  
  53.     /*JComboBox<String> ghost = new JComboBox<String> (new AbstractAction(listOfGhost) {
  54.         @Override
  55.         public void itemStateChanged(ItemEvent e) {
  56.  
  57.         }
  58.     });*/
  59.  
  60.     // create one Frame
  61.     public static void main(String[] args) {
  62.         new GUI();
  63.     }
  64. }
RAW Paste Data