Visualizzazione dei risultati da 1 a 4 su 4
  1. #1
    Utente di HTML.it L'avatar di 1sirena
    Registrato dal
    Mar 2008
    Messaggi
    163

    nascondere jpanel al click

    Ciao a tutti!!
    Vorrei che cliccando sul pulsante "Entra" presente nel JPanel "Login" venga nascosto il JPanel contenente la Login e compaia un altro JPanel. Come posso fare??



    codice:
    import java.awt.Color;
    import java.awt.Cursor;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.KeyEvent;
    
    import javax.swing.BorderFactory;
    import javax.swing.DebugGraphics;
    import javax.swing.ImageIcon;
    import javax.swing.JButton;
    import javax.swing.JLabel;
    import javax.swing.JOptionPane;
    import javax.swing.JPanel;
    import javax.swing.JPasswordField;
    import javax.swing.JTextField;
    import javax.swing.border.BevelBorder;
    import javax.swing.border.SoftBevelBorder;
    
    import org.schedule.db.SQLManager;
    
    
    import com.jgoodies.forms.layout.CellConstraints;
    import com.jgoodies.forms.layout.FormLayout;
    
    
    /**
    * This code was edited or generated using CloudGarden's Jigloo
    * SWT/Swing GUI Builder, which is free for non-commercial
    * use. If Jigloo is being used commercially (ie, by a corporation,
    * company or business for any purpose whatever) then you
    * should purchase a license for each developer using Jigloo.
    * Please visit www.cloudgarden.com for details.
    * Use of Jigloo implies acceptance of these licensing terms.
    * A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
    * THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
    * LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
    */
    @SuppressWarnings("serial")
    public class PannelloLogin  {
    	public JPasswordField jPasswordField1;
    	private JLabel jLabel2;
    	public JButton jButton1;
    	private JLabel jLabel3;
    	private JLabel jLabel1;
    	public JTextField textFieldUsername;
    	public JPanel jPanel1;
    	private JLabel LabLogin;
    	public static boolean utenteLoggato = false; 
    	
    	
    	@SuppressWarnings("unused")
    	public JPanel getJContentPane()
     {
    		if(jPanel1 == null) {
    			jPanel1 = new JPanel();
    			FormLayout jPanel1Layout = new FormLayout(
    					"max(p;5dlu), max(p;5dlu), 138dlu, 95dlu, max(p;5dlu)", 
    					"max(p;5dlu), max(p;5dlu), 8dlu, 17dlu, 37dlu, max(p;5dlu), 62dlu, max(p;5dlu), 62dlu");
    			jPanel1.setLayout(jPanel1Layout);
    			jPanel1.setBorder(new SoftBevelBorder(BevelBorder.LOWERED, null, null, null, null));
    			jPanel1.setBackground(new Color(0, 51, 255));
    			jPanel1.setPreferredSize(new java.awt.Dimension(542, 367));
    			jPanel1.add(getTextFieldUsername(), new CellConstraints("4, 4, 1, 1, default, default"));
    			jPanel1.add(getJPasswordField1(), new CellConstraints("4, 5, 1, 1, default, default"));
    			jPanel1.add(getJLabel1(), new CellConstraints("3, 4, 1, 1, default, default"));
    			jPanel1.add(getJButton1(), new CellConstraints("4, 7, 2, 1, default, default"));
    			jPanel1.add(getJLabel2(), new CellConstraints("3, 5, 1, 1, default, default"));
    			jPanel1.add(getJLabel3(), new CellConstraints("3, 2, 1, 1, default, default"));
    			jPanel1.add(getLabLogin(), new CellConstraints("2, 1, 3, 1, default, default"));
    		}
    		return jPanel1;
    	}
    	
    	
    	
    	public JTextField getTextFieldUsername() {
    		if(textFieldUsername == null) {
    			textFieldUsername = new JTextField();
    		}
    		return textFieldUsername;
    	}
    	
    	public JPasswordField getJPasswordField1() {
    		if(jPasswordField1 == null) {
    			jPasswordField1 = new JPasswordField();
    		}
    		return jPasswordField1;
    	}
    	
    	private JLabel getJLabel1() {
    		if(jLabel1 == null) {
    			jLabel1 = new JLabel();
    			jLabel1.setIcon(new ImageIcon(getClass().getClassLoader().getResource("img/username.png")));
    		}
    		return jLabel1;
    	}
    	
    	public JButton getJButton1() {
    		if(jButton1 == null) {
    			jButton1 = new JButton();
    			jButton1.setIcon(new ImageIcon(getClass().getClassLoader().getResource("img/entra.png")));
    			jButton1.setBackground(new java.awt.Color(255,128,255));
    			jButton1.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
    			jButton1.setOpaque(false);
    			jButton1.setBorderPainted(false);
    			jButton1.setDebugGraphicsOptions(DebugGraphics.BUFFERED_OPTION);
    			jButton1.setRolloverIcon(new ImageIcon(getClass().getResource("/img/entra2.png")));
    			jButton1.setPressedIcon(new ImageIcon(getClass().getResource("/img/entraClick.png")));
    			jButton1.setMnemonic(KeyEvent.VK_UNDEFINED);
    			jButton1.setFocusCycleRoot(true);
    			jButton1.setSelected(true);
    			jButton1.setFocusPainted(false);
    			jButton1.setFocusTraversalPolicyProvider(true);
    			jButton1.setContentAreaFilled(false);
                jButton1.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    
    			jButton1.addActionListener(new ActionListener() {
    				@SuppressWarnings("deprecation")
    		
    				public void actionPerformed(ActionEvent evt) { 
    				     try{ 
    				          if(textFieldUsername.getText().equals("") || jPasswordField1.getText().equals("")) { 
    				               JOptionPane.showMessageDialog(null, "Inserire Username e Password","Login", JOptionPane.ERROR_MESSAGE); 
    				          }else{ 
    
    				        	  SQLManager sqlm = new SQLManager("com.mysql.jdbc.Driver","jdbc:mysql://localhost:3306/schedule","root","root");
    
    				        	  		String query = "select * from Utente where cognome = ? and password = ?"; 
    				                    String[] parametri = new String[] {textFieldUsername.getText(), jPasswordField1.getText()}; 
    				                    boolean esitoLogin = sqlm.verificaEsistenzaRecord(query,parametri); 
    				                    if(esitoLogin){ 
    				                         //utente loggato 
    				                    	 utenteLoggato = false; 
    						                    //JOptionPane.showMessageDialog(null, "Utente loggato" ,"Login", JOptionPane.INFORMATION_MESSAGE);
    						                    jPanel1.setVisible(false);
    						                    
    						                    					                      }else{ 
    				                        //utente NON loggato 
    				                    	JOptionPane.showMessageDialog(null, "Riprova","Login", JOptionPane.ERROR_MESSAGE);
    					                	
    				                    } 
    				                      
    				                    sqlm.close();  //questa chiamata è importantissima onde evitare di lasciare troppe connessioni aperte verso il DB 
    				          } 
    				           
    				     }catch(Exception ex){ 
    				          ex.printStackTrace(); 
    				     } 
    				}
    
    				} 
    				
    				);
    
    
    		}
    		return jButton1;
    	}
    	private JLabel getJLabel2() {
    		if(jLabel2 == null) {
    			jLabel2 = new JLabel();
    			jLabel2.setIcon(new ImageIcon(getClass().getClassLoader().getResource("img/password.png")));
    		}
    		return jLabel2;
    	}
    	
    	private JLabel getJLabel3() {
    		if(jLabel3 == null) {
    			jLabel3 = new JLabel();
    		}
    		return jLabel3;
    	}
    	
    	private JLabel getLabLogin() {
    		if(LabLogin == null) {
    			LabLogin = new JLabel();
    			LabLogin.setIcon(new ImageIcon(getClass().getClassLoader().getResource("img/login.png")));
    		}
    		return LabLogin;
    	}
    
    }

  2. #2
    la prima cosa che mi viene in mente è settare le dimensioni a 0, aggiungere l'altro jpanel e repaint o validate..
    Write Once, Run Everywhere.
    Write Less, Do More.

  3. #3
    Utente di HTML.it L'avatar di 1sirena
    Registrato dal
    Mar 2008
    Messaggi
    163
    questa è la prima ... e non l'ho capita!? quindi che dici passiamo all'ultima cosa ke t viene in mente???

  4. #4
    dicevo alla pressione del bottone per il login, oltre che chiedere la connessione, il programma va a settare le dimensioni a 0..
    se prima il pannello era 200x300 ora diventa 0x0..
    intendevo questo.. non credo sia la cosa più giusta da fare ma è stato il primo "trucchetto" che mi era venuto in mente..
    Write Once, Run Everywhere.
    Write Less, Do More.

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.