Advertisement
Guest User

Untitled

a guest
Dec 13th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.43 KB | None | 0 0
  1. package ConvertorValutar;
  2.  
  3. import javax.swing.*;
  4. import java.awt.event.*;
  5. import java.awt.*;
  6. import java.lang.StrictMath;
  7. import java.math.BigInteger;
  8.  
  9. public class View extends JFrame {
  10. private String[] optiuni = { "EUR - European Euro", "USD - American Dollar", "GBP - Great Britain Pound" };
  11. private JComboBox options = new JComboBox(optiuni);
  12. private JTextField userInput = new JTextField(5);
  13. private JTextField output = new JTextField(5);
  14. private JButton convert = new JButton("Convert");
  15. private JButton clear = new JButton("Clear");
  16. private Model m_model;
  17.  
  18. public View(Model model) {
  19. m_model = model;
  20. model.setValue(Model.INITIAL_VALUE);
  21.  
  22. output.setText(model.getValue());
  23. output.setEditable(false);
  24.  
  25. JPanel content = new JPanel();
  26. content.setLayout(new FlowLayout());
  27. content.add(options);
  28. content.add(new JLabel("Input"));
  29. content.add(userInput);
  30. content.add(convert);
  31. content.add(new JLabel("Output"));
  32. content.add(output);
  33. content.add(clear);
  34. convert.addActionListener(new ActionListener() {
  35. public void actionPerformed(ActionEvent e) {
  36. try {
  37. String input = "";
  38. input = userInput.getText();
  39.  
  40. if ((options.getSelectedItem().toString()).equals("EUR - European Euro")) {
  41. model.currencyConversionEuro(input);
  42. } else {
  43. if ((options.getSelectedItem().toString()).equals("USD - American Dollar")) {
  44. model.currencyConversionUSD(input);
  45. } else {
  46. if ((options.getSelectedItem().toString()).equals("GBP - Great Britain Pound")) {
  47. model.currencyConversionGBP(input);
  48. }
  49. }
  50. }
  51.  
  52. setTotal(model.getValue());
  53. } catch (NumberFormatException nformat) {
  54. showError("Eroare. A crapat");
  55. }
  56. }
  57. });
  58.  
  59. clear.addActionListener(new ActionListener() {
  60. public void actionPerformed(ActionEvent e) {
  61. try {
  62. reset();
  63. model.reset();
  64. } catch (NumberFormatException nformat) {
  65. showError("Salut");
  66. }
  67. }
  68. });
  69.  
  70. this.setContentPane(content);
  71. this.pack();
  72. this.setTitle("Convertor Valutar");
  73. this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  74. }
  75.  
  76. public void reset() {
  77. output.setText(Model.INITIAL_VALUE);
  78. }
  79.  
  80. public String getUserInput() {
  81. return userInput.getText();
  82. }
  83.  
  84. public void setTotal(String newTotal) {
  85. output.setText(newTotal);
  86. }
  87.  
  88. public void showError(String errMsg) {
  89. JOptionPane.showMessageDialog(this, errMsg);
  90. }
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement