Rabu, 27 November 2019

KUIS

Membuat aplikasi POS sederhana
Input:
-Petugas Kair
-Kode Barang
-Nama Barang
-Harga
-Jumlah Pembelian

Output:
-Total Bayar
-Bukti

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
 
public class POS {
    JFrame frameList = null;
    JPanel panel = null;
 
    JTextField txtKodeKasir = null;
    JTextField txtKodeBarang = null;
    JTextField txtNamaBarang = null;
    JTextField txtHarga = null;
    JTextField txtJumlahBarang = null;
 
    JFrame framePrint = null;
    JPanel panelList = null;
   
    public static void main(String[] args){
        POS gui = new POS();
        gui.list();
    }
 
    public void list(){
        frameList = new JFrame();
        frameList.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        panel = new JPanel();
 
        JLabel lblKodeKasir = new JLabel("Kode Kasir:");  
        txtKodeKasir = new JTextField(20);
 
        JLabel lblKodeBarang = new JLabel("Kode Barang:");
        txtKodeBarang = new JTextField(20);
 
        JLabel lblNamaBarang = new JLabel("Nama Barang:");
        txtNamaBarang = new JTextField(20);
 
        JLabel lblHarga = new JLabel("Harga:");
        txtHarga = new JTextField(20);
       
        JLabel lblJumlahPembelian = new JLabel("Jumlah Barang:");
        txtJumlahBarang = new JTextField(20);
       
        JButton btnSubmit = new JButton("Print");
        btnSubmit.addActionListener(new SubmitListener(this));
       
        panel.add(lblKodeKasir);
        panel.add(txtKodeKasir);
        panel.add(lblKodeBarang);
        panel.add(txtKodeBarang);
        panel.add(lblNamaBarang);
        panel.add(txtNamaBarang);
        panel.add(lblHarga);
        panel.add(txtHarga);
        panel.add(lblJumlahPembelian);
        panel.add(txtJumlahBarang);
       
        panel.add(btnSubmit);        
        frameList.getContentPane().add(BorderLayout.CENTER,panel);
 
        frameList.setSize(250,500);
        frameList.setVisible(true);
    }
   
    public void sendMessage(String msg) {
        JOptionPane.showMessageDialog(null,msg);
    }
   
    public void printBarang(POS pos) {
        String petugasKasir = pos.txtKodeKasir.getText();
        String kodeBarang = pos.txtKodeBarang.getText();
        String namaBarang = pos.txtNamaBarang.getText();
        String harga = pos.txtHarga.getText();
        String jumlahPembelian = pos.txtJumlahBarang.getText();
        int totalHarga = Integer.parseInt(harga) * Integer.parseInt(jumlahPembelian);
 
        pos.framePrint = new JFrame();
        pos.framePrint.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        pos.panelList = new JPanel();
       
        JLabel lblKodeKasir = new JLabel("Kode Kasir: " + pos.txtKodeKasir.getText()+"\n");  
        JLabel lblKodeBarang = new JLabel("Kode Barang: " + pos.txtKodeBarang.getText());
        JLabel lblNamaBarang = new JLabel("Nama Barang: " + pos.txtNamaBarang.getText());
        JLabel lblHarga = new JLabel("Harga: Rp. " + pos.txtHarga.getText());
        JLabel lblJumlahPembelian = new JLabel("Jumlah Barang: " + pos.txtJumlahBarang.getText());
        JLabel lblTotalBayar = new JLabel("Total Bayar: Rp. " + (Integer.parseInt(harga) * Integer.parseInt(jumlahPembelian)));
 
        pos.panelList.add(lblKodeKasir);
        pos.panelList.add(lblKodeBarang);
        pos.panelList.add(lblNamaBarang);
        pos.panelList.add(lblHarga);
        pos.panelList.add(lblJumlahPembelian);
        pos.panelList.add(lblTotalBayar);
 
        pos.framePrint.getContentPane().add(BorderLayout.CENTER, pos.panelList);
 
        pos.framePrint.setSize(210,500);
 
        pos.frameList.setVisible(false);
        pos.framePrint.setVisible(true);
 
    }
   
    public class SubmitListener implements ActionListener{
        POS pos;
       
        public SubmitListener(POS pos) {
            this.pos = pos;
        }
       
        public void actionPerformed(ActionEvent event){
            pos.printBarang(pos);
        }
 
    }
 
}
output:

 
 

Tidak ada komentar:

Posting Komentar