Friday, September 27, 2013

Exercise no. 42

package lord1;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.JComboBox;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JSeparator;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
import javax.swing.JButton;
import javax.swing.event.CaretListener;
import javax.swing.event.CaretEvent;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.InputMethodListener;
import java.awt.event.InputMethodEvent;

public class caculate extends JFrame {

private JPanel contentPane;
private JTextField tfNumforCH;
private JTextField tfNumforT;
private JTextField tfNumforA;
private JTextField textField;
private JTextField textField_1;
private JTextField textField_2;
private JTextField textField_3;

/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {caculate frame = new caculate();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}

/**
* Create the frame.
*/
public caculate() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);

JLabel lblWelcomeToPeoples = new JLabel("Welcome to Peoples Park Davao");
lblWelcomeToPeoples.setFont(new Font("Times New Roman", Font.BOLD, 20));
lblWelcomeToPeoples.setBounds(85, 11, 282, 25);
contentPane.add(lblWelcomeToPeoples);

JLabel lblEntranceFeeFor = new JLabel("Entrance fee for");
lblEntranceFeeFor.setBounds(108, 48, 109, 25);
contentPane.add(lblEntranceFeeFor);

JLabel lblChildrenBelow = new JLabel("Children below 8");
lblChildrenBelow.setBounds(108, 84, 98, 14);
contentPane.add(lblChildrenBelow);

JLabel lblNewLabel = new JLabel("Tennager 17 below");
lblNewLabel.setBounds(108, 109, 109, 14);
contentPane.add(lblNewLabel);

JLabel lblAdult = new JLabel("Adult");
lblAdult.setBounds(108, 134, 81, 14);
contentPane.add(lblAdult);

JLabel lblFees = new JLabel("Fees");
lblFees.setBounds(269, 52, 46, 14);
contentPane.add(lblFees);

JLabel lblphp = new JLabel("5 php");
lblphp.setBounds(269, 84, 46, 14);
contentPane.add(lblphp);

JLabel lblphp_1 = new JLabel("7 php");
lblphp_1.setBounds(269, 109, 46, 14);
contentPane.add(lblphp_1);

JLabel lblphp_2 = new JLabel("10 php");
lblphp_2.setBounds(269, 134, 46, 14);
contentPane.add(lblphp_2);

JLabel lblNewLabel_1 = new JLabel("Payment Here:");
lblNewLabel_1.setFont(new Font("Tahoma", Font.BOLD, 11));
lblNewLabel_1.setBounds(10, 160, 98, 14);
contentPane.add(lblNewLabel_1);

JLabel lblNewLabel_2 = new JLabel("Children");
lblNewLabel_2.setBounds(108, 175, 45, 15);
contentPane.add(lblNewLabel_2);

JLabel lblTeenager = new JLabel("Teenager");
lblTeenager.setBounds(108, 195, 81, 15);
contentPane.add(lblTeenager);

JLabel label_1 = new JLabel("Children");
label_1.setBounds(108, 215, 45, 15);
contentPane.add(label_1);

tfNumforCH = new JTextField();
tfNumforCH.addFocusListener(new FocusAdapter() {
public void focusLost(FocusEvent arg0) {
int num1 = Integer.parseInt(tfNumforCH.getText());
int total = num1 * 5;
textField.setText(""+total);

textField_3.setText(""+total);
}
});
tfNumforCH.setBounds(270, 175, 35, 15);
contentPane.add(tfNumforCH);
tfNumforCH.setColumns(10);

tfNumforT = new JTextField();
tfNumforT.addFocusListener(new FocusAdapter() {
@Override
public void focusLost(FocusEvent e) {
int num1 = Integer.parseInt(tfNumforT.getText());
int num2 = Integer.parseInt(tfNumforCH.getText());
int total = num1 * 7;
textField_1.setText(""+total);
int total1 = total + num2;
textField_3.setText(""+total1);
}
});
tfNumforT.setColumns(10);
tfNumforT.setBounds(270, 195, 35, 15);
contentPane.add(tfNumforT);

tfNumforA = new JTextField();
tfNumforA.addFocusListener(new FocusAdapter() {
public void focusLost(FocusEvent e) {
int num1 = Integer.parseInt(tfNumforA.getText());
int total = num1 * 10;
textField_2.setText(""+total);

int num01 = Integer.parseInt(textField.getText());
int num02 = Integer.parseInt(textField_1.getText());
int num03 = Integer.parseInt(textField_2.getText());
int total1 = num01 + num02 + num03;

textField_3.setText(""+total1);
}
});
tfNumforA.setColumns(10);
tfNumforA.setBounds(269, 215, 35, 15);
contentPane.add(tfNumforA);

JSeparator separator = new JSeparator();
separator.setBounds(345, 233, 50, 2);
contentPane.add(separator);

JLabel lblNewLabel_3 = new JLabel("Total");
lblNewLabel_3.setBounds(310, 237, 46, 14);
contentPane.add(lblNewLabel_3);

textField = new JTextField();
textField.setEditable(false);
textField.setEnabled(false);
textField.setColumns(10);
textField.setBounds(349, 175, 35, 15);
contentPane.add(textField);

textField_1 = new JTextField();
textField_1.setEnabled(false);
textField_1.setEditable(false);
textField_1.setColumns(10);
textField_1.setBounds(349, 195, 35, 15);
contentPane.add(textField_1);

textField_2 = new JTextField();
textField_2.setEnabled(false);
textField_2.setEditable(false);
textField_2.setColumns(10);
textField_2.setBounds(349, 215, 35, 15);
contentPane.add(textField_2);

textField_3 = new JTextField();
textField_3.setEnabled(false);
textField_3.setEditable(false);
textField_3.setColumns(10);
textField_3.setBounds(350, 236, 35, 15);
contentPane.add(textField_3);

JButton submit = new JButton("Submit");
submit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
JOptionPane.showMessageDialog(null, "OK");
}
});
submit.setBounds(230, 235, 75, 21);
contentPane.add(submit);
}
}

No comments:

Post a Comment