import javax.swing.*; import java.awt.event.*; public class FirstWindow extends JFrame{ private JLabel lblQuantity; private JLabel lblPrice; private JTextField txtQuantity; private JTextField txtPrice; private JTextField txtResult; private JButton btnCalculate; private JPanel panel; public FirstWindow() { super("First Application!!!"); setSize(250,300); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setVisible(true); buildPanel(); add(panel); //pack(); } public void buildPanel() { panel = new JPanel(); lblQuantity = new JLabel("Enter a quantity"); lblPrice = new JLabel("Enter a price"); txtQuantity = new JTextField("test", 15); txtPrice = new JTextField("test", 15); btnCalculate = new JButton("Calculate!"); txtResult = new JTextField(10); panel.add(lblQuantity); panel.add(txtQuantity); panel.add(lblPrice); panel.add(txtPrice); panel.add(txtResult); panel.add(btnCalculate); btnCalculate.addActionListener(new CalcButtonListener()); } private class CalcButtonListener implements ActionListener { public void actionPerformed(ActionEvent e) { String strQuantity = txtQuantity.getText(); String strPrice = txtPrice.getText(); double result = Double.parseDouble(strQuantity) * Double.parseDouble(strPrice); txtResult.setText(result + ""); } } }