Guest User

Untitled

a guest
Oct 18th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. package knapp;
  2. import java.awt.*;
  3. import java.awt.event.*;
  4.  
  5. import javax.swing.*;
  6.  
  7. public class knapp extends JFrame implements ActionListener {
  8. JButton k1, k2, k3;
  9. String fn;
  10. String ln;
  11. String petter;
  12.  
  13. public knapp(){
  14. this.setSize(400,100);
  15. this.setTitle("My Program");
  16. this.setVisible(true);
  17. this.setLocationRelativeTo(null);
  18. this.setLayout(new FlowLayout());
  19.  
  20. Container content = getContentPane();
  21.  
  22. k1 = new JButton("Close Program");
  23. k1.setActionCommand("Exit");
  24.  
  25. k2 = new JButton("Enter name");
  26. k2.setActionCommand("Name");
  27.  
  28. k3 = new JButton("Klikk");
  29. k3.setActionCommand("fucked");
  30.  
  31. k1.addActionListener(this);
  32. k2.addActionListener(this);
  33. k3.addActionListener(this);
  34.  
  35. content.add(k1, BorderLayout.NORTH);
  36. content.add(k2, BorderLayout.WEST);
  37. content.add(k3, BorderLayout.SOUTH);
  38. }
  39. public void actionPerformed(ActionEvent e){
  40. if(e.getActionCommand().equals("Exit")){
  41. System.exit(0);
  42. }
  43.  
  44. if(e.getActionCommand().equals("Name")){
  45. fn = JOptionPane.showInputDialog("Enter First Name: ");
  46. ln = JOptionPane.showInputDialog("Enter Last Name: ");
  47.  
  48. JOptionPane.showMessageDialog(null, "Hello " + fn + " " + ln);
  49.  
  50. }
  51. if(e.getActionCommand().equals("fucked")){
  52. petter = JOptionPane.showInputDialog("Skriv inn fornavnet ditt her: ");
  53. JOptionPane.showMessageDialog(null, petter + ", du er FUCKED!");
  54. }
  55. }
  56.  
  57. public static void main(String[] args){
  58. new knapp();
  59. }
  60. }
Add Comment
Please, Sign In to add comment