Last active
February 22, 2018 12:56
-
-
Save jamesgeorge007/5e2f10f0480477b54dbea67269be9342 to your computer and use it in GitHub Desktop.
This is a very simple GUI application in the swing library written in Java which computes the Net Amount based on the choices received from the user.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javax.swing.*; | |
import java.awt.*; | |
import java.awt.event.*; | |
public class netAmount_Calculator extends JFrame | |
{ | |
private Label billAmount,modeOfPayment,Discount,netAmount; | |
private Button discountButton,netAmountButton,Stop; | |
private TextField billAmount_tf,modeOfPaymnet_tf,Discount_tf,netAmount_tf; | |
private JComboBox cb; | |
String mode_of_payment[]={"Cash","Cheque","Credit Card"}; | |
public netAmount_Calculator() | |
{ | |
super("Glamour Garments"); | |
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | |
setVisible(true); | |
setSize(350,200); | |
setResizable(false); | |
setLayout(new GridBagLayout()); | |
GridBagConstraints c=new GridBagConstraints(); | |
Label billAmount=new Label("Bill Amount"); | |
c.gridx=2; | |
c.gridy=1; | |
add(billAmount,c); | |
TextField billAmount_tf=new TextField(10); | |
c.gridx=3; | |
c.gridy=1; | |
add(billAmount_tf,c); | |
Label modeOfPayment=new Label("Mode of Payment:"); | |
c.gridx=2; | |
c.gridy=2; | |
add(modeOfPayment,c); | |
JComboBox cb=new JComboBox(mode_of_payment); | |
c.gridx=3; | |
c.gridy=2; | |
add(cb,c); | |
Button discountButton=new Button("Calculate Discount"); | |
c.gridx=2; | |
c.gridy=4; | |
add(discountButton,c); | |
Button netAmountButton=new Button("Calculate Net Amount"); | |
c.gridx=3; | |
c.gridy=4; | |
add(netAmountButton,c); | |
Label Discount=new Label("Discount:"); | |
c.gridx=3; | |
c.gridy=5; | |
add(Discount,c); | |
TextField Discount_tf=new TextField(8); | |
Discount_tf.setEditable(false); | |
c.gridx=4; | |
c.gridy=5; | |
add(Discount_tf,c); | |
Label netAmount=new Label("Net Amount:"); | |
c.gridx=3; | |
c.gridy=6; | |
add(netAmount,c); | |
TextField netAmount_tf=new TextField(8); | |
netAmount_tf.setEditable(false); | |
c.gridx=4; | |
c.gridy=6; | |
add(netAmount_tf,c); | |
Button Stop=new Button("STOP"); | |
c.gridx=4; | |
c.gridy=7; | |
add(Stop,c); | |
event e=new event(); | |
discountButton.addActionListener(e); | |
netAmountButton.addActionListener(e); | |
Stop.addActionListener(e); | |
} | |
public class event implements ActionListener | |
{ | |
public void actionPerformed(ActionEvent e) | |
{ | |
String op,s; | |
Double disc=0.0,bm,nm=0.0; | |
op=e.getActionCommand(); | |
bm=Double.parseDouble(billAmount_tf.getText()); | |
if(op.equals("Calculate Discount")) | |
{ | |
s=cb.getSelectedItem().toString(); | |
if(s.equals("Cash")) | |
disc=0.08*bm; | |
else if(s.equals("Cheque")) | |
disc=0.07*bm; | |
else if(s.equals("Credit Card")) | |
disc=0.0; | |
Discount_tf.setText("" + disc); | |
} | |
else if(op.equals("Calculate Net Amount")) | |
{ | |
nm=bm-disc; | |
netAmount_tf.setText("" + nm); | |
} | |
else if(op.equals("STOP")) | |
{ | |
System.exit(0); | |
} | |
} | |
} | |
public static void main(String[]args) | |
{ | |
netAmount_Calculator gui=new netAmount_Calculator(); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment