Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javafx.application.Application;
- import javafx.application.Platform;
- import javafx.event.ActionEvent;
- import javafx.event.EventHandler;
- import javafx.geometry.Insets;
- import javafx.geometry.Pos;
- import javafx.scene.Scene;
- import javafx.scene.control.*;
- import javafx.scene.layout.*;
- import javafx.scene.text.Font;
- import javafx.scene.text.Text;
- import javafx.stage.Stage;
- import javafx.scene.layout.StackPane;
- import javafx.collections.*;
- import javafx.scene.paint.*;
- import javafx.scene.text.*;
- import javafx.scene.Group;
- import java.util.Random;
- public class Detaildata extends Application
- {
- Text textKasir = new Text("Petugas Kasir :");
- Text KodeBarang = new Text("");
- Text textHarga = new Text("");
- Text textJumlah = new Text("");
- Text textTotalBayar = new Text("");
- Text NamaBarang = new Text("");
- Text HargaBarang = new Text("");
- Text TotalHargaText = new Text("");
- TextField textFieldJumlah = new TextField ();
- TextField textFieldKasir = new TextField ();
- Text JumlahText = new Text("");
- ObservableList<String> optionBarang = FXCollections.observableArrayList( "A001", "B002", "C003");
- final ComboBox comboBoxBarang = new ComboBox(optionBarang);
- private int TotalHarga;
- private int Harga;
- private int Jumlah;
- @Override
- public void start(Stage stage) throws Exception
- {
- Scene scene = new Scene(new Group(), 500, 250);
- stage.setTitle("Detail Pembelian");
- textKasir.setFont(Font.font("SanSerif",18));
- KodeBarang.setFont(Font.font("SanSerif", 18));
- textHarga.setFont(Font.font("SanSerif", 18));
- textJumlah.setFont(Font.font("SanSerif", 18));
- textTotalBayar.setFont(Font.font("SanSerif",18));
- GridPane grid = new GridPane();
- grid.setVgap(10);
- grid.setHgap(10);
- grid.setPadding(new Insets(10, 10, 10, 10));
- grid.add(new Label("Petugas Kasir : "), 0, 0);
- grid.add(textFieldKasir, 1, 0);
- grid.add(new Label("Kode Barang : " ), 0, 1);
- grid.add(comboBoxBarang, 1, 1);
- EventHandler<ActionEvent> event = new EventHandler<ActionEvent>()
- {
- public void handle(ActionEvent e)
- {
- if(comboBoxBarang.getValue() == "A001")
- {
- NamaBarang.setText("Sticker");
- HargaBarang.setText("Rp5000");
- Harga = 5000;
- }
- else if(comboBoxBarang.getValue() == "B002")
- {
- NamaBarang.setText("Enamel Pin");
- HargaBarang.setText("Rp25000");
- Harga = 25000;
- }
- else if(comboBoxBarang.getValue() == "C003")
- {
- NamaBarang.setText("Patch");
- HargaBarang.setText("Rp20000");
- Harga = 20000;
- }
- }
- };
- comboBoxBarang.setOnAction(event);
- grid.add(new Label("Nama Barang : "), 0, 2);
- grid.add(NamaBarang, 1, 2);
- grid.add(new Label("Harga : "), 0, 3);
- grid.add(HargaBarang,1, 3);
- grid.add(new Label("Jumlah Barang : "), 0, 4);
- grid.add(textFieldJumlah, 1, 4);
- EventHandler<ActionEvent> eventJumlah = new EventHandler<ActionEvent>()
- {
- public void handle(ActionEvent e)
- {
- TotalHarga = Integer.parseInt(textFieldJumlah.getText()) * Harga;
- TotalHargaText.setText("Rp " + Integer.toString(TotalHarga));
- Jumlah = Integer.parseInt(textFieldJumlah.getText());
- JumlahText.setText(Integer.toString(Jumlah));
- }
- };
- textFieldJumlah.setOnAction(eventJumlah);
- grid.add(new Label("Total Harga : "), 0, 5);
- grid.add(TotalHargaText, 1, 5);
- grid.add(new Label("Total Bayar : "), 0, 6);
- grid.add(TotalHargaText, 1, 6);
- Button button = new Button("Cetak");
- grid.add(button, 1, 6);
- button.setOnAction(this::buttonClick);
- Group root = (Group)scene.getRoot();
- root.getChildren().add(grid);
- stage.setScene(scene);
- stage.show();
- }
- private void buttonClick(ActionEvent event)
- {
- Cetak c = new Cetak(NamaBarang, JumlahText, TotalHargaText);
- c.showCetak();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement