Sqlve.....
problemucci
Creo una GUI. All'interno di questa ultima istanzio un oggeto che crea un'altra GUI2. Chiudo GUI2 e si chiude pure GUI e il programma termina.
Come faccio a chiudere GUI2 senza che si chiuda anche GUI
![]()
![]()
![]()
Sqlve.....
problemucci
Creo una GUI. All'interno di questa ultima istanzio un oggeto che crea un'altra GUI2. Chiudo GUI2 e si chiude pure GUI e il programma termina.
Come faccio a chiudere GUI2 senza che si chiuda anche GUI
![]()
![]()
![]()
Dovrebbe bastare fornire anche la seconda Gui di un metodo main e lanciarla con un comando tipo:
codice:String [] rigaComando = {"java","nomeClasseSecondaGui"}; Runtime.getRuntime().exec(rigaComando);
Il centro dell'attenzione non è sempre un buon posto in cui trovarsi
Mai discutere con uno stupido, la gente potrebbe non capire la differenza. (O. W.)
da questa gui prelevo informaioni che servono alla gui precedente....come faccio???
non esiste un metodo meno drastico???
![]()
![]()
mmmmhhh però mi sembra strano...ti scoccia postare un po di codice per vedere come crei la seconda gui dalla prima?codice:Creo una GUI. All'interno di questa ultima istanzio un oggeto che crea un'altra GUI2. Chiudo GUI2 e si chiude pure GUI e il programma termina.
Il centro dell'attenzione non è sempre un buon posto in cui trovarsi
Mai discutere con uno stupido, la gente potrebbe non capire la differenza. (O. W.)
GUI 1
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
jButton1 = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstan ts.EXIT_ON_CLOSE);
jButton1.setText("jButton1");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jPanel1.add(jButton1);
getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER);
pack();
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
Due d=new Due();
}
GUI 2
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
jButton1 = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstan ts.EXIT_ON_CLOSE);
jButton1.setText("jButton1");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jPanel1.add(jButton1);
getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER);
pack();
}
public boolean getState1(){return state;}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
MAIN
public class Main {
/** Creates a new instance of Main */
public Main() {
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Uno u=new Uno();
}
}
![]()
![]()
![]()
Non dovrebbe chiuderti anche GUI1 chiudendo GUI2 perchè GUi 2 è solo un oggetto con scope locale alla action peformed di GUI1.Quindi le cose sono 2gui2 genera qualche eccezzione che fa uscire il programma oppure io non ho capito bene la situazione e allora sarebbe meglio che tu mi postassi o il codice completo o ti costruissi un esempio che si compila e si esegue correttamente che ti da lo stesso problema.Tu mi hai postato solo porzioni di codice (ad esempio mancano i costruttori) e così mi è abbastyanza difficile capire dove sta il problema.Ciao
Il centro dell'attenzione non è sempre un buon posto in cui trovarsi
Mai discutere con uno stupido, la gente potrebbe non capire la differenza. (O. W.)
GUI1
package javaapplication18;
/**
*
* @author Auron
*/
public class GUI1 extends javax.swing.JFrame {
/** Creates new form GUI1 */
public GUI1() {
initComponents();
setVisible(true);
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
jButton1 = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstan ts.EXIT_ON_CLOSE);
jButton1.setText("jButton1");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jPanel1.add(jButton1);
getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER);
pack();
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
new GUI2();
}
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JPanel jPanel1;
// End of variables declaration
GUI2
package javaapplication18;
/**
*
* @author Auron
*/
public class GUI2 extends javax.swing.JFrame {
/** Creates new form GUI2 */
public GUI2() {
initComponents();
setVisible(true);
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
jButton1 = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstan ts.EXIT_ON_CLOSE);
jButton1.setText("jButton1");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jPanel1.add(jButton1);
getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER);
pack();
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JPanel jPanel1;
// End of variables declaration
}
MAIN
package javaapplication18;
/**
*
* @author Auron
*/
public class Main {
/** Creates a new instance of Main */
public Main() {
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
new GUI1();
}
}
HELLLLLLLPPPPPPPPPPP
![]()
![]()
Devi eliminare quella riga di codice che hai scritto nella GUI2:
Questa riga di codice dice che quando chiudi GUI2 l'applicazione termina: EXIT_ON_CLOSE significa, infatti, ESCI alla chiusura.codice:setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
Modificalo, in questo modo:
Ciao.codice:setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);![]()
"Perchè spendere anche solo 5 dollari per un S.O., quando posso averne uno gratis e spendere quei 5 dollari per 5 bottiglie di birra?" [Jon "maddog" Hall]
Fatti non foste a viver come bruti, ma per seguir virtute e canoscenza
ok funziona
pensavo che exit_on_close significasse uscire localmente e non in modo globale
Grazie....
Adesso ho un alto problema:
vorrei far diventare la gui2 può complessa e renderla riutilizzabile....
Come posso fare????
I java beans sono una soluzione??
VOrrei che la gui2 una volta avviata, reperisca informazioni e li passi a gui1(che sarà costretta ad aspettare gui2....in sostanza una spece di JOptionPane)
![]()