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;
- /**
- * Write a description of JavaFX class FortuneTeller here.
- *
- * @author (your name)
- * @version (a version number or a date)
- */
- public class Pembelian extends Application
- {
- Text textKasir = new Text("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 ();
- ObservableList<String> optionsKasir = FXCollections.observableArrayList(
- "Nyno",
- "Fadly",
- "Nadhif",
- "Rey"
- );
- final ComboBox comboBoxKasir = new ComboBox(optionsKasir);
- ObservableList<String> optionsBarang = FXCollections.observableArrayList(
- "PP001",
- "GC001",
- "FG001",
- "GM001"
- );
- final ComboBox comboBoxBarang = new ComboBox(optionsBarang);
- private int TotalHarga;
- private int harga;
- @Override
- public void start(Stage stage) throws Exception
- {
- Scene scene = new Scene(new Group(), 500, 250);
- stage.setTitle("Pembelian");
- //fortune.setFont(Font.font("SanSerif", 18));
- 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("Kasir: "), 0, 0);
- grid.add(comboBoxKasir, 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() == "PP001")
- {
- NamaBarang.setText("Pisang Goreng");
- HargaBarang.setText("Rp5000");
- harga = 5000;
- }
- else if(comboBoxBarang.getValue() == "GC001")
- {
- NamaBarang.setText("Gorengan Cimol");
- HargaBarang.setText("Rp3000");
- harga = 3000;
- }
- else if(comboBoxBarang.getValue() == "FG001")
- {
- NamaBarang.setText("Mainan Figur");
- HargaBarang.setText("Rp100000");
- harga = 100000;
- }
- else if(comboBoxBarang.getValue() == "GM001")
- {
- NamaBarang.setText("Gundam");
- HargaBarang.setText("Rp40000");
- harga = 40000;
- }
- }
- };
- 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: "), 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));
- }
- };
- textFieldJumlah.setOnAction(eventJumlah);
- grid.add(new Label("Total Bayar: "), 0, 5);
- grid.add(TotalHargaText, 1,5);
- Text title=new Text("Hello Fortune Teller");
- title.setFont(Font.font("SanSerif",36));
- 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, textFieldJumlah.getText(), TotalHargaText);
- c.showCetak();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement