Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.BorderLayout;
- import java.awt.GridLayout;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.io.PrintStream;
- import java.util.Scanner;
- import static javax.swing.JOptionPane.*;
- import javax.swing.*;
- import java.awt.event.*;
- public class Valutakalkulator extends JFrame implements ActionListener {
- private JTextField txtNOK, txtAnnet;
- private JLabel label;
- private String NOK, Currency;
- private double doubleNOK, doubleCurrency;
- public Valutakalkulator() {
- //Tittel
- super("VALUTAKALKULATOR");
- JPanel pnlTop = new JPanel();
- pnlTop.setLayout(new GridLayout(1, 4));
- //NOK
- pnlTop.add(new JLabel("NOK"));
- txtNOK = new JTextField(NOK);
- pnlTop.add(txtNOK);
- //Annen Valuta, vi kan endre Stringen videre
- label = new JLabel("Annen Valuta");
- pnlTop.add(label);
- txtAnnet = new JTextField(Currency);
- pnlTop.add(txtAnnet);
- JPanel pnlSouth = new JPanel();
- pnlSouth.setLayout(new GridLayout(1, 4));
- //Bunn knapper
- JButton btnRemoveNOK = new JButton("Fjern NOK");
- JButton btnRemoveCurrency = new JButton("Fjern Annen valuta");
- JButton btnRemoveBoth = new JButton("Fjern begge");
- JButton btnExit = new JButton("Avslutt");
- btnRemoveNOK.addActionListener(new ActionListener(){
- public void actionPerformed(ActionEvent e) {
- txtNOK.setText("");
- }
- });
- btnRemoveCurrency.addActionListener(new ActionListener(){
- public void actionPerformed(ActionEvent e) {
- txtAnnet.setText("");
- }
- });
- btnRemoveBoth.addActionListener(new ActionListener(){
- public void actionPerformed(ActionEvent e) {
- txtNOK.setText("");
- txtAnnet.setText("");
- }
- });
- //Kort avslutt kode
- btnExit.addActionListener(new ActionListener(){
- public void actionPerformed(ActionEvent e) {
- System.exit(0);
- }
- });
- pnlSouth.add(btnRemoveNOK);
- pnlSouth.add(btnRemoveCurrency);
- pnlSouth.add(btnRemoveBoth);
- pnlSouth.add(btnExit);
- //Valuta knapper
- JPanel pnlSouth1 = new JPanel();
- pnlSouth1.setLayout(new GridLayout(2, 2));
- JButton btnGBP = new JButton("GBP");
- JButton btnEUR = new JButton("EUR");
- JButton btnUSD = new JButton("USD");
- JButton btnSEK = new JButton("SEK");
- btnGBP.addActionListener(this);
- btnEUR.addActionListener(this);
- btnUSD.addActionListener(this);
- btnSEK.addActionListener(this);
- pnlSouth1.add(btnGBP);
- pnlSouth1.add(btnEUR);
- pnlSouth1.add(btnUSD);
- pnlSouth1.add(btnSEK);
- add(pnlTop, BorderLayout.NORTH);
- add(pnlSouth, BorderLayout.SOUTH);
- add(pnlSouth1, BorderLayout.CENTER);
- setSize(600, 135);
- setVisible(true);
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- }
- public void actionPerformed(ActionEvent event) {
- if (event.getActionCommand().equals("GBP")) {
- //doubleCurrency = Double.parseDouble(Currency);
- //System.out.println(doubleCurrency);
- label.setText("GBP");
- } else if (event.getActionCommand().equals("EUR")) {
- label.setText("EUR");
- } else if (event.getActionCommand().equals("USD")) {
- label.setText("USD");
- } else if (event.getActionCommand().equals("SEK")) {
- label.setText("SEK");
- }
- else
- {
- System.exit(0);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement