ݺߣ

ݺߣShare a Scribd company logo
importjavax.swing.*;
importjava.awt.*;
importjava.awt.event.*;
public class uas extends JFrame implements ActionListener
{

JLabelnama,kota,kode,harga,pesan,total;
JTextFieldtxtnama,txtkode,txtharga,txtpesan,txttotal;
JComboBoxcbokota;
JPanel panel= new JPanel();
JButtonhitung,keluar;

publicuas()
{

setTitle("UaS");
setSize(350,400);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

nama = new JLabel("NamaPemesan");
txtnama = new JTextField();

kota = new JLabel("Kota Tujuan");
cbokota = new JComboBox(new String[]{"","Jakarta","Bandung","Semarang"});

kode = new JLabel("KodeKendaraan");
txtkode = new JTextField();

harga = new JLabel("Harga");
txtharga = new JTextField();

pesan = new JLabel("JmlPesan");
txtpesan = new JTextField();

total = new JLabel("Total");
txttotal = new JTextField();

hitung = new JButton("Hitung");
hitung.addActionListener(this);

keluar = new JButton("Keluar");
keluar.addActionListener(this);

nama.setBounds(30,30,100,25);
txtnama.setBounds(130,30,100,25);

kota.setBounds(30,60,100,25);
cbokota.setBounds(130,60,100,25);

kode.setBounds(30,90,100,25);
txtkode.setBounds(130,90,100,25);

harga.setBounds(30,120,100,25);
txtharga.setBounds(130,120,100,25);

pesan.setBounds(30,150,100,25);
txtpesan.setBounds(130,150,100,25);

total.setBounds(30,180,100,25);
txttotal.setBounds(130,180,100,25);

hitung.setBounds(75,210,90,25);
keluar.setBounds(190,210,90,25);
panel.add(nama);
panel.add(txtnama);
panel.add(kota);
panel.add(cbokota);
panel.add(kode);
panel.add(txtkode);
panel.add(harga);
panel.add(txtharga);
panel.add(pesan);
panel.add(txtpesan);
panel.add(total);
panel.add(txttotal);
panel.add(hitung);
panel.add(keluar);
add(panel);
panel.setLayout(null);
setVisible(true); }
public static void main(String[] args)
{

newuas();

}

public void actionPerformed(ActionEvent e)
{

String d2 = txtharga.getText();
String d3 = txtpesan.getText();
doubleharga = Integer.parseInt(d2);
doublepesan = Integer.parseInt(d3);

inthasil = (int)(harga*pesan);
Object objek = e.getSource();
if(objek==hitung)
txttotal.setText(new String().valueOf(hasil));
{

if (objek==keluar)
System.exit(0);

}}}

More Related Content

Form Pemesanan Tiket dengan Java NetBeans

  • 1. importjavax.swing.*; importjava.awt.*; importjava.awt.event.*; public class uas extends JFrame implements ActionListener { JLabelnama,kota,kode,harga,pesan,total; JTextFieldtxtnama,txtkode,txtharga,txtpesan,txttotal; JComboBoxcbokota; JPanel panel= new JPanel(); JButtonhitung,keluar; publicuas() { setTitle("UaS"); setSize(350,400); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); nama = new JLabel("NamaPemesan"); txtnama = new JTextField(); kota = new JLabel("Kota Tujuan"); cbokota = new JComboBox(new String[]{"","Jakarta","Bandung","Semarang"}); kode = new JLabel("KodeKendaraan"); txtkode = new JTextField(); harga = new JLabel("Harga"); txtharga = new JTextField(); pesan = new JLabel("JmlPesan"); txtpesan = new JTextField(); total = new JLabel("Total");
  • 2. txttotal = new JTextField(); hitung = new JButton("Hitung"); hitung.addActionListener(this); keluar = new JButton("Keluar"); keluar.addActionListener(this); nama.setBounds(30,30,100,25); txtnama.setBounds(130,30,100,25); kota.setBounds(30,60,100,25); cbokota.setBounds(130,60,100,25); kode.setBounds(30,90,100,25); txtkode.setBounds(130,90,100,25); harga.setBounds(30,120,100,25); txtharga.setBounds(130,120,100,25); pesan.setBounds(30,150,100,25); txtpesan.setBounds(130,150,100,25); total.setBounds(30,180,100,25); txttotal.setBounds(130,180,100,25); hitung.setBounds(75,210,90,25); keluar.setBounds(190,210,90,25); panel.add(nama);
  • 3. panel.add(txtnama); panel.add(kota); panel.add(cbokota); panel.add(kode); panel.add(txtkode); panel.add(harga); panel.add(txtharga); panel.add(pesan); panel.add(txtpesan); panel.add(total); panel.add(txttotal); panel.add(hitung); panel.add(keluar); add(panel); panel.setLayout(null); setVisible(true); } public static void main(String[] args) { newuas(); } public void actionPerformed(ActionEvent e) { String d2 = txtharga.getText(); String d3 = txtpesan.getText(); doubleharga = Integer.parseInt(d2); doublepesan = Integer.parseInt(d3); inthasil = (int)(harga*pesan); Object objek = e.getSource(); if(objek==hitung) txttotal.setText(new String().valueOf(hasil)); { if (objek==keluar) System.exit(0); }}}