Advertisement
Rhull1188

rhullfin1

Nov 24th, 2022
728
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.45 KB | Source Code | 0 0
  1. import java.awt.*;
  2. import java.applet.*;
  3. import java.awt.event.*;
  4.  
  5. public class rhullfin1 extends Applet implements ItemListener
  6. {
  7.     //Ceate components for applet
  8.     Label CompanyLabel=new Label("Imus Computer College");
  9.     Label paymentLabel=new Label("Please enter the Tuition Fee");
  10.         TextField paymentField=new TextField(20);
  11.     Label optionLabel=new Label("Please choose your Payment Scheme");
  12.  
  13.     CheckboxGroup paymentGroup=new CheckboxGroup();
  14.         Checkbox cashBox=new Checkbox("Cash Payment",false,paymentGroup);
  15.         Checkbox installmentBox=new Checkbox("Installment",false,paymentGroup);
  16.  
  17.         Label outputLabel=new Label("ICC assessment sample              ");
  18.  
  19.         public void init()
  20.         {
  21.             //add Components to window and colors
  22.             setBackground(Color.cyan);
  23.             add(CompanyLabel);
  24.             add(paymentLabel);
  25.             add(paymentField);
  26.                 paymentfield.requestFocus();
  27.             add(optionLabel);
  28.             add(cashBox);
  29.                 cashBox.addItemListener(this);              
  30.             add(installmentBox);
  31.                 installmentBox.addItemListener(this);
  32.             add(outputLabel);
  33.         }
  34.  
  35.         public void itemStateChanged(ItemEvent choice)
  36.         {
  37.             try
  38.             {
  39.                 double payment=0;
  40.                 double price=0;
  41.                 price=Double.parseDouble(paymentField.getText());
  42.  
  43.                 if(price<=) throw new NumberFormatException();
  44.  
  45.                 //check to see selected options
  46.                 if(cashBox.getState())
  47.                 {
  48.                     payment=price;
  49.                     outputLabel.setForeground(Color.black);
  50.                     outputLabel.setText("Your total Tuition Fee is Php"+payment);
  51.                 }
  52.                 else
  53.                 {
  54.                 //if(installmentbox.getState())
  55.                     payment=price*.05+price;
  56.                     outputLabel.setForeground(Color.black);
  57.                     outputLabel.setText("Your total Tuition Fee is Php"+payment);
  58.                
  59.                 }
  60.  
  61.             }
  62.             catch(NumberFormatException e)
  63.             {
  64.                 outputLabel.setText("You must enter a valid Tuition Fee");
  65.                 outputLabel.setForeground(Color.red);
  66.                 paymentField.setText("");
  67.                 paymentField.requestFocus();
  68.             }
  69.         }  
  70. }
  71.  
  72.  
  73.            
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement