Skip to content
Snippets Groups Projects
Commit 372b4d3c authored by Jan Schubert's avatar Jan Schubert
Browse files

Merge branch 'master' of https://www.gitrepo.de/alfatrainingkurse/java/enigma

 Conflicts:
	src/main/java/projekt/enigma/App.java
parents c54543a4 08263370
No related branches found
No related tags found
No related merge requests found
...@@ -2,7 +2,6 @@ package projekt.enigma; ...@@ -2,7 +2,6 @@ package projekt.enigma;
import javafx.application.Application; import javafx.application.Application;
import javafx.fxml.FXMLLoader; import javafx.fxml.FXMLLoader;
import javafx.geometry.Insets;
import javafx.scene.Parent; import javafx.scene.Parent;
import javafx.scene.Scene; import javafx.scene.Scene;
import javafx.scene.control.Button; import javafx.scene.control.Button;
...@@ -10,67 +9,99 @@ import javafx.scene.control.Label; ...@@ -10,67 +9,99 @@ import javafx.scene.control.Label;
import javafx.scene.control.TextField; import javafx.scene.control.TextField;
import javafx.scene.layout.VBox; import javafx.scene.layout.VBox;
import javafx.stage.Stage; import javafx.stage.Stage;
import projekt.enigma.model.Codierer; import projekt.enigma.model.Fehler;
import java.io.IOException; import java.io.IOException;
/** /**
* JavaFX App * JavaFX App
* Startklasse fuer JavaFX Application, durch die Erweiterung um die Klasse Application.
* Baut die Benutzeroberflaeche in ihren Grundstrukturen auf.
*/ */
public class App extends Application { public class App extends Application {
private Scene sce1, sce2; private static String kenngruppe;
private static GuiController gc;
private static int debug;
private static Fehler fehler;
Scene sce1, sce2;
private static Parent loadFXML(String fxml) throws IOException {
FXMLLoader fxmlLoader = new FXMLLoader(App.class.getResource(fxml + ".fxml"));
Parent result = fxmlLoader.load();
if (fxml.equals("gui")) {
gc = fxmlLoader.getController();
gc.setKenngruppe(kenngruppe);
}
return result;
}
public static void main(String[] args) {
fehler = new Fehler();
launch(args);
}
public static int getDebug() {
return debug;
}
public static void setDebug(int debug) {
App.debug = debug;
}
public static Fehler getFehler() {
return fehler;
}
@Override @Override
public void start(Stage primaryStage) throws IOException { public void start(Stage primaryStage) throws IOException {
Codierer cod = new Codierer(); primaryStage.setTitle("Kenngruppenabfrage");
//Scene 1
Label label1 = new Label("Bitte Kenngruppe eingeben!");
label1.setTranslateX(55);
Label l1 = new Label("");
Label l2 = new Label("");
TextField tfield = new TextField();
Button button1 = new Button("Kenngruppe setzen!");
Label label1 = new Label("Bitte Kenngruppe eingeben!"); VBox layout1 = new VBox();
TextField tfKenngruppe = new TextField();
Button button1 = new Button("Kenngruppe setzen!");
button1.setTranslateX(10);
VBox layout1 = new VBox(); button1.setOnAction(e -> {
layout1.setSpacing(30); String alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
layout1.setPadding(new Insets(15,15,15,15));
button1.setOnAction(e -> {
String alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
boolean error = false; boolean error = false;
for (char c : tfKenngruppe.getText().toUpperCase().toCharArray()) {
for (char c : tfield.getText().toUpperCase().toCharArray()) {
if (!alphabet.contains(String.valueOf(c))) { if (!alphabet.contains(String.valueOf(c))) {
error = true; error = true;
break; break;
} }
} }
if (tfKenngruppe.getText().length() < 9 && !error) { if (tfield.getText().length() < 9 && !error) {
cod.setKenngruppe(tfKenngruppe.getText().toUpperCase()); kenngruppe = tfield.getText();
primaryStage.setScene(sce2); try {
primaryStage.setScene(new Scene(loadFXML("gui"), 962, 677));
} catch (IOException ex) {
ex.printStackTrace();
}
} else { } else {
tfKenngruppe.setStyle("-fx-background-color:#FF0000"); tfield.setStyle("-fx-background-color:#FF0000");
tfKenngruppe.setText("Fehlerhafte Kenngruppe!"); tfield.setText("Fehlerhafte Kenngruppe!");
} }
});
layout1.getChildren().addAll(label1, tfKenngruppe, button1);
sce1 = new Scene(layout1);
sce2 = new Scene(loadFXML("gui"), 962, 677); });
layout1.getChildren().addAll(label1, l1, tfield, l2, button1);
primaryStage.setScene(sce1); sce1 = new Scene(layout1, 234, 137);
primaryStage.show();
}
private static Parent loadFXML(String fxml) throws IOException { primaryStage.setScene(sce1);
FXMLLoader fxmlLoader = new FXMLLoader(App.class.getResource(fxml + ".fxml")); primaryStage.show();
return fxmlLoader.load(); }
}
public static void main(String[] args) {
launch(args);
}
// /** // /**
// * TODO Dokumentieren // * TODO Dokumentieren
......
This diff is collapsed.
package projekt.enigma;
import java.io.IOException;
import javafx.fxml.FXML;
import javafx.scene.control.TextField;
import projekt.enigma.model.Codierer;
public class KenngruppeController {
private Codierer cod = new Codierer();
@FXML
private TextField tfKenngruppe;
//TODO: Doku
/**
* Beim drücken der Taste wird überprüft ob die eingegebene Kenngruppe weniger als 9 Zeichen hat und ob die
* eingegebenen Zeichen nur Buchstaben sind.
* Bei einer gültigen Eingabe wird die eingegebene Kenngruppe gespeichert und die Enigma-Anwendung gestartet
*
* @throws IOException :
*/
@FXML
private void btnGui() throws IOException {
String alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
boolean error = false;
for (char c : tfKenngruppe.getText().toUpperCase().toCharArray()) {
if (!alphabet.contains(String.valueOf(c))) {
error = true;
}
}
if (tfKenngruppe.getText().length() < 9 && !error) {
cod.setKenngruppe(tfKenngruppe.getText().toUpperCase());
//setzt
// App.setRoot("gui");
} else {
tfKenngruppe.setStyle("-fx-background-color:#FF0000");
tfKenngruppe.setText("Fehlerhafte Kenngruppe!");
}
}
}
...@@ -9,10 +9,6 @@ import java.sql.SQLException; ...@@ -9,10 +9,6 @@ import java.sql.SQLException;
public class Main { public class Main {
public static void main(String[] args) throws SQLException { public static void main(String[] args) throws SQLException {
Thread app = new Thread(new ThreadApp()); App.main(args);
// Thread funk = new Thread(new ThreadFunkraum());
app.start();
// funk.start();
} }
} }
This diff is collapsed.
package projekt.enigma.model;
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
import projekt.enigma.App;
/**
* In dieser Klasse werden Fehler behandelt und an den User/Admin/Entwickler ausgegeben
*/
public class Fehler {
private String functionPrefix = "- ";
private String messagePrefix = "--> ";
/**
* Zeige Fehler Dialog
*
* @param type : String : Art der Meldung (warning/information/error)
* @param subject : Titel des Dialoges
* @param message : Nachricht der Meldung
*/
public void showErrorDialog(String type, String subject, String message) {
new Fehler().debug(this.getClass().getName() + "." + new Throwable().getStackTrace()[0].getMethodName(), true);
Alert alert;
/* Der Titel darf auch als leerer String übergeben werden, dann wird ein Default gesetzt */
if (subject.equals("")) {
subject = "Es ist ein Fehler aufgetreten";
}
/* Welcher Fehler Typ wurde übergeben? */
switch (type) {
case "warning":
alert = new Alert(AlertType.WARNING);
break;
case "information":
alert = new Alert(AlertType.INFORMATION);
break;
case "error":
alert = new Alert(AlertType.ERROR);
break;
default:
alert = new Alert(AlertType.NONE);
}
/* Setzt den Titel des Dialoges */
alert.setTitle(subject);
/* Setzt den Headertext des Dialoges */
alert.setHeaderText(null);
/* Setzt die Nachricht des Dialoges */
alert.setContentText(message);
/* Zeige den Dialog an */
alert.showAndWait();
}
public void debug(String message, boolean isFunction) {
if (App.getDebug() != 0) {
if (isFunction) {
System.out.println(functionPrefix + message);
} else {
System.out.println(messagePrefix + message);
}
}
}
public void debug(String message, boolean isFunction, int debugLevel) {
if (App.getDebug() != 0 && (App.getDebug() >= debugLevel || App.getDebug() == 3) ) {
if (isFunction) {
System.out.println(functionPrefix + message);
} else {
System.out.println(messagePrefix + message);
}
}
}
}
\ No newline at end of file
...@@ -10,6 +10,7 @@ import org.apache.http.client.methods.HttpPost; ...@@ -10,6 +10,7 @@ import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.HttpClients; import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair; import org.apache.http.message.BasicNameValuePair;
import org.json.JSONObject; import org.json.JSONObject;
import projekt.enigma.App;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
...@@ -63,10 +64,11 @@ public class Funkraum { ...@@ -63,10 +64,11 @@ public class Funkraum {
} }
} }
} catch (UnsupportedEncodingException e) { } catch (UnsupportedEncodingException e) {
System.out.println("Encoding wird nicht unterstützt."); App.getFehler().showErrorDialog("error", "Fehler", "Encoding wird nicht unterstützt.");
} catch (IOException e) { } catch (IOException e) {
System.out.println("HTTP Post war nicht erfolgreich.\nBitte wenden Sie sich an ihren Vorgesetzten."); App.getFehler().showErrorDialog("error", "HTTP Post war nicht erfolgreich", "Bitte wenden Sie sich an ihren Vorgesetzten.");
e.printStackTrace(); } catch (NullPointerException e) {
App.getFehler().showErrorDialog("error", "Fehler", "Keine Nachrichten für diese Kenngruppe");
} }
return funkspruch; return funkspruch;
...@@ -107,7 +109,7 @@ public class Funkraum { ...@@ -107,7 +109,7 @@ public class Funkraum {
JSONObject result = new JSONObject(reader.readLine()); JSONObject result = new JSONObject(reader.readLine());
if (result.getInt("result") != 200) { if (result.getInt("result") != 200) {
throw new HttpException("Der andere Funker mag deine Nachricht nicht. " + throw new HttpException("Der andere Funker mag deine Nachricht nicht. " +
"Rüge ihn wenn du ihn wieder siehst..."); "Rüge ihn wenn du ihn wieder siehst...");
} }
} }
} }
......
...@@ -2,14 +2,18 @@ package projekt.enigma.threads; ...@@ -2,14 +2,18 @@ package projekt.enigma.threads;
import projekt.enigma.App; import projekt.enigma.App;
import java.sql.SQLException; /**
* Thread fuer die Benutzeroberflaeche, wird durch das Interface Runnable erweitert
*/
public class ThreadApp implements Runnable { public class ThreadApp implements Runnable {
private String[] args; private String[] args;
/**
* Ueberschriebene Funktion - fuehrt die Klasse App aus
*/
@Override @Override
public void run() { public void run() {
System.out.println("ThreadApp" + Thread.currentThread()); System.out.println("ThreadApp " + Thread.currentThread());
App app = new App(); App app = new App();
app.main(args); app.main(args);
......
package projekt.enigma.threads; package projekt.enigma.threads;
import org.apache.http.HttpException;
import projekt.enigma.model.Codierer; import projekt.enigma.model.Codierer;
import projekt.enigma.model.Funkraum; import projekt.enigma.model.Funkraum;
import java.io.IOException; /**
* Thread fuer den Funkraum, wird durch das Interface Runnable erweitert
*/
public class ThreadFunkraum implements Runnable { public class ThreadFunkraum implements Runnable {
String kenngruppe = new Codierer().getKenngruppe(); String kenngruppe;
// String funkspruch;
public ThreadFunkraum(String kenngruppe) {
this.kenngruppe = kenngruppe;
}
/**
* Ueberschriebene Funktion - fuehrt die Klasse Funkraum aus und startet
*/
@Override @Override
public void run() { public void run() {
Funkraum funkraum = new Funkraum(); Funkraum funkraum = new Funkraum();
System.out.println("Threadfunkraum" + Thread.currentThread()); System.out.println("Threadfunkraum" + Thread.currentThread());
funkraum.empfangeFunkspruch(kenngruppe); funkraum.empfangeFunkspruch(this.kenngruppe);
// try {
// funkraum.sendeFunkspruch(funkspruch, kenngruppe);
// } catch (HttpException he) {
// System.err.println("Error");
// } catch (IOException io) {
// System.err.println("Error");
// }
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment