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;
}
}