Amigos,
Estou com o seguinte formulário declarado:
package inicial;
import cadastros.CadastroUsuario;
import javax.swing.JOptionPane;
import javax.swing.UIManager;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
public class Principal extends javax.swing.JFrame{
/** Creates new form Principal */
public Principal() {
initComponents();
}
public void HabilitarMenu(){
jMenuItem1.setEnabled(true);
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jDesktopPane1 = new javax.swing.JDesktopPane();
jMenuBar1 = new javax.swing.JMenuBar();
jMenu1 = new javax.swing.JMenu();
jMenuItem1 = new javax.swing.JMenuItem();
jMenu2 = new javax.swing.JMenu();
jMenuItem2 = new javax.swing.JMenuItem();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jMenu1.setText("Cadastros");
jMenuItem1.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_U, 0));
jMenuItem1.setText("Cadastro de Usuários");
jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem1ActionPerformed(evt);
}
});
jMenu1.add(jMenuItem1);
jMenuBar1.add(jMenu1);
jMenu2.setText("Edit");
jMenuItem2.setText("jMenuItem2");
jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem2ActionPerformed(evt);
}
});
jMenu2.add(jMenuItem2);
jMenuBar1.add(jMenu2);
setJMenuBar(jMenuBar1);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jDesktopPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 700, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jDesktopPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 522, Short.MAX_VALUE)
);
pack();
}// </editor-fold>
private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {
//jMenuItem1.setEnabled(false);
CadastroUsuario cadastrousuario = CadastroUsuario.getInstance();
this.repaint();
jDesktopPane1.add(cadastrousuario);
cadastrousuario.setVisible(true);
jMenuItem1.setEnabled(false);
}
private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {
this.HabilitarMenu(); // TODO add your handling code here:
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
try {
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
} catch (Exception e) {
JOptionPane.showMessageDialog(null,
"Não foi possível carregar o \"Skin\" padrão. Definindo o padrão original.", "Erro",
JOptionPane.ERROR_MESSAGE);
}
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
javax.swing.JFrame frame = new Principal();
frame.setVisible(true);
}
}
);
}
// Variables declaration - do not modify
private javax.swing.JDesktopPane jDesktopPane1;
private javax.swing.JMenu jMenu1;
private javax.swing.JMenu jMenu2;
private javax.swing.JMenuBar jMenuBar1;
private javax.swing.JMenuItem jMenuItem1;
private javax.swing.JMenuItem jMenuItem2;
// End of variables declaration
}
Então este é instanciado como frame.
O que eu quero saber é o seguinte como faço para executar um método desta classe a partir de uma outra?
Então nesta classe eu tenho o método HabilitarMenu()public void HabilitarMenu(){
jMenuItem1.setEnabled(true);
}
Como eu faço para a partir de uma outra classe chamar este método e fazer o método habilitar a janela já aberta como frame?
Alguem pode me ajudar?
Att
Tiago Dantas