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

    la mia jDialog non si chiude ;(

    salve a tutti!!
    ho un problema ...
    sto' cercando di ricreare una jdialog per l'uscita dalla mia applicazione che chiede all'utente se ha intenzione veramente di uscire, quindi con 2 bottoni: si, che chiude il tutto e no, che dovrebbe far scomparire la jdialog.

    questo è qll che ho fatto, non mi funziona il bottone no ... cosa sbaglio???

    codice:
    package Schedule.Accesso;
    
    import javax.swing.ImageIcon;
    import javax.swing.JButton;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import java.awt.Frame;
    import java.awt.Toolkit;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    
    import javax.swing.JDialog;
    
    import com.jgoodies.forms.layout.CellConstraints;
    
    public class EsciDaSchedule extends JDialog {
    
    	/**
    	 * 
    	 */
    	private static final long serialVersionUID = 1L;
    
    	private JLabel Corso;
    
    	private JLabel jLabel1;
    
    	private JPanel scatola;
    	private JButton SI;
    	private JLabel Esci;
    	private JButton NO;
    	public JDialog jDialog;
    	
    	
    	/* (non-Javadoc)
    	 * @see Schedule.Accesso.Interfaccia#getJFrame()
    	 */
    	public JDialog getJDialog() {
    		if (jDialog == null) {
    			jDialog = new JDialog();
    			jDialog.setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource("/img/logo_uni.png")));
    			jDialog.setSize(550,300);
    			jDialog.setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource("/img/logo_uni.png")));
    			jDialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
    			jDialog.setContentPane(getJContentPane());
    
    		}
    		return jDialog;
    	}
    
    	/**
    	 * @param owner
    	 */
    	public EsciDaSchedule(Frame owner) {
    		super(owner);
    		initialize();
    		
    	}
    
    	/**
    	 * This method initializes this
    	 * 
    	 * @return void
    	 */
    	private void initialize() {
    		this.setSize(550, 300);
    		this.setContentPane(getJContentPane());
    	}
    
    	/**
    	 * This method initializes jContentPane
    	 * 
    	 * @return javax.swing.JPanel
    	 */
    	public JPanel getJContentPane(){
    		if(scatola==null){
    			scatola = new JPanel();
    			scatola.setLayout(null);
    			scatola.setPreferredSize(new java.awt.Dimension(500, 300));
    			scatola.setBackground(new java.awt.Color(0, 51, 255));
    			scatola.add(getCorso());
    			scatola.add(getjLabel1());
    			scatola.add(getSI());
    			scatola.add(getNO());
    			scatola.add(getEsci());
    
    		}
    		return scatola;
    		}
    
    	public JLabel getCorso(){
    			if (Corso==null){
    						Corso = new JLabel("");
    						scatola.add(Corso, new CellConstraints("3, 5, 1, 1, default, default"));
    						Corso.setBounds(208, 201, 293, 35);
    					}
    			return Corso;
    	}
    
    	public JLabel getjLabel1(){
    		if(jLabel1==null)
    					{
    						jLabel1 = new JLabel();
    						scatola.add(jLabel1, new CellConstraints("3, 3, 2, 1, default, default"));
    						jLabel1.setIcon(new ImageIcon(getClass().getClassLoader().getResource("img/schedule.png")));
    						jLabel1.setBounds(0, 20, 637, 85);
    					}
    		return jLabel1;
    	}
    
    		
    	        
    	    
    
    			
    			private JButton getSI() {
    				if(SI == null) {
    					SI = new JButton();
    					SI.setBounds(149, 214, 59, 22);
    					SI.setText("Si");
    					SI.addActionListener(new ActionListener() {
    						public void actionPerformed(ActionEvent evt) {
    							System.out.println("SI.actionPerformed, event="+evt);
    							//TODO add your code for SI.actionPerformed
    							System.exit(0);
    						}
    					});
    
    				}
    				return SI;
    			}
    			
    			private JButton getNO() {
    				if(NO == null) {
    					NO = new JButton();
    					NO.setBounds(295, 214, 59, 22);
    					NO.setText("No");
    					NO.addActionListener(new ActionListener() {
    						public void actionPerformed(ActionEvent evt) {
    							System.out.println("NO.actionPerformed, event="+evt);
    							//TODO add your code for NO.actionPerformed
    							EsciDaSchedule esci= new EsciDaSchedule(null);
    							esci.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
    ;
    						}
    					});
    
    				}
    				return NO;
    			}
    			
    			private JLabel getEsci() {
    				if(Esci == null) {
    					Esci = new JLabel();
    					Esci.setBounds(69, 149, 37, 16);
    				}
    				return Esci;
    			}
    
    	
    }

  2. #2
    Utente di HTML.it L'avatar di andbin
    Registrato dal
    Jan 2006
    residenza
    Italy
    Messaggi
    18,284
    Usa showConfirmDialog() di javax.swing.JOptionPane. Fai 10 volte prima.
    Andrea, andbin.devSenior Java developerSCJP 5 (91%) • SCWCD 5 (94%)
    java.util.function Interfaces Cheat SheetJava Versions Cheat Sheet

  3. #3
    Utente di HTML.it L'avatar di 1sirena
    Registrato dal
    Mar 2008
    Messaggi
    163
    scusa l'ignoranza ... e cm lo dovrei usare???

  4. #4
    Utente di HTML.it L'avatar di andbin
    Registrato dal
    Jan 2006
    residenza
    Italy
    Messaggi
    18,284
    Originariamente inviato da 1sirena
    scusa l'ignoranza ... e cm lo dovrei usare???
    http://java.sun.com/javase/6/docs/ap...ptionPane.html
    Andrea, andbin.devSenior Java developerSCJP 5 (91%) • SCWCD 5 (94%)
    java.util.function Interfaces Cheat SheetJava Versions Cheat Sheet

  5. #5
    Utente di HTML.it L'avatar di 1sirena
    Registrato dal
    Mar 2008
    Messaggi
    163
    grazie ho risolto

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.