Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.26 KB | None | 0 0
  1. import javax.swing.*;
  2. import java.awt.*;
  3. import java.awt.event.*;
  4.  
  5. public class Thot extends JFrame implements ActionListener
  6. {  
  7.     private JButton button1, button2;
  8.    
  9.     public static void main(String[] args)
  10.     {
  11.         Thot thot = new Thot();
  12.         thot.setLocationRelativeTo(null);
  13.         thot.setVisible(true);
  14.     }
  15.    
  16.     public Thot()
  17.     {
  18.         //Init Shit
  19.         super("Thots button shit");        
  20.         Container container = this.getContentPane();
  21.         JPanel panel = new JPanel();
  22.         panel.setPreferredSize(new Dimension(250,50));
  23.         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);    
  24.        
  25.         //Button 1
  26.         button1 = new JButton("Click me!");
  27.         button1.addActionListener(this);
  28.        
  29.         //Button 2
  30.         button2 = new JButton("Hi thar!");
  31.         button2.addActionListener(this);
  32.        
  33.         //Add buttons to panel
  34.         panel.add(button1);
  35.         panel.add(button2);
  36.        
  37.         //Add panel to container
  38.         container.add(panel);
  39.         pack();
  40.     }
  41.  
  42.     public void actionPerformed(ActionEvent e)
  43.     {
  44.         Object source = e.getSource();
  45.        
  46.         if(source == button1)
  47.         {
  48.             JOptionPane.showMessageDialog(null, "You pressed button 1!",
  49.             "Hi",   JOptionPane.INFORMATION_MESSAGE);
  50.         }
  51.        
  52.         if(source == button2)
  53.         {
  54.             JOptionPane.showMessageDialog(null, "You pressed button 2!",
  55.             "Hi", JOptionPane.INFORMATION_MESSAGE);
  56.         }
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement