Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ConvertorValutar;
- import javax.swing.*;
- import java.awt.event.*;
- import java.awt.*;
- import java.lang.StrictMath;
- import java.math.BigInteger;
- public class View extends JFrame {
- private String[] optiuni = { "EUR - European Euro", "USD - American Dollar", "GBP - Great Britain Pound" };
- private JComboBox options = new JComboBox(optiuni);
- private JTextField userInput = new JTextField(5);
- private JTextField output = new JTextField(5);
- private JButton convert = new JButton("Convert");
- private JButton clear = new JButton("Clear");
- private Model m_model;
- public View(Model model) {
- m_model = model;
- model.setValue(Model.INITIAL_VALUE);
- output.setText(model.getValue());
- output.setEditable(false);
- JPanel content = new JPanel();
- content.setLayout(new FlowLayout());
- content.add(options);
- content.add(new JLabel("Input"));
- content.add(userInput);
- content.add(convert);
- content.add(new JLabel("Output"));
- content.add(output);
- content.add(clear);
- convert.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- try {
- String input = "";
- input = userInput.getText();
- if ((options.getSelectedItem().toString()).equals("EUR - European Euro")) {
- model.currencyConversionEuro(input);
- } else {
- if ((options.getSelectedItem().toString()).equals("USD - American Dollar")) {
- model.currencyConversionUSD(input);
- } else {
- if ((options.getSelectedItem().toString()).equals("GBP - Great Britain Pound")) {
- model.currencyConversionGBP(input);
- }
- }
- }
- setTotal(model.getValue());
- } catch (NumberFormatException nformat) {
- showError("Eroare. A crapat");
- }
- }
- });
- clear.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- try {
- reset();
- model.reset();
- } catch (NumberFormatException nformat) {
- showError("Salut");
- }
- }
- });
- this.setContentPane(content);
- this.pack();
- this.setTitle("Convertor Valutar");
- this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- }
- public void reset() {
- output.setText(Model.INITIAL_VALUE);
- }
- public String getUserInput() {
- return userInput.getText();
- }
- public void setTotal(String newTotal) {
- output.setText(newTotal);
- }
- public void showError(String errMsg) {
- JOptionPane.showMessageDialog(this, errMsg);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement