loginConfirmButton Action Listener implemented

gui
David Groys 2024-06-10 17:04:57 +02:00
parent 9bdae273d8
commit 11db856157
1 changed files with 35 additions and 20 deletions

View File

@ -156,22 +156,22 @@ public class Main extends JFrame {
jframe.setVisible(true); jframe.setVisible(true);
} }
private void profileCreate() { private void profileCreate() {
profile = new JPanel(new FlowLayout()); profile = new JPanel(new FlowLayout());
ImageIcon png = png("profile.png", 30, 30); ImageIcon png = png("profile.png", 30, 30);
JLabel jl = new JLabel(png); JLabel jl = new JLabel(png);
String[] details = facade.getUserDetails(); // 6 bzw 7 String[] details = facade.getUserDetails(); // 6 bzw 7
JLabel jlTXT = new JLabel("Name: " + details[0] JLabel jlTXT = new JLabel("Name: " + details[0]
+ "\nWohnort: " + details[1] + "\nWohnort: " + details[1]
+ "\nPlz: " + details[2] + "\nPlz: " + details[2]
+ "\nAuto Name: " + details[3] + "\nAuto Name: " + details[3]
+ "\nAuto km/h: " + details[4] + "\nAuto km/h: " + details[4]
+ "\nCO2/100km: " + details[5] + "\nCO2/100km: " + details[5]
+ "\nFahrrad km/h: " + details[6] + "\nFahrrad km/h: " + details[6]
+ "\nWetter: " + facade.current_weather()); + "\nWetter: " + facade.current_weather());
profile.add(jl); profile.add(jl);
profile.add(jlTXT); profile.add(jlTXT);
} }
private void errorMessageCreate() { private void errorMessageCreate() {
errorMessage = new JPanel(); errorMessage = new JPanel();
@ -189,7 +189,7 @@ public class Main extends JFrame {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
cardLayout.show(panelLayout, "2"); cardLayout.show(panelLayout, "2");
jframe.setSize(new Dimension(400, 150)); jframe.setSize(new Dimension(400, 150));
// implementiere einlesen der textfelder des Panels // implementiere einlesen der textfelder des Panles
} }
}); });
@ -234,9 +234,15 @@ public class Main extends JFrame {
loginConfirmButton.addActionListener(new ActionListener() { loginConfirmButton.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
cardLayout.show(panelLayout, "4"); String nameTXT = getTextfieldContent(loginName, "loginNameText");
jframe.setSize(new Dimension(500, 500)); String passwordTXT = getTextfieldContent(loginPassword, "loginPasswordText");
// implementiere einlesen der textfelder des Panles if(facade.sign_in_user(nameTXT, passwordTXT)) {
cardLayout.show(panelLayout, "4");
jframe.setSize(new Dimension(500, 500));
}
else{
//vllt zukünftig implementiert
}
} }
}); });
} }
@ -431,6 +437,15 @@ public class Main extends JFrame {
}); });
} }
private String getTextfieldContent(JPanel panel, String name) {
for (Component component : panel.getComponents()) {
if (component instanceof JTextField && name.equals(component.getName())) {
return component.getText();
}
}
return null;
}
public ImageIcon png(String path, int sizeX, int sizeY) { // umständlich und png nicht transparent public ImageIcon png(String path, int sizeX, int sizeY) { // umständlich und png nicht transparent
ImageIcon icon = new ImageIcon(getClass().getResource(path)); // Path des PNGs muss angegeben werden ImageIcon icon = new ImageIcon(getClass().getResource(path)); // Path des PNGs muss angegeben werden
Image img = icon.getImage(); Image img = icon.getImage();