Advertisement
Guest User

Untitled

a guest
Apr 26th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.95 KB | None | 0 0
  1. import java.awt.BorderLayout;
  2. import java.awt.GridLayout;
  3. import java.awt.event.ActionEvent;
  4. import java.awt.event.ActionListener;
  5. import java.io.File;
  6. import java.io.FileNotFoundException;
  7. import java.io.PrintStream;
  8. import java.util.Scanner;
  9. import static javax.swing.JOptionPane.*;
  10. import javax.swing.*;
  11. import java.awt.event.*;
  12.  
  13. public class Valutakalkulator extends JFrame implements ActionListener {
  14. private JTextField txtNOK, txtAnnet;
  15. private JLabel label;
  16. private String NOK, Currency;
  17. private double doubleNOK, doubleCurrency;
  18. public Valutakalkulator() {
  19. //Tittel
  20. super("VALUTAKALKULATOR");
  21. JPanel pnlTop = new JPanel();
  22. pnlTop.setLayout(new GridLayout(1, 4));
  23.  
  24. //NOK
  25. pnlTop.add(new JLabel("NOK"));
  26. txtNOK = new JTextField(NOK);
  27. pnlTop.add(txtNOK);
  28.  
  29. //Annen Valuta, vi kan endre Stringen videre
  30. label = new JLabel("Annen Valuta");
  31. pnlTop.add(label);
  32. txtAnnet = new JTextField(Currency);
  33. pnlTop.add(txtAnnet);
  34.  
  35. JPanel pnlSouth = new JPanel();
  36. pnlSouth.setLayout(new GridLayout(1, 4));
  37.  
  38. //Bunn knapper
  39. JButton btnRemoveNOK = new JButton("Fjern NOK");
  40. JButton btnRemoveCurrency = new JButton("Fjern Annen valuta");
  41. JButton btnRemoveBoth = new JButton("Fjern begge");
  42. JButton btnExit = new JButton("Avslutt");
  43.  
  44. btnRemoveNOK.addActionListener(new ActionListener(){
  45. public void actionPerformed(ActionEvent e) {
  46. txtNOK.setText("");
  47. }
  48. });
  49.  
  50. btnRemoveCurrency.addActionListener(new ActionListener(){
  51. public void actionPerformed(ActionEvent e) {
  52. txtAnnet.setText("");
  53. }
  54. });
  55.  
  56. btnRemoveBoth.addActionListener(new ActionListener(){
  57. public void actionPerformed(ActionEvent e) {
  58. txtNOK.setText("");
  59. txtAnnet.setText("");
  60. }
  61. });
  62.  
  63. //Kort avslutt kode
  64. btnExit.addActionListener(new ActionListener(){
  65. public void actionPerformed(ActionEvent e) {
  66. System.exit(0);
  67. }
  68. });
  69.  
  70. pnlSouth.add(btnRemoveNOK);
  71. pnlSouth.add(btnRemoveCurrency);
  72. pnlSouth.add(btnRemoveBoth);
  73. pnlSouth.add(btnExit);
  74.  
  75.  
  76. //Valuta knapper
  77. JPanel pnlSouth1 = new JPanel();
  78. pnlSouth1.setLayout(new GridLayout(2, 2));
  79. JButton btnGBP = new JButton("GBP");
  80. JButton btnEUR = new JButton("EUR");
  81. JButton btnUSD = new JButton("USD");
  82. JButton btnSEK = new JButton("SEK");
  83. btnGBP.addActionListener(this);
  84. btnEUR.addActionListener(this);
  85. btnUSD.addActionListener(this);
  86. btnSEK.addActionListener(this);
  87. pnlSouth1.add(btnGBP);
  88. pnlSouth1.add(btnEUR);
  89. pnlSouth1.add(btnUSD);
  90. pnlSouth1.add(btnSEK);
  91.  
  92.  
  93. add(pnlTop, BorderLayout.NORTH);
  94. add(pnlSouth, BorderLayout.SOUTH);
  95. add(pnlSouth1, BorderLayout.CENTER);
  96.  
  97. setSize(600, 135);
  98. setVisible(true);
  99. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  100. }
  101.  
  102. public void actionPerformed(ActionEvent event) {
  103. if (event.getActionCommand().equals("GBP")) {
  104. //doubleCurrency = Double.parseDouble(Currency);
  105. //System.out.println(doubleCurrency);
  106. label.setText("GBP");
  107. } else if (event.getActionCommand().equals("EUR")) {
  108. label.setText("EUR");
  109. } else if (event.getActionCommand().equals("USD")) {
  110. label.setText("USD");
  111. } else if (event.getActionCommand().equals("SEK")) {
  112. label.setText("SEK");
  113. }
  114. else
  115. {
  116. System.exit(0);
  117. }
  118. }
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement