Sunteți pe pagina 1din 3

/*

* To change this license header, choose License Headers in Project Properties.


* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package menumakanan;

import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.Background;
import javafx.scene.layout.BackgroundFill;
import javafx.scene.layout.CornerRadii;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
import javafx.stage.Stage;

/**
*
* @author User
*/
public class MenuMakanan extends Application {
//inisiasi variable
double totalHarga=0, hargaSoto=0, hargaGudeg = 0;

@Override
public void start(Stage primaryStage) {
// judul aplikasi
primaryStage.setTitle("Menu Makanan"); // nama title terserah

//MENAMPILKAN CHECKBOX
CheckBox cbSoto = new CheckBox("Soto");
CheckBox cbGudeg = new CheckBox("Gudeg");

//menampilkan textfield
TextField tfSoto = new TextField("0");
TextField tfGudeg = new TextField("0");

//memberiwarna pada background (pada textfield)


tfSoto.setBackground(new Background(new
BackgroundFill(Color.rgb(224,255,255), CornerRadii.EMPTY,Insets.EMPTY)));
tfGudeg.setBackground(new Background(new
BackgroundFill(Color.rgb(135,206,250), CornerRadii.EMPTY,Insets.EMPTY)));

//menampilkan button
Button btnHitung = new Button ("Hitung");
Button btnHapus = new Button ("Hapus");
Label lblHarga = new Label();
HBox box = new HBox(btnHitung, btnHapus);
box.setSpacing(5);

btnHitung.setBackground(new Background(new
BackgroundFill(Color.rgb(135,206,250), CornerRadii.EMPTY,Insets.EMPTY)));
btnHapus.setBackground(new Background(new
BackgroundFill(Color.rgb(135,206,250), CornerRadii.EMPTY,Insets.EMPTY)));

// layout
GridPane root = new GridPane();
root.add(cbSoto,0,0);
root.add(cbGudeg,0,1);
root.add(tfSoto,1,0);
root.add(tfGudeg,1,1);
root.setVgap(10); // untuk memberi jarak
root.setHgap(10);
//root.setPadding(new Insets(5));

root.add(box,1,2);
root.add(lblHarga, 1, 3);

//WARNA BACKGROUND PADA HALAMAN UTAMA


root.setBackground(new Background(new
BackgroundFill(Color.rgb(135,206,250), CornerRadii.EMPTY,Insets.EMPTY)));

// MENAMPILKAN APLIKASI
Scene scene = new Scene(root);// atau
//Scene scene = new Scene (root, 300,400);
primaryStage.setScene(scene);
primaryStage.show();

cbSoto.setOnAction(e->{
if (cbSoto.isSelected()){
hargaSoto=10000;
tfSoto.setDisable(false);
}
else {
//uncheck
hargaSoto=0;
tfSoto.setDisable(true);

}
});
btnHitung.setOnAction(e->{
if (tfSoto.getText().isEmpty()
|| tfGudeg.getText().isEmpty()){
tfSoto.setText("0");
tfGudeg.setText("0");

totalHarga = hargaSoto *
Double.valueOf(tfSoto.getText())
+hargaGudeg*
Double.valueOf(tfGudeg.getText());
}
else {
totalHarga = hargaSoto*
Double.valueOf(tfSoto.getText())
+hargaGudeg *
Double.valueOf(tfGudeg.getText());
// format RP
DecimalFormat kursIndo = (DecimalFormat)
DecimalFormat.getCurrencyInstance();
DecimalFormatSymbols formatRp= new DecimalFormatSymbols();

formatRp.setCurrencySymbol ("Rp.");
formatRp.setMonetaryDecimalSeparator(',');

formatRp.setGroupingSeparator(',');
kursIndo.setDecimalFormatSymbols (formatRp);

String string = kursIndo.format(totalHarga);


lblHarga.setText(string);
}
});
}

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}

S-ar putea să vă placă și