Skip to content
Snippets Groups Projects
Commit 66179d81 authored by Mikkel Marstein's avatar Mikkel Marstein
Browse files

Update javafx-app/src/javafxapp/application.css,...

Update javafx-app/src/javafxapp/application.css, javafx-app/src/javafxapp/Main.java, javafx-app/src/javafxapp/ValutaKalkulator.java, javafx-app/src/javafxapp/ValutaKalkulator.fxml, javafx-app/src/javafxapp/ValutaKalkulatorController.java files
parent 37c27b36
No related branches found
No related tags found
No related merge requests found
package application;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.stage.Stage;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
public class Main extends Application {
@Override
public void start(Stage primaryStage) {
try {
final Parent parent = FXMLLoader.load(getClass().getResource("ValutaKalkulator.fxml"));
Scene scene = new Scene(parent);
scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
primaryStage.setScene(scene);
primaryStage.show();
} catch(Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
Application.launch(args);
}
}
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.ComboBox?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>
<?import javafx.scene.text.Text?>
<AnchorPane xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.ValutaKalkulatorController">
<children>
<BorderPane prefHeight="325.0" prefWidth="435.0">
<top>
</top>
<left>
<VBox prefHeight="200.0" prefWidth="100.0" BorderPane.alignment="CENTER">
<children>
<VBox prefHeight="200.0" prefWidth="100.0">
<children>
<TextField id="input" fx:id="input" onInputMethodTextChanged="#calcu" onKeyReleased="#calcu" promptText="0" text="0" />
<ComboBox fx:id="comboBox1" onAction="#calcu" prefWidth="150.0" />
</children>
</VBox>
</children>
</VBox>
</left>
<right>
<VBox prefHeight="200.0" prefWidth="100.0" BorderPane.alignment="CENTER">
<children>
<TextField id="output" fx:id="output" disable="true" prefWidth="139.0" promptText="0" />
<ComboBox fx:id="comboBox" onAction="#calcu" prefWidth="150.0" />
</children>
</VBox>
</right>
<top>
<Text strokeType="OUTSIDE" strokeWidth="0.0" text="Valuta Kalkulator" BorderPane.alignment="CENTER">
<font>
<Font size="30.0" />
</font>
</Text>
</top>
<center>
<Text strokeType="OUTSIDE" strokeWidth="0.0" text="--&gt; From To --&gt;" BorderPane.alignment="TOP_CENTER">
<font>
<Font size="26.0" />
</font>
<BorderPane.margin>
<Insets top="20.0" />
</BorderPane.margin>
</Text>
</center>
<bottom>
<Button id="calculate" mnemonicParsing="false" onAction="#calcu" text="Calculate" BorderPane.alignment="CENTER">
<BorderPane.margin>
<Insets bottom="40.0" />
</BorderPane.margin>
</Button>
</bottom>
</BorderPane>
</children>
</AnchorPane>
package application;
import java.util.Hashtable;
public class ValutaKalkulator {
private Hashtable<String, Double> valuta =
new Hashtable<String, Double>();
public void initialize() {
valuta.put("Dollar", 1.0);
valuta.put("Kr", 0.11);
valuta.put("Euro", 0.84);
}
public double calcuate(String kurs1, String kurs2) {
if(valuta.get(kurs2) == null || valuta.get(kurs1)== null) {
return 0.0;
}
return valuta.get(kurs2)/valuta.get(kurs1);
}
}
package application;
import javafx.fxml.FXML;
import javafx.scene.control.ComboBox;
import javafx.scene.control.TextField;
public class ValutaKalkulatorController {
@FXML
private TextField input, output;
@FXML
private ComboBox<String> comboBox, comboBox1;
private final ValutaKalkulator vk = new ValutaKalkulator();
@FXML
public void initialize() {
vk.initialize();
comboBox.getItems().removeAll(comboBox.getItems());
comboBox.getItems().addAll("Kr", "Dollar", "Euro");
comboBox.getSelectionModel().select("Dollar");
comboBox1.getItems().removeAll(comboBox1.getItems());
comboBox1.getItems().addAll("Kr", "Dollar", "Euro");
comboBox1.getSelectionModel().select("Kr");
}
private double getInput() {
if(input.getText().isEmpty())
return 0.0;
return Double.parseDouble(input.getText());
}
@FXML
private void calcu() {
Double kurs = getInput();
kurs = ((double) (Math.round(1000*kurs*vk.calcuate(comboBox.getValue().toString(), comboBox1.getValue().toString())
)))/1000;
this.output.setText(Double.toString(kurs));
}
}
/* JavaFX CSS - Leave this comment until you have at least create one rule which uses -fx-Property */
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment