Added Register Features

This commit is contained in:
shaggy3007 2023-10-17 00:05:17 +02:00
parent b95287d193
commit 73ee8d093a
5 changed files with 60 additions and 13 deletions

View File

@ -1,9 +1,12 @@
package ClientApp;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javafx.scene.Scene;
import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane;
import javafx.scene.text.Text;
@ -11,16 +14,19 @@ public abstract class AbstractAppPane implements AppPane {
protected GridPane pannello = new GridPane();
protected Map<String,Text> Texts = new HashMap<>();
protected Map<Text,TextField> Fields = new HashMap<>();
protected Scene scena = new Scene(pannello);
protected int heigth, width, insets;
protected List<String> Names = new ArrayList<>();
@Override
abstract public void gridSetup();
@Override
public void textFill(Iterable<String> A) {
for (String s : A) {
public void textFill() {
for (String s : Names) {
Texts.put(s, new Text(s));
Fields.put(Texts.get(s), new TextField());
}
}

View File

@ -4,6 +4,6 @@ import javafx.scene.Scene;
public interface AppPane {
public void gridSetup();
public void textFill(Iterable<String> A);
public void textFill();
public Scene getScene();
}

View File

@ -2,13 +2,16 @@ package ClientApp;
import java.util.ArrayList;
import java.util.List;
import java.util.HashMap;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.control.Button;
public class RegPane extends AbstractAppPane {
@Override
private HashMap<String,String> ClientInfo = new HashMap<>();
public void gridSetup() {
pannello.setMinHeight(width);
pannello.setMinWidth(heigth);
@ -16,17 +19,35 @@ public class RegPane extends AbstractAppPane {
pannello.setVgap(5);
pannello.setHgap(5);
pannello.setAlignment(Pos.CENTER);
int x = 0;
for (String s : Names) {
pannello.add(Texts.get(s),0,x);
pannello.add(Fields.get(Texts.get(s)), 1, x++);
}
Button RegButton = new Button("Register");
RegButton.setOnAction(e->{
for(String name : UserDataTypes.Names()) {
String out = "";
ClientInfo.put(name,Fields.get(Texts.get(name)).getText());
Fields.get(Texts.get(name)).clear();
out += ClientInfo.get(name);
System.out.println(out);
}
});
pannello.add(RegButton, x++, x);
}
public RegPane (int insets, int width, int heigth, String ... S) {
public RegPane (int insets, int width, int heigth, ArrayList<String> S) {
this.width = width;
this.heigth = heigth;
this.insets = insets;
List<String> L = new ArrayList<>();
for (String s: S) {
L.add(s);
Names.add(s);
}
textFill(L);
textFill();
gridSetup();
}
}

View File

@ -1,8 +1,10 @@
package ClientApp;
import java.util.ArrayList;
import javafx.application.Application;
import javafx.stage.Stage;
import java.util.function.*;
public class TestMain extends Application{
public static void main(String args[]) {
@ -11,9 +13,10 @@ public class TestMain extends Application{
@Override
public void start(Stage stage) throws Exception {
AppPane Register = new RegPane(10, 500, 500, "ciao", "bello");
AppPane Register = new RegPane(10, 500, 500,UserDataTypes.Names());
stage.setScene(Register.getScene());
stage.show();
}
}
}

View File

@ -0,0 +1,17 @@
package ClientApp;
import java.util.ArrayList;
public enum UserDataTypes {
GAY,
NERO,
FROCIO,
GRASSO;
public static ArrayList<String> Names() {
ArrayList<String> names = new ArrayList<>();
for (var N: UserDataTypes.values()) {
names.add(N.toString());
}
return names;
}
}