# JPanel Größe ändern



## pawlo (28. Apr 2012)

Hallo, 

möchte die Größe eines LogIn-Register Menüs ändern. Leider mit den üblichen Befehlen bis jetzt ohne Erfolg, z.B. panel.setSize(...) oder panel.getDimension() etc. ...

Weiß eventuell jm. was noch zu machen ist?

Gruß Pawel



```
class Register extends JFrame implements ActionListener
{
 JButton SUBMIT;
 JPanel panel;
 JLabel label1,label2, label3, l4,l5,l6,l7;
 final JTextField  text1,text2, text3, vname, name, jgang, kgr;

  Register()
  {
     
  label1 = new JLabel();
  label1.setText("Username:");
  text1 = new JTextField(15);

  label2 = new JLabel();
  label2.setText("Password:");
  text2 = new JPasswordField(15);
  
  label3 = new JLabel();
  label3.setText("Confirm Password:");
  text3 = new JPasswordField(15);
  
  l4 = new JLabel();
  l4.setText("VorName");
  vname = new JTextField(15);
  
  l5 = new JLabel();
  l4.setText("Name");
  name = new JTextField(15);
  
  l6 = new JLabel();
  l6.setText("Jahrgang");
  jgang = new JTextField(15);
  
  l7 = new JLabel();
  l7.setText("KörperGröße");
  kgr = new JTextField(15);
  
  SUBMIT=new JButton("SUBMIT");
  
  panel=new JPanel(new GridLayout(7,1));
  panel.add(label1);
  panel.add(text1);
  panel.add(label2);
  panel.add(text2);
  panel.add(label3);
  panel.add(text3);
  panel.add(l4);
   panel.add(l5);
   panel.add(l6);
   panel.add(l7);
  panel.add(SUBMIT);
  
  pack();
    panel.setSize(400,300);

  //panel.setPreferredSize(new Dimension(400, 200));
  //panel.getBounds();
  add(panel,BorderLayout.CENTER);
  SUBMIT.addActionListener(this);
  setTitle("REGISTER FORM"); 
  }
```


----------



## KingOfExceptions (28. Apr 2012)

mach doch mal dein 
	
	
	
	





```
panel.setSize();
```
 vor dem 
	
	
	
	





```
pack();
```


----------



## pawlo (28. Apr 2012)

geht leider immer noch nicht:-(


----------



## KingOfExceptions (28. Apr 2012)

und setBounds() ?

und mach es vlllt mal vor die 
	
	
	
	





```
panel.add(...);
```


----------



## pawlo (28. Apr 2012)

funktioniert auch nicht, aber warum?


----------



## KingOfExceptions (28. Apr 2012)

dann mach halt:


```
panel=new JPanel(500,200);
panel.setLayout(new GridLayout(7,1));
```

sorry weiß ich grad auch nicht...

und setzt vllt mal ein 
	
	
	
	





```
validate()
```
 und ein 
	
	
	
	





```
repaint();
```
 ..... kann manchmal helfen...


----------



## pawlo (28. Apr 2012)

kein Problem, werde noch weitergucken.


----------



## KingOfExceptions (28. Apr 2012)

hat keins davon funktioniert?


----------



## pawlo (28. Apr 2012)

nee, leider nicht. weiss auch nicht woran es liegt...


----------



## KingOfExceptions (28. Apr 2012)

wieso soll das denn größer sein? passt nicht alles rein? dann mach das 
	
	
	
	





```
pack();
```
 raus, das 'packt' alles so zusammen, wie platz ist...


----------



## pawlo (28. Apr 2012)

ja genau, die box hat eine konstante größe ca 3x5cm und da passt nicht alles rein.
ohne pack() gets auch nicht.


----------



## KingOfExceptions (28. Apr 2012)

KingOfExceptions hat gesagt.:


> dann mach halt:
> 
> 
> ```
> ...




hat auch nicht geholfen? 

sonst schick mir halt mal den ganzen code dann kann ich versuchen es dir hinzubiegen


----------



## pawlo (28. Apr 2012)

ja ok, danke ist aber an eine db gebunden.


```
package fitness2;

import javax.swing.*;
import java.awt.*;
import java.io.*;
import java.awt.event.*;
import java.lang.Object;
import java.sql.*;
import javax.swing.JOptionPane;


public class FitNess2 extends JFrame implements ActionListener, WindowListener{
    
 
	
	private JButton jb;
        
        private   JMenuBar menueleiste;
        private  JMenu menu1,menu2;
        private  JMenuItem item1,item2;
        
       
      
       
       
	public FitNess2 ()
	{
		super ("FitNess2");
		JPanel mainpanel = new JPanel ();
		mainpanel.setLayout (new BorderLayout ());
		this.getContentPane ().add (mainpanel);
                addWindowListener(this);
		//jb = new JButton ("foobar");
		//jb.addActionListener (this);
		        //jta = new JTextArea ();
		       
	    menueleiste = new JMenuBar();
              menu1 = new JMenu("File");
              menu1.addActionListener(this);
              menu1.setEnabled(true);
             
              item1 = new JMenuItem("Login");
              item1.addActionListener(this);
              item1.setEnabled(true);  
              menu1.add(item1);
              
              item1 = new JMenuItem("Register");
              item1.addActionListener(this);
              item1.setEnabled(true);
              menu1.add(item1);
               
               item1 = new JMenuItem("Exit");
               item1.addActionListener(this);
               menu1.setEnabled(true);
               menu1.add(item1);
               
               item1 = new JMenuItem("Benutzer");
               item1.addActionListener(this);
               menu1.setEnabled(true);
               menu1.add(item1);
              
               menueleiste.add(menu1);
              
              menu1 = new JMenu("BenutzerDat");
              menu1.addActionListener(this);
              menu1.setEnabled(true);
              menu2 = new JMenu("Datum");
              menu2.addActionListener(this);
              menu2.setEnabled(true);
           /*   item1 = new JMenuItem("Datum");
              item1.addActionListener(this);
              item1.setEnabled(true);*/
              menu1.add(menu2);
              
              
              item1= new JMenuItem("Ubers");
              item1.addActionListener(this);
              item1.setEnabled(true);
              menu1.add(item1);
              menu2.add(item1);
              
              item1= new JMenuItem("Add");
              item1.addActionListener(this);
              item1.setEnabled(true);
              menu1.add(item1);
              menu2.add(item1);
               
              item1= new JMenuItem("Delete");
              item1.addActionListener(this);
              item1.setEnabled(true);
              menu1.add(item1);
              
              menueleiste.add(menu1);
              
          /*    menu1 = new JMenu("Register");
              menu1.addActionListener(this);
              menu1.setEnabled(true);*/
              
              menueleiste.add(menu1);
                      
              menueleiste.add(menu1);
              
		//jta.setBounds (20, 10, 560, 450);
		//jta.setLineWrap (true);
		//jta.setWrapStyleWord (true);
		
              
		
               // mainpanel.add (j, BorderLayout.CENTER);
	        mainpanel.add (menueleiste, BorderLayout.NORTH);
                setSize (400, 200);
		setLocation (100, 100);
		setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
                setVisible (true);    
                
                
                              
	}
        //--------LOGIN---------
       
         class NextPage extends JFrame
{
  NextPage()
 {
 setDefaultCloseOperation(javax.swing.
  WindowConstants.DISPOSE_ON_CLOSE);
 setTitle("Welcome");
 setSize(400, 200);
  }
 } 
        
             class Login extends JFrame implements ActionListener
{
 JButton SUBMIT;
 JPanel panel;
 JLabel label1,label2;
 final JTextField  text1,text2;

  Login()
  {
     
  label1 = new JLabel();
  label1.setText("Username:");
  text1 = new JTextField(15);

  label2 = new JLabel();
  label2.setText("Password:");
  text2 = new JPasswordField(15);
 
  SUBMIT=new JButton("SUBMIT");
  
  panel=new JPanel(new GridLayout(3,1));
  
  panel.add(label1);
  panel.add(text1);
  panel.add(label2);
  panel.add(text2);
  panel.add(SUBMIT);
  add(panel,BorderLayout.CENTER);
  SUBMIT.addActionListener(this);
  setTitle("LOGIN FORM"); 
  }
  //----------SQL-Login--------
  
  
  String sql="Select * from fitn1 where uname = 'koko'";
  
//  String sql1="Select uname from fitn1 where uname = 'koko'";
 // String sql2="Select upass from fitn1 where upass = 'abc'";
 /* public void connect(ResultSet rs) 
  {

  }*/
  
 public void actionPerformed(ActionEvent ae)
  {
  String value1=text1.getText();
  String value2=text2.getText();
 //-----------
 // String sql1="Select uname from fitn1 where uname = '"+value1+"';";
 // String sql2="Select upass from fitn1 where upass = '"+value2+"';";
 // String sql1="Select uname from fitn1 where uname = 'koko'";
 // String sql2="Select upass from fitn1 where upass = 'abc'";
  try {
Class.forName("com.mysql.jdbc.Driver");
Connection con= (Connection) DriverManager.getConnection("jdbc:mysql://localhost/first","root","mypawel");
/*As we are creating a connection on a local computer we will write the url as jdbc:mysql://localhost:3306 */
Statement stmt=con.createStatement();
//ResultSet  rs1 = stmt.executeQuery(sql1);
//ResultSet  rs2 = stmt.executeQuery(sql2);
ResultSet  rs = stmt.executeQuery(sql);
while(rs.next()){
//String uname=rs1.getString("uname");
    String uname=rs.getString("uname");
    String upass=rs.getString("upass");
//String upass=rs2.getString("upass");
//Username is the coloumn name in the database table 
//String password=rs.getString("Password");

if (value1.equals(uname) && value2.equals(upass)) {
  NextPage page=new NextPage();
  page.setVisible(true);
  JLabel label = new JLabel("Welcome: "+value1);
  page.getContentPane().add(label);
  dispose();

  }
  
  else{
  System.out.println("enter the valid username and password");
  JOptionPane.showMessageDialog(this,"Incorrect login or password",
  "Error",JOptionPane.ERROR_MESSAGE);
  }
}
}
catch (Exception e){
    System.out.println(value1);
JOptionPane.showMessageDialog(this, e.getMessage());
}
  
}
} 
   
 //------------------REGISTER------     
             class Register extends JFrame implements ActionListener
{
 JButton SUBMIT;
 JPanel panel;
 JLabel label1,label2, label3, l4,l5,l6,l7;
 final JTextField  text1,text2, text3, vname, name, jgang, kgr;

  Register()
  {
     
  label1 = new JLabel();
  label1.setText("Username:");
  text1 = new JTextField(15);

  label2 = new JLabel();
  label2.setText("Password:");
  text2 = new JPasswordField(15);
  
  label3 = new JLabel();
  label3.setText("Confirm Password:");
  text3 = new JPasswordField(15);
  
  l4 = new JLabel();
  l4.setText("VorName");
  vname = new JTextField(15);
  
  l5 = new JLabel();
  l4.setText("Name");
  name = new JTextField(15);
  
  l6 = new JLabel();
  l6.setText("Jahrgang");
  jgang = new JTextField(15);
  
  l7 = new JLabel();
  l7.setText("KörperGröße");
  kgr = new JTextField(15);
  
  SUBMIT=new JButton("SUBMIT");
  
  panel=new JPanel(new GridLayout(7,1));
   

  
  panel.add(label1);
  panel.add(text1);
  panel.add(label2);
  panel.add(text2);
  panel.add(label3);
  panel.add(text3);
  panel.add(l4);
   panel.add(l5);
   panel.add(l6);
   panel.add(l7);
  panel.add(SUBMIT);
  
 // panel.setLayout (new BorderLayout ()); 
   //this.getContentPane ().add (panel);
              //  addWindowListener(this);
 
  //this.pack();
   // panel.setSize(400,300);
 // panel.setLayout (new BorderLayout ()); 
  this.getContentPane ().add (panel);
  panel.setBounds(200,300,400,200);
panel.validate();
panel.repaint();
  //  this.pack();
   // panel.
     setVisible(true);
  //panel.setPreferredSize(new Dimension(400, 200));
  //panel.getBounds();
  add(panel,BorderLayout.CENTER);
  SUBMIT.addActionListener(this);
  setTitle("REGISTER FORM"); 
  }
  //----------SQL-Login--------
  
  
 
  
  
 public void actionPerformed(ActionEvent ae)
  {
  String value1=text1.getText();
  String value2=text2.getText();
  String value3=text3.getText();
 
  try {
Class.forName("com.mysql.jdbc.Driver");
Connection con= (Connection) DriverManager.getConnection("jdbc:mysql://localhost/first","root","mypawel");
/*As we are creating a connection on a local computer we will write the url as jdbc:mysql://localhost:3306 */


 String sql="Select * from fitn1 where uname = 'koko'";

Statement stmt=con.createStatement();

ResultSet  rs = stmt.executeQuery(sql);

 
   
   String sql2="insert into fitn1 (uname, upass) values ('"+value1+"','"+value2+"')";
 
   while(rs.next()){
       String uname=rs.getString("uname");
    // !value2.equals(uname) &&  value2.equals(value3)
 if  ((!value1.equals("") && !value2.equals("") && !value3.equals("")) && value2.equals(value3) && !value2.equals(uname))
//if (((!value1.equals("") && !value2.equals("") && value3.equals("")) && value2.equals(value3) && !value2.equals(uname)))
      //  || (value1.equals("") && !value2.equals("") && !value3.equals(""))|| (!value1.equals("") && value2.equals("") && !value3.equals("")) || (value1.equals("") && !value2.equals("") && !value3.equals(""))) && value2.equals(value3) && !value2.equals(uname))
        //&& !value2.equals(uname) )
{      
     Statement stmt2=con.createStatement();
     stmt2.executeUpdate(sql2);
     stmt2.close();
     dispose();

  }
  
  else{
  System.out.println("enter the valid username and password");
  JOptionPane.showMessageDialog(this,"Incorrect login or password",
  "Error",JOptionPane.ERROR_MESSAGE);
  }
   }
}
catch (Exception e){
    System.out.println(value1);
JOptionPane.showMessageDialog(this, e.getMessage());
}
  }

} 
             
    //---------------------------End Register-------------
	
             public void actionPerformed (ActionEvent e)
	{       
               
             
		String cmd = e.getActionCommand ();
		if (cmd.equals ("Login"))
		{
			
                 Login frame= new Login();
                 frame.setSize(300,100);
                 frame.setVisible(true);
                    
		}
		
                if(cmd.equals("Exit"))
                {
                  dispose();
                  System.exit(0);
                }
               
                if(cmd.equals("Register"))
                {
                Register frame = new Register();
                 frame.setSize(300,100);
                 frame.setVisible(true);
                         
                }          
                    	}
       

             
 public void windowClosing(WindowEvent e)
    {
        dispose();
        System.exit(0);
    }
     public void windowClosed(WindowEvent e)
    {
    }
    public void windowOpened(WindowEvent e)
    {
    }
    public void windowIconified(WindowEvent e)
    {
    }
    public void windowDeiconified(WindowEvent e)
    {
    }
    public void windowActivated(WindowEvent e)
    {
    }
    public void windowDeactivated(WindowEvent e)
    {
    }
    
    
    public static void main(String[] args) {
      
              new FitNess2();
        
    }
}
```


----------



## KingOfExceptions (28. Apr 2012)

ok mach mich gleich ran


----------



## KingOfExceptions (28. Apr 2012)

ok ich frage mal ganz blöd: wieso machst du nicht 
	
	
	
	





```
this.setSize(200,400);
```
 ?


----------



## pawlo (28. Apr 2012)

ja habe schon ausprobiert, hat aber für register-fenster nicht funktioniert.


----------



## KingOfExceptions (28. Apr 2012)

pawlo hat gesagt.:


> ja habe schon ausprobiert, hat aber für register-fenster nicht funktioniert.



ich sehe nur jframes...? und wie wärs mit 
	
	
	
	





```
this.pack();
```
 ?

zumindest funktioniert beides bei mir.....


----------



## pawlo (28. Apr 2012)

läufts nicht 


```
panel=new JPanel(new GridLayout(7,1));
   

  
  panel.add(label1);
  panel.add(text1);
  panel.add(label2);
  panel.add(text2);
  panel.add(label3);
  panel.add(text3);
  panel.add(l4);
   panel.add(l5);
   panel.add(l6);
   panel.add(l7);
  panel.add(SUBMIT);
  
 // panel.setLayout (new BorderLayout ()); 
   //this.getContentPane ().add (panel);
              //  addWindowListener(this);
 
  //this.pack();
   // panel.setSize(400,300);
 // panel.setLayout (new BorderLayout ()); 
  this.getContentPane ().add (panel);
 // panel.setBounds(200,300,400,200);
panel.validate();
panel.repaint();
  //  this.pack();
   // panel.
 this.pack();
     setVisible(true);
     //this.setSize(200, 400);
  //panel.setPreferredSize(new Dimension(400, 200));
  //panel.getBounds();
   
  add(panel,BorderLayout.CENTER);
  SUBMIT.addActionListener(this);
  setTitle("REGISTER FORM"); 
  }
```


----------



## KingOfExceptions (28. Apr 2012)

bin noch dran


----------



## pawlo (28. Apr 2012)

also wirklich geht es mir nur um die größe des panels, der rest ist unwichtig.


----------



## KingOfExceptions (28. Apr 2012)

ok fertig.... ich hab ein paar teile wegen der übersichtlichkeit halber rausgelöscht...hier mal zum copy und pasten


```
package fitness2;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import javax.swing.JOptionPane;

public class FitNess2 extends JFrame implements ActionListener , WindowListener
{
    private static final long serialVersionUID = 1L;
    private JMenuBar menueleiste;
    private JMenu    menu1 , menu2;
    private JMenuItem item1;
    
    public FitNess2()
    {
        super("FitNess2");
        JPanel mainpanel = new JPanel();
        mainpanel.setLayout(new BorderLayout());
        this.getContentPane().add(mainpanel);
        addWindowListener(this);
        // jb = new JButton ("foobar");
        // jb.addActionListener (this);
        // jta = new JTextArea ();
        
        menueleiste = new JMenuBar();
        menu1 = new JMenu("File");
        menu1.addActionListener(this);
        menu1.setEnabled(true);
        
        item1 = new JMenuItem("Login");
        item1.addActionListener(this);
        item1.setEnabled(true);
        menu1.add(item1);
        
        item1 = new JMenuItem("Register");
        item1.addActionListener(this);
        item1.setEnabled(true);
        menu1.add(item1);
        
        item1 = new JMenuItem("Exit");
        item1.addActionListener(this);
        menu1.setEnabled(true);
        menu1.add(item1);
        
        item1 = new JMenuItem("Benutzer");
        item1.addActionListener(this);
        menu1.setEnabled(true);
        menu1.add(item1);
        
        menueleiste.add(menu1);
        
        menu1 = new JMenu("BenutzerDat");
        menu1.addActionListener(this);
        menu1.setEnabled(true);
        menu2 = new JMenu("Datum");
        menu2.addActionListener(this);
        menu2.setEnabled(true);
        /*
         * item1 = new JMenuItem("Datum");
         * item1.addActionListener(this);
         * item1.setEnabled(true);
         */
        menu1.add(menu2);
        
        item1 = new JMenuItem("Ubers");
        item1.addActionListener(this);
        item1.setEnabled(true);
        menu1.add(item1);
        menu2.add(item1);
        
        item1 = new JMenuItem("Add");
        item1.addActionListener(this);
        item1.setEnabled(true);
        menu1.add(item1);
        menu2.add(item1);
        
        item1 = new JMenuItem("Delete");
        item1.addActionListener(this);
        item1.setEnabled(true);
        menu1.add(item1);
        
        menueleiste.add(menu1);
        
        /*
         * menu1 = new JMenu("Register");
         * menu1.addActionListener(this);
         * menu1.setEnabled(true);
         */
        
        menueleiste.add(menu1);
        
        menueleiste.add(menu1);
        
        // jta.setBounds (20, 10, 560, 450);
        // jta.setLineWrap (true);
        // jta.setWrapStyleWord (true);
        
        // mainpanel.add (j, BorderLayout.CENTER);
        mainpanel.add(menueleiste, BorderLayout.NORTH);
        setSize(400, 200);
        setLocation(100, 100);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setVisible(true);
        
    }
    
    // --------LOGIN---------
    
    class NextPage extends JFrame
    {
        private static final long serialVersionUID = 1L;

        NextPage()
        {
            setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
            setTitle("Welcome");
            setSize(400, 200);
        }
    }
    
    class Login extends JFrame implements ActionListener
    {
        private static final long serialVersionUID = 1L;
        JButton SUBMIT;
        JPanel  panel;
        JLabel  label1 , label2;
        final JTextField text1 , text2;
        
        Login()
        {
            
            label1 = new JLabel();
            label1.setText("Username:");
            text1 = new JTextField(15);
            
            label2 = new JLabel();
            label2.setText("Password:");
            text2 = new JPasswordField(15);
            
            SUBMIT = new JButton("SUBMIT");
            
            panel = new JPanel(new GridLayout(3, 1));
            
            panel.add(label1);
            panel.add(text1);
            panel.add(label2);
            panel.add(text2);
            panel.add(SUBMIT);
            add(panel);
            SUBMIT.addActionListener(this);
            pack();
            setTitle("LOGIN FORM");
            setVisible(true);
        }
        
        // ----------SQL-Login--------
        
        String sql = "Select * from fitn1 where uname = 'koko'";
        
        // String sql1="Select uname from fitn1 where uname = 'koko'";
        // String sql2="Select upass from fitn1 where upass = 'abc'";
        /*
         * public void connect(ResultSet rs)
         * {
         * }
         */
        
        public void actionPerformed(ActionEvent ae)
        {
            String value1 = text1.getText();
            String value2 = text2.getText();
            // -----------
            // String
            // sql1="Select uname from fitn1 where uname = '"+value1+"';";
            // String
            // sql2="Select upass from fitn1 where upass = '"+value2+"';";
            // String sql1="Select uname from fitn1 where uname = 'koko'";
            // String sql2="Select upass from fitn1 where upass = 'abc'";
            try
            {
                Class.forName("com.mysql.jdbc.Driver");
                Connection con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost/first", "root", "mypawel");
                /*
                 * As we are creating a connection on a local computer we will
                 * write the url as jdbc:mysql://localhost:3306
                 */
                Statement stmt = con.createStatement();
                // ResultSet rs1 = stmt.executeQuery(sql1);
                // ResultSet rs2 = stmt.executeQuery(sql2);
                ResultSet rs = stmt.executeQuery(sql);
                while (rs.next())
                {
                    // String uname=rs1.getString("uname");
                    String uname = rs.getString("uname");
                    String upass = rs.getString("upass");
                    // String upass=rs2.getString("upass");
                    // Username is the coloumn name in the database table
                    // String password=rs.getString("Password");
                    
                    if (value1.equals(uname) && value2.equals(upass))
                    {
                        NextPage page = new NextPage();
                        page.setVisible(true);
                        JLabel label = new JLabel("Welcome: " + value1);
                        page.getContentPane().add(label);
                        dispose();
                        
                    }
                    
                    else
                    {
                        System.out.println("enter the valid username and password");
                        JOptionPane.showMessageDialog(this, "Incorrect login or password", "Error", JOptionPane.ERROR_MESSAGE);
                    }
                }
            }
            catch (Exception e)
            {
                System.out.println(value1);
                JOptionPane.showMessageDialog(this, e.getMessage());
            }
            
        }
    }
    
    // ------------------REGISTER------
    class Register extends JFrame implements ActionListener
    {
        private static final long serialVersionUID = 1L;
        JButton SUBMIT;
        JPanel  panel;
        JLabel  label1 , label2 , label3 , l4 , l5 , l6 , l7;
        final JTextField text1 , text2 , text3 , vname , name , jgang , kgr;
        
        Register()
        {
            
            label1 = new JLabel();
            label1.setText("Username:");
            text1 = new JTextField(15);
            
            label2 = new JLabel();
            label2.setText("Password:");
            text2 = new JPasswordField(15);
            
            label3 = new JLabel();
            label3.setText("Confirm Password:");
            text3 = new JPasswordField(15);
            
            l4 = new JLabel();
            l4.setText("VorName");
            vname = new JTextField(15);
            
            l5 = new JLabel();
            l4.setText("Name");
            name = new JTextField(15);
            
            l6 = new JLabel();
            l6.setText("Jahrgang");
            jgang = new JTextField(15);
            
            l7 = new JLabel();
            l7.setText("KörperGröße");
            kgr = new JTextField(15);
            
            SUBMIT = new JButton("SUBMIT");
            
            panel = new JPanel(new GridLayout(7, 1));
            
            panel.add(label1);
            panel.add(text1);
            panel.add(label2);
            panel.add(text2);
            panel.add(label3);
            panel.add(text3);
            panel.add(l4);
            panel.add(l5);
            panel.add(l6);
            panel.add(l7);
            panel.add(SUBMIT);
 
            add(panel);
            pack();
            SUBMIT.addActionListener(this);
            setTitle("REGISTER FORM");
            setVisible(true);
        }
        
        // ----------SQL-Login--------
        
        public void actionPerformed(ActionEvent ae)
        {
            String value1 = text1.getText();
            String value2 = text2.getText();
            String value3 = text3.getText();
            
            try
            {
                Class.forName("com.mysql.jdbc.Driver");
                Connection con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost/first", "root", "mypawel");
                /*
                 * As we are creating a connection on a local computer we will
                 * write the url as jdbc:mysql://localhost:3306
                 */
                
                String sql = "Select * from fitn1 where uname = 'koko'";
                
                Statement stmt = con.createStatement();
                
                ResultSet rs = stmt.executeQuery(sql);
                
                String sql2 = "insert into fitn1 (uname, upass) values ('" + value1 + "','" + value2 + "')";
                
                while (rs.next())
                {
                    String uname = rs.getString("uname");
                    // !value2.equals(uname) && value2.equals(value3)
                    if ((!value1.equals("") && !value2.equals("") && !value3.equals("")) && value2.equals(value3) && !value2.equals(uname))
                    // if (((!value1.equals("") && !value2.equals("") &&
                    // value3.equals("")) && value2.equals(value3) &&
                    // !value2.equals(uname)))
                    // || (value1.equals("") && !value2.equals("") &&
                    // !value3.equals(""))|| (!value1.equals("") &&
                    // value2.equals("") && !value3.equals("")) ||
                    // (value1.equals("") && !value2.equals("") &&
                    // !value3.equals(""))) && value2.equals(value3) &&
                    // !value2.equals(uname))
                    // && !value2.equals(uname) )
                    {
                        Statement stmt2 = con.createStatement();
                        stmt2.executeUpdate(sql2);
                        stmt2.close();
                        dispose();
                        
                    }
                    
                    else
                    {
                        System.out.println("enter the valid username and password");
                        JOptionPane.showMessageDialog(this, "Incorrect login or password", "Error", JOptionPane.ERROR_MESSAGE);
                    }
                }
            }
            catch (Exception e)
            {
                System.out.println(value1);
                JOptionPane.showMessageDialog(this, e.getMessage());
            }
        }
        
    }
    
    // ---------------------------End Register-------------
    
    public void actionPerformed(ActionEvent e)
    {
        
        String cmd = e.getActionCommand();
        if (cmd.equals("Login"))
        {
            new Login();
        }
        
        if (cmd.equals("Exit"))
        {
            dispose();
            System.exit(0);
        }
        
        if (cmd.equals("Register"))
        {
            new Register();
            
        }
    }
    
    public void windowClosing(WindowEvent e)
    {
        dispose();
        System.exit(0);
    }
    
    public void windowClosed(WindowEvent e)
    {
    }
    
    public void windowOpened(WindowEvent e)
    {
    }
    
    public void windowIconified(WindowEvent e)
    {
    }
    
    public void windowDeiconified(WindowEvent e)
    {
    }
    
    public void windowActivated(WindowEvent e)
    {
    }
    
    public void windowDeactivated(WindowEvent e)
    {
    }
    
    public static void main(String[] args)
    {
        
        new FitNess2();
        
    }
}
```

und hier lag der fehler:


```
public void actionPerformed(ActionEvent e)
   		 {
        
       		 String cmd = e.getActionCommand();
        
        	if (cmd.equals("Exit"))
       	 {
            dispose();
            System.exit(0);
        }
        
        if (cmd.equals("Register"))
        {
            new Register();
            
        }
   	 }
```

[WR]EINRÜCKEN! Du solltest deinen Code umbedingt einrücken, sonst wird das mit der Fehlersuche nichts! Die if/else Anweisungen werden dann viel übersichtlicher, so findet man dann auch Fehler viel schneller. [/WR]


----------



## pawlo (30. Apr 2012)

habe jetzt den Fehler selber gefunden. Die Größe wurde nochmal beim Aufruf festgelegt.


----------



## KingOfExceptions (30. Apr 2012)

ist ja das, was ich dir gesagt hab....


----------

