diff --git a/src/main/java/de/hs_mannheim/ui/Main.java b/src/main/java/de/hs_mannheim/ui/Main.java index ee4a4f8..faa69ad 100644 --- a/src/main/java/de/hs_mannheim/ui/Main.java +++ b/src/main/java/de/hs_mannheim/ui/Main.java @@ -6,11 +6,14 @@ import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import javax.swing.BorderFactory; +import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextField; +import javax.swing.SwingConstants; public class Main extends JFrame { public static void main(String[] args) { @@ -24,18 +27,20 @@ public class Main extends JFrame { //Wird in mehreren Labels benutzt (reg und log) private JPanel errorMessage; // mal gucken, vllt auch nicht - private JPanel profile; //wird nach registrieren oder login kreiert + private JLabel mainMenuLabel; private JPanel logRegScreen; private JButton loginButton; private JButton registerButton; + private JLabel loginLabel; private JPanel loginScreen; private JPanel loginName; private JPanel loginPassword; private JButton loginConfirmButton; private JButton loginZurückButton; + private JLabel registerLabel; private JPanel registerScreen; // Backend muss PLZ und Ort prüfen, sonst kann die Entfernung in Zukunft nicht berechnet werden private JPanel registerName; private JPanel registerPassword; @@ -48,12 +53,13 @@ public class Main extends JFrame { private JButton registerConfirmButton; private JButton registerZurückButton; + private JLabel menuLabel; private JPanel menu; - private JPanel searchPLZ; - private JPanel searchOrt; + private JPanel searchPLZ_ORT; private JButton searchConfirmButton; private JButton randDestinationsCarButton; private JButton randDestinationsBikeButton; + private JPanel profile; private JButton logOutButton; public Main(String api_key) { @@ -71,23 +77,30 @@ public class Main extends JFrame { errorMessageCreate();//wahrscheinlich muss individuell angepasst werden logRegScreen = new JPanel(new FlowLayout()); + mainMenuLabel = new JLabel(" Hauptmenü "); + mainMenuLabel.setFont(new Font("Arial", Font.PLAIN, 24)); loginButtonCreate(); registerButtonCreate(); + logRegScreen.add(mainMenuLabel); logRegScreen.add(loginButton, BorderLayout.WEST); logRegScreen.add(registerButton, BorderLayout.EAST); loginScreen = new JPanel(new FlowLayout()); + loginLabel = new JLabel(" Einloggen "); + loginLabel.setFont(new Font("Arial", Font.PLAIN, 24)); loginNameCreate(); loginPasswordCreate(); loginConfirmButtonCreate(); loginZurückButtonCreate(); + loginScreen.add(loginLabel); loginScreen.add(loginName); loginScreen.add(loginPassword); loginScreen.add(loginConfirmButton); loginScreen.add(loginZurückButton); - loginScreen.add(loginZurückButton); registerScreen = new JPanel(new FlowLayout()); // flowLayout muss angepasst werden, um nicht scheiße auszusehen + registerLabel = new JLabel("Registrieren"); + registerLabel.setFont(new Font("Arial", Font.PLAIN, 24)); registerNameCreate(); registerPasswordCreate(); registerOrtCreate(); @@ -98,31 +111,34 @@ public class Main extends JFrame { registerBikeSpeedCreate(); registerConfirmButtonCreate(); registerZurückButtonCreate(); + registerScreen.add(registerLabel); registerScreen.add(registerName); registerScreen.add(registerPassword); registerScreen.add(registerOrt); registerScreen.add(registerPLZ); + registerScreen.add(registerCarName); registerScreen.add(registerCarSpeed); + registerScreen.add(registerCarCO2); registerScreen.add(registerBikeSpeed); registerScreen.add(registerConfirmButton); registerScreen.add(registerZurückButton); - registerScreen.add(registerZurückButton); menu = new JPanel(null); - searchPLZCreate(); - searchOrtCreate(); + menuLabel = new JLabel("Gugl Maps"); + menuLabel.setFont(new Font("Arial", Font.PLAIN, 24)); + searchPLZ_ORTCreate(); searchConfirmButtonCreate(); randDestinationsCarButtonCreate(); randDestinationsBikeButtonCreate(); logOutButtonCreate(); - searchPLZ.setBounds(160, 0, 200, 200); - searchOrt.setBounds(0, 0, 200, 200); - searchConfirmButton.setBounds(360, 5, 90, 20); - randDestinationsCarButton.setBounds(360, 40, 90, 20); - randDestinationsBikeButton.setBounds(360, 75, 90, 20); - logOutButton.setBounds(380, 420, 90, 30); - menu.add(searchPLZ); - menu.add(searchOrt); + menuLabel.setBounds(180, -125, 300, 300); + searchPLZ_ORT.setBounds(20, 50, 300, 100); + searchConfirmButton.setBounds(346, 70, 110, 30); + randDestinationsCarButton.setBounds(346, 115, 110, 30); + randDestinationsBikeButton.setBounds(346, 160, 110, 30); + logOutButton.setBounds(346, 420, 110, 30); + menu.add(menuLabel); + menu.add(searchPLZ_ORT); menu.add(searchConfirmButton); menu.add(randDestinationsCarButton); menu.add(randDestinationsBikeButton); @@ -135,18 +151,11 @@ public class Main extends JFrame { cardLayout.show(panelLayout, "1"); jframe.add(panelLayout); jframe.setResizable(false); - jframe.setSize(450, 140); + jframe.setSize(450, 160); jframe.setLocationRelativeTo(null); jframe.setVisible(true); } - private void profileCreate() { - profile = new JPanel(); - JLabel jl = new JLabel("Profil"); - searchOrt.add(jl); - //Backend soll DatenLiefern - } - private void errorMessageCreate() { errorMessage = new JPanel(); JLabel jl = new JLabel("Daten sind falsch oder unvollständig!"); @@ -162,7 +171,7 @@ public class Main extends JFrame { @Override public void actionPerformed(ActionEvent e) { cardLayout.show(panelLayout, "2"); - jframe.setSize(new Dimension(500, 180)); + jframe.setSize(new Dimension(400, 150)); // implementiere einlesen der textfelder des Panels } }); @@ -177,7 +186,7 @@ public class Main extends JFrame { @Override public void actionPerformed(ActionEvent e) { cardLayout.show(panelLayout, "3"); - jframe.setSize(new Dimension(520, 180)); + jframe.setSize(new Dimension(260, 390)); // implementiere einlesen der textfelder des Panles } }); @@ -230,7 +239,7 @@ public class Main extends JFrame { private void registerNameCreate() { registerName = new JPanel(); - JLabel jl = new JLabel("Name"); + JLabel jl = new JLabel(" Name"); JTextField tf = new JTextField(10); tf.setName("registerPasswordText"); registerName.add(jl); @@ -239,7 +248,7 @@ public class Main extends JFrame { private void registerPasswordCreate() { registerPassword = new JPanel(); - JLabel jl = new JLabel("Passwort"); + JLabel jl = new JLabel(" Passwort"); JTextField tf = new JTextField(10); tf.setName("registerPasswordText"); registerPassword.add(jl); @@ -248,7 +257,7 @@ public class Main extends JFrame { private void registerOrtCreate() { registerOrt = new JPanel(); - JLabel jl = new JLabel("Ort"); + JLabel jl = new JLabel(" Ort"); JTextField tf = new JTextField(10); tf.setName("registerOrtText"); registerOrt.add(jl); @@ -257,7 +266,7 @@ public class Main extends JFrame { private void registerPLZCreate() { registerPLZ = new JPanel(); - JLabel jl = new JLabel("PLZ"); + JLabel jl = new JLabel(" PLZ"); JTextField tf = new JTextField(10); tf.setName("registerPLZText"); registerPLZ.add(jl); @@ -266,7 +275,7 @@ public class Main extends JFrame { private void registerCarNameCreate() { registerCarName = new JPanel(); - JLabel jl = new JLabel("Auto km/h"); + JLabel jl = new JLabel(" Auto Name"); JTextField tf = new JTextField(10); tf.setName("registerCarNameText"); registerCarName.add(jl); @@ -275,7 +284,7 @@ public class Main extends JFrame { private void registerCarSpeedCreate() { registerCarSpeed = new JPanel(); - JLabel jl = new JLabel("Auto km/h"); + JLabel jl = new JLabel(" Auto km/h"); JTextField tf = new JTextField(10); tf.setName("registerCarSpeedText"); registerCarSpeed.add(jl); @@ -284,7 +293,7 @@ public class Main extends JFrame { private void registerCarCO2Create() { registerCarCO2 = new JPanel(); - JLabel jl = new JLabel("Auto km/h"); + JLabel jl = new JLabel("Verbrauch/100km"); JTextField tf = new JTextField(10); tf.setName("registerCarCO2Text"); registerCarCO2.add(jl); @@ -293,7 +302,7 @@ public class Main extends JFrame { private void registerBikeSpeedCreate() { registerBikeSpeed = new JPanel(); - JLabel jl = new JLabel("Bike km/h"); + JLabel jl = new JLabel(" Bike km/h"); JTextField tf = new JTextField(10); tf.setName("registerBikeSpeedText"); registerBikeSpeed.add(jl); @@ -328,28 +337,25 @@ public class Main extends JFrame { }); } - private void searchPLZCreate() { - searchPLZ = new JPanel(); - JLabel jl = new JLabel("PLZ"); - JTextField tf = new JTextField(10); - tf.setName("plzSuche"); - searchPLZ.add(jl); - searchPLZ.add(tf); - } - - private void searchOrtCreate() { - searchOrt = new JPanel(); - JLabel jl = new JLabel("Ort"); - JTextField tf = new JTextField(10); + private void searchPLZ_ORTCreate() { + searchPLZ_ORT = new JPanel(); + JLabel jl = new JLabel("Plz oder Ort"); + JTextField tf = new JTextField(28); tf.setName("ortSuche"); - searchOrt.add(jl); - searchOrt.add(tf); + searchPLZ_ORT.add(jl); + searchPLZ_ORT.add(tf); } private void searchConfirmButtonCreate() { - searchConfirmButton = new JButton("Suche"); - searchConfirmButton.setPreferredSize(new Dimension(150, 50)); + searchConfirmButton = new JButton(); + searchConfirmButton.setPreferredSize(new Dimension(150, 80)); searchConfirmButton.setFocusable(false); + + ImageIcon icon = png("lupe.png", 20, 20); + searchConfirmButton.setIcon(icon); + searchConfirmButton.setText(" Suche"); + searchConfirmButton.setIconTextGap(3); + searchConfirmButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { @@ -359,9 +365,15 @@ public class Main extends JFrame { } private void randDestinationsCarButtonCreate() { //Auto Icon hinzufügen - randDestinationsCarButton = new JButton("Kurztrip"); - randDestinationsCarButton.setPreferredSize(new Dimension(150, 50)); + randDestinationsCarButton = new JButton(); + randDestinationsCarButton.setPreferredSize(new Dimension(150, 80)); randDestinationsCarButton.setFocusable(false); + + ImageIcon icon = png("auto.png", 20, 20); + randDestinationsCarButton.setIcon(icon); + randDestinationsCarButton.setText("Kurztrip"); + randDestinationsCarButton.setIconTextGap(3); + randDestinationsCarButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { @@ -371,9 +383,15 @@ public class Main extends JFrame { } private void randDestinationsBikeButtonCreate() { //Fahrrad Icon hinzufügen - randDestinationsBikeButton = new JButton("Kurztrip"); - randDestinationsBikeButton.setPreferredSize(new Dimension(150, 50)); + randDestinationsBikeButton = new JButton(); + randDestinationsBikeButton.setPreferredSize(new Dimension(150, 80)); randDestinationsBikeButton.setFocusable(false); + + ImageIcon icon = png("fahrrad.png", 20, 20); + randDestinationsBikeButton.setIcon(icon); + randDestinationsBikeButton.setText("Kurztrip"); + randDestinationsBikeButton.setIconTextGap(3); + randDestinationsBikeButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { @@ -396,4 +414,12 @@ public class Main extends JFrame { }); } + 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 + Image img = icon.getImage(); + Image newimg = img.getScaledInstance(sizeX, sizeY, java.awt.Image.SCALE_SMOOTH); // wähle Größe des PNGs + ImageIcon iconTwo = new ImageIcon(newimg); + return iconTwo; + } + }