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

Nye endringer

parent 37c27b36
No related branches found
No related tags found
No related merge requests found
......@@ -3,7 +3,7 @@ image:
tasks:
- init: sdk use java 14.0.2.j9-adpt
command: cd javafx-app
command: cd Valutakalkulator
ports:
# used by virtual desktop and vnc, supports JavaFX
......
......@@ -3,7 +3,7 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>it1901</groupId>
<artifactId>javafx-app</artifactId>
<artifactId>Valutakalkulator</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
......@@ -97,7 +97,7 @@
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.4</version>
<configuration>
<mainClass>javafxapp.App</mainClass>
<mainClass>Valutakalkulator.App</mainClass>
</configuration>
</plugin>
</plugins>
......
<?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="Valutakalkulator.AppController">
<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 Valutakalkulator;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class App extends Application {
@Override
public void start(Stage primaryStage) {
try {
final Parent parent = FXMLLoader.load(getClass().getResource("App.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);
}
}
package Valutakalkulator;
import javafx.fxml.FXML;
import javafx.scene.control.ComboBox;
import javafx.scene.control.TextField;
public class AppController {
@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));
}
}
package Valutakalkulator;
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);
}
}
module javafxapp {
module Valutakalkulatorpp {
requires javafx.fxml;
requires transitive javafx.graphics;
requires javafx.controls;
exports javafxapp;
exports Valutakalkulator;
opens javafxapp to javafx.fxml;
opens Valutakalkulator to javafx.fxml;
}
\ No newline at end of file
package javafxapp;
package Valutakalkulator;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
......
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.layout.Pane?>
<?import javafx.scene.control.Button?>
<Pane xmlns:fx="http://javafx.com/fxml/1" fx:controller="javafxapp.AppController">
<Button fx:id="clickMeButton" text="Click me!" onAction="#handleClickMeButtonAction"/>
</Pane>
package javafxapp;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class App extends Application {
@Override
public void start(final Stage primaryStage) throws Exception {
final Parent parent = FXMLLoader.load(getClass().getResource("App.fxml"));
primaryStage.setScene(new Scene(parent));
primaryStage.show();
}
public static void main(final String[] args) {
launch(args);
}
}
package javafxapp;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
public class AppController {
@FXML
Button clickMeButton;
@FXML
void handleClickMeButtonAction() {
clickMeButton.setText("Thanks!");
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment