Prezados,
No codigo abaixo como faço para deixar o criaMostraGUI() como true quando for gerado um evento em um JMenuItem.
private void criaMostraGui() {
JFrame frame = new JFrame("Hello");
JLabel label = new JLabel("Hello, Swing World");
frame.getContentPane().add(label);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(false);
}
private void createAndShowGUI() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setJMenuBar(createMenuBar());
JScrollPane scrollPane = new JScrollPane(textArea,
JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
getContentPane().add(scrollPane);
setLocation(150, 200);
setSize(450, 260);
setVisible(true);
}
public static void main(String[] args) {
ExemploJMenu exemploJMenu = new ExemploJMenu("Quina Muita Sorte 2007");
exemploJMenu.createAndShowGUI();
exemploJMenu.criaMostraGui();
}
public void actionPerformed(ActionEvent e) {
// checar se o evento é de JMenuItem
if (e.getSource() instanceof JMenuItem) {
JMenuItem menuItem = (JMenuItem) e.getSource();
String texto = menuItem.getText();
textArea.append("=> Evento gerado para JMenuItem " + texto);
textArea.append("\n");
if ("Sair".equals(texto)) {
int opcao = JOptionPane.showConfirmDialog(this,
"Deseja realmente sair?", "Sair",
JOptionPane.YES_NO_OPTION);
if (opcao == JOptionPane.OK_OPTION) {
System.exit(0);
}
}
}
}