Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.42 KB | None | 0 0
  1. import java.awt.GridBagConstraints;
  2. import java.awt.GridBagLayout;
  3. import java.awt.event.ActionEvent;
  4. import java.awt.event.ActionListener;
  5.  
  6. import javax.swing.JButton;
  7. import javax.swing.JFrame;
  8. import javax.swing.JPanel;
  9.  
  10. public class guii {
  11.     static class GUI extends JFrame {
  12.         private static final long serialVersionUID = 1L;
  13.         private JFrame frame;
  14.         private JPanel panel;
  15.         private JButton startbutton, cancelbutton;
  16.         private GridBagConstraints c = new GridBagConstraints();
  17.  
  18.         public GUI() {
  19.             createAndShowGui();
  20.             frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
  21.         }
  22.  
  23.         public void createAndShowGui() {
  24.             frame = new JFrame("GUI");
  25.             frame.setResizable(false);
  26.             frame.setSize(300, 300);
  27.             panel = new JPanel(new GridBagLayout());
  28.             frame.add(panel);
  29.             c.gridx = 5;
  30.             c.gridy = 5;
  31.             startbutton = new JButton("start");
  32.             cancelbutton = new JButton("quit");
  33.             panel.add(startbutton, c);
  34.             panel.add(cancelbutton);
  35.             startbutton.addActionListener(new ActionListener() {
  36.  
  37.                 @Override
  38.                 public void actionPerformed(ActionEvent e) {
  39.                     System.out.println("start");
  40.                     dispose();
  41.                 }
  42.  
  43.             });
  44.             cancelbutton.addActionListener(new ActionListener() {
  45.  
  46.                 @Override
  47.                 public void actionPerformed(ActionEvent e) {
  48.                     System.out.println("cancel");
  49.                     dispose();
  50.  
  51.                 }
  52.             });
  53.         }
  54.     }
  55.  
  56.     public static void main(String[] args) {
  57.         final GUI gui = new GUI();
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement