Hola de nuevo, tengo el siguiente codigo que se supone que al presionar el boton de la clase Menu, me suspende el hilo donde se ejecuta el objeto de la clase Graficos, pero se me congela toda la interfaz grafica del Menu tambien; he usado wait y notify pero algo estoy haciendo mal y no se que es
Clase Menu:
Código Java:
Ver originalpackage invoke;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.SwingUtilities;
Graficos obj;
initComponents();
obj=new Graficos();
obj.setVisible(true);
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jButton1
= new javax.
swing.
JButton();
jButton1.setText("jButton1");
public void actionPerformed
(java.
awt.
event.
ActionEvent evt
) { jButton1ActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(158, 158, 158)
.addComponent(jButton1)
.
addContainerGap(165,
Short.
MAX_VALUE)) );
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(57, 57, 57)
.addComponent(jButton1)
.
addContainerGap(41,
Short.
MAX_VALUE)) );
pack();
}// </editor-fold>
private void jButton1ActionPerformed
(java.
awt.
event.
ActionEvent evt
) { public void run() {
synchronized(obj){
try {
if(1==obj.pausar(obj)){
notify();
}
Logger.
getLogger(Menu.
class.
getName()).
log(Level.
SEVERE,
null, ex
); }
}
};
};
//new Thread(actualizar).start();
}
/**
* @param args the command line arguments
*/
public static void main
(String args
[]) { /* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
if ("Nimbus".equals(info.getName())) {
javax.
swing.
UIManager.
setLookAndFeel(info.
getClassName()); break;
}
}
java.
util.
logging.
Logger.
getLogger(Menu.
class.
getName()).
log(java.
util.
logging.
Level.
SEVERE,
null, ex
); java.
util.
logging.
Logger.
getLogger(Menu.
class.
getName()).
log(java.
util.
logging.
Level.
SEVERE,
null, ex
); java.
util.
logging.
Logger.
getLogger(Menu.
class.
getName()).
log(java.
util.
logging.
Level.
SEVERE,
null, ex
); java.
util.
logging.
Logger.
getLogger(Menu.
class.
getName()).
log(java.
util.
logging.
Level.
SEVERE,
null, ex
); }
//</editor-fold>
/* Create and display the form */
public void run() {
new Menu().
setVisible(true); }
});
}
// Variables declaration - do not modify
private javax.
swing.
JButton jButton1
; // End of variables declaration
}
Clase Graficos:
Código Java:
Ver originalpackage invoke;
public Graficos() {
initComponents();
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jButton1
= new javax.
swing.
JButton(); jButton2
= new javax.
swing.
JButton();
jButton1.setText("jButton1");
jButton2.setText("jButton2");
jTextArea1.setColumns(20);
jTextArea1.setRows(5);
jScrollPane1.setViewportView(jTextArea1);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(102, 102, 102)
.addComponent(jButton1)
.addGap(63, 63, 63)
.addComponent(jButton2))
.addGroup(layout.createSequentialGroup()
.addGap(114, 114, 114)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
.
addContainerGap(89,
Short.
MAX_VALUE)) );
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(51, 51, 51)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton1)
.addComponent(jButton2))
.addGap(31, 31, 31)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.
addContainerGap(99,
Short.
MAX_VALUE)) );
pack();
}// </editor-fold>
/**
* @param args the command line arguments
*/
wait(10000);
/*synchronized(obj){
obj.wait(10000);
}*/
return(1);
}
public static void main
(String args
[]) { /* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
if ("Nimbus".equals(info.getName())) {
javax.
swing.
UIManager.
setLookAndFeel(info.
getClassName()); break;
}
}
java.util.logging.Logger.getLogger(Graficos.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
java.util.logging.Logger.getLogger(Graficos.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
java.util.logging.Logger.getLogger(Graficos.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
java.util.logging.Logger.getLogger(Graficos.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
public void run() {
new Graficos().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.
swing.
JButton jButton1
; private javax.
swing.
JButton jButton2
; // End of variables declaration
@Override
public void run() {
}
}
Gracias por su atencion.