Created
December 15, 2019 09:25
-
-
Save AriffAzmi/08de8274d9c4b85bf112e70035fa9e6f to your computer and use it in GitHub Desktop.
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
JFrame frame=new JFrame("TRAIN TICKET"); | |
frame.setSize(800,600); | |
frame.setLayout(null); | |
frame.setVisible(true); | |
//label | |
JLabel l1 = new JLabel("NAME :"); | |
frame.add(l1); | |
l1.setBounds(50,45,100,60); | |
JLabel l2 = new JLabel("CATEGORY :"); | |
l2.setBounds(50,60,150,90);; | |
frame.add(l2); | |
JLabel l3 = new JLabel("DESTINATION :"); | |
frame.add(l3); | |
l3.setBounds(50,70,150,120); | |
//textfield | |
TextField name = new TextField (); | |
frame.add(name); | |
name.setBounds(200,60,200,20); | |
TextField cate= new TextField (); | |
frame.add(cate); | |
cate.setBounds(200,90,200,20); | |
TextField desti= new TextField (); | |
frame.add(desti); | |
desti.setBounds(200,125,200,20); | |
//text | |
JTextArea tout = new JTextArea(); | |
frame.add(tout); | |
tout.setBounds(450,50,300,400); | |
//button | |
JButton no=new JButton("WELCOME TO TRAIN TICKET PADANG BESAR"); | |
no.setBounds(0,0,800,40); //(,,lebar,tinggi) | |
frame.add(no,BorderLayout.NORTH); | |
JButton sub = new JButton("Submit"); | |
frame.add(sub); | |
sub.setBounds(350,500,100,20); | |
sub.addActionListener(new ActionListener() { | |
@Override | |
public void actionPerformed(ActionEvent e) { | |
double price = 0.00; | |
double tax = 0.06; | |
double charge = 0.00; | |
double total = 0.00;; | |
System.out.println(price); | |
//double total; | |
String data1 = new String(name.getText()); | |
String data2 = new String(cate.getText()); | |
String data3 = new String(desti.getText()); | |
// data2,data3; | |
// data1 = ; | |
// data2 = cate.getText(); | |
// data3 = desti.getText(); | |
if (data3.equals("Alor Setar")) { | |
price = 5.00; | |
} | |
else if (data3.equals("Sungai Petani")) { | |
price = 5.00; | |
} | |
else if (data3.equals("Anak Bukit")) { | |
price = 6.00; | |
} | |
else if (data3.equals("Tasek Gelugor")) { | |
price = 11.00; | |
} | |
else if (data3.equals("Gurun")) { | |
price = 9.00; | |
} | |
if (data2.equals("Children")) { | |
charge = 0.00; | |
} | |
else if (data2.equals("Adult")) { | |
charge = 0.00; | |
} | |
else if (data2.equals("Elder")) { | |
charge = 0.15; | |
} | |
double total_tax_price = ( price * tax ); | |
double total_charge_price = (price * charge); | |
total = price + total_charge_price + total_tax_price; | |
System.out.println(price); | |
tout.setText(" Customer Name: "+data1+"\n Destination: "+data3+"\n Ticket Price: RM "+(price + total_charge_price)+"\n SST: RM "+total_tax_price+"\n Total Price: RM "+total); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment