Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.*;
- import java.awt.*;
- import java.awt.event.*;
- public class Thot extends JFrame implements ActionListener
- {
- private JButton button1, button2;
- public static void main(String[] args)
- {
- Thot thot = new Thot();
- thot.setLocationRelativeTo(null);
- thot.setVisible(true);
- }
- public Thot()
- {
- //Init Shit
- super("Thots button shit");
- Container container = this.getContentPane();
- JPanel panel = new JPanel();
- panel.setPreferredSize(new Dimension(250,50));
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- //Button 1
- button1 = new JButton("Click me!");
- button1.addActionListener(this);
- //Button 2
- button2 = new JButton("Hi thar!");
- button2.addActionListener(this);
- //Add buttons to panel
- panel.add(button1);
- panel.add(button2);
- //Add panel to container
- container.add(panel);
- pack();
- }
- public void actionPerformed(ActionEvent e)
- {
- Object source = e.getSource();
- if(source == button1)
- {
- JOptionPane.showMessageDialog(null, "You pressed button 1!",
- "Hi", JOptionPane.INFORMATION_MESSAGE);
- }
- if(source == button2)
- {
- JOptionPane.showMessageDialog(null, "You pressed button 2!",
- "Hi", JOptionPane.INFORMATION_MESSAGE);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement