Advertisement
Guest User

Untitled

a guest
Apr 15th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.83 KB | None | 0 0
  1. package AddingMachine;
  2.  
  3. import java.awt.event.ActionEvent;
  4. import java.awt.event.ActionListener;
  5.  
  6. public class AddControl implements ActionListener {
  7.     private AddView view;
  8.     private AddModel model;
  9.  
  10.     public AddControl(AddView v, AddModel m){
  11.         view=v;
  12.         model=m;
  13.         view.getSumButton().addActionListener(this);
  14.     }
  15.  
  16.     @Override
  17.     public void actionPerformed(ActionEvent actionEvent) {
  18.         if(actionEvent.getSource()==view.getSumButton()){
  19.             getDataFromFields();
  20.             model.sumNumbers();
  21.             view.getResultLabel().setText("="+model.getResult());
  22.         }
  23.     }
  24.  
  25.     public void getDataFromFields(){
  26.         model.setOperand1(Integer.parseInt(view.getOp1Field().getText()));
  27.         model.setOperand2(Integer.parseInt(view.getOp2Field().getText()));
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement