Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package javaapplication;
- import java.awt.*;
- import java.awt.event.*;
- public class De7 extends Frame implements ActionListener {
- Label lbFormTest, lbBasicSalary, lbRate, lbSalary;
- TextField tfBasicSalary, tfRate, tfSalary;
- Button btCalculate;
- GridBagLayout gb;
- GridBagConstraints gbc;
- public De7(String title) {
- super(title);
- this.addWindowListener(new WindowAdapter() {
- public void windowClosing(WindowEvent we) {
- System.exit(0);
- }
- });
- lbFormTest = new Label("FormTest");
- lbBasicSalary = new Label("BasicSalary");
- lbRate = new Label("Rate");
- lbSalary = new Label("Salary");
- tfBasicSalary = new TextField(20);
- tfRate = new TextField(20);
- tfSalary = new TextField(20);
- btCalculate = new Button("Calculate");
- tfSalary.setEnabled(false);
- gb = new GridBagLayout();
- this.setLayout(gb);
- this.Them(lbFormTest, 1, 0, 1, 1);
- this.Them(lbBasicSalary, 0, 1, 1, 1);
- this.Them(lbRate, 0, 2, 1, 1);
- this.Them(lbSalary, 0, 3, 1, 1);
- this.Them(tfBasicSalary, 1, 1, 1, 1);
- this.Them(tfRate, 1, 2, 1, 1);
- this.Them(tfSalary, 1, 3, 1, 1);
- this.Them(btCalculate, 1, 4, 1, 1);
- btCalculate.addActionListener(this);
- }
- public void Them(Component comp, int x, int y, int rong, int cao) {
- gbc = new GridBagConstraints();
- gbc.gridx = x;
- gbc.gridy = y;
- gbc.gridwidth = rong;
- gbc.gridheight = cao;
- gb.setConstraints(comp, gbc);
- this.add(comp);
- }
- public static void main(String[] args) {
- De7 fr = new De7("Thieu Mao");
- fr.setSize(400, 300);
- fr.setVisible(true);
- }
- public void actionPerformed(ActionEvent a) {
- if(a.getSource()==btCalculate){
- if(tfBasicSalary.getText().isEmpty()){
- System.out.println("Loi");
- }else{
- if(tfRate.getText().isEmpty()){
- try{
- float bs = Float.valueOf(tfBasicSalary.getText());
- float salary = (float) (bs*2.34);
- tfSalary.setText(String.valueOf(salary));
- }catch(Exception e){
- System.out.println("Da Loi");
- }
- }else{
- try {
- float bs = Float.valueOf(tfBasicSalary.getText());
- float rate = Float.valueOf(tfRate.getText());
- float salary = (float) (rate*bs);
- tfSalary.setText(String.valueOf(salary));
- } catch (Exception e) {
- System.out.println("Da Loi Roi");
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment