Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package knapp;
- import java.awt.*;
- import java.awt.event.*;
- import javax.swing.*;
- public class knapp extends JFrame implements ActionListener {
- JButton k1, k2, k3;
- String fn;
- String ln;
- String petter;
- public knapp(){
- this.setSize(400,100);
- this.setTitle("My Program");
- this.setVisible(true);
- this.setLocationRelativeTo(null);
- this.setLayout(new FlowLayout());
- Container content = getContentPane();
- k1 = new JButton("Close Program");
- k1.setActionCommand("Exit");
- k2 = new JButton("Enter name");
- k2.setActionCommand("Name");
- k3 = new JButton("Klikk");
- k3.setActionCommand("fucked");
- k1.addActionListener(this);
- k2.addActionListener(this);
- k3.addActionListener(this);
- content.add(k1, BorderLayout.NORTH);
- content.add(k2, BorderLayout.WEST);
- content.add(k3, BorderLayout.SOUTH);
- }
- public void actionPerformed(ActionEvent e){
- if(e.getActionCommand().equals("Exit")){
- System.exit(0);
- }
- if(e.getActionCommand().equals("Name")){
- fn = JOptionPane.showInputDialog("Enter First Name: ");
- ln = JOptionPane.showInputDialog("Enter Last Name: ");
- JOptionPane.showMessageDialog(null, "Hello " + fn + " " + ln);
- }
- if(e.getActionCommand().equals("fucked")){
- petter = JOptionPane.showInputDialog("Skriv inn fornavnet ditt her: ");
- JOptionPane.showMessageDialog(null, petter + ", du er FUCKED!");
- }
- }
- public static void main(String[] args){
- new knapp();
- }
- }
Add Comment
Please, Sign In to add comment