// CalcView.java - View component // Presentation only. No user actions. No direct interaction with model. // Fred Swartz -- December 2004 // Paolo Bucci -- November 2009 (modified) import java.awt.FlowLayout; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JTextField; public class CalcView extends JPanel { //... Components private JTextField m_userInputTf = new JTextField(5); private JTextField m_totalTf = new JTextField(20); private JButton m_multiplyBtn = new JButton("Multiply"); private JButton m_clearBtn = new JButton("Clear"); //======================================================= constructor /** Constructor */ public CalcView() { //... Initialize components m_totalTf.setEditable(false); //... Layout the components. setLayout(new FlowLayout()); add(new JLabel("Input")); add(m_userInputTf); add(m_multiplyBtn); add(new JLabel("Total")); add(m_totalTf); add(m_clearBtn); // setVisible(true); } String getUserInput() { return m_userInputTf.getText(); } void setTotal(String newTotal) { m_totalTf.setText(newTotal); } void showError(String errMessage) { JOptionPane.showMessageDialog(this, errMessage); } void addMultiplyListener(ActionListener mal) { m_multiplyBtn.addActionListener(mal); } void addClearListener(ActionListener cal) { m_clearBtn.addActionListener(cal); } }