Problema para exibir janelas internas no net beans [Resolvido]

4 respostas
T

Ola pessual boa tarde, estou fazendo a interface do trabalho de conclusão de curso e estou com um seio problema, desenvolv a tela principal no net beans e criei outras classes por exemplo cadastro de acervo, cadastro de usuarios e assim por diante e na ação dos botões quando clico eles chamam essas classas exibindo seus forms respectivos, porem eles sobrepõem a tela principal, ficando ruim o entendimento e a disposição dos mesmos, gostaria que aparecesse esses forms preenchendo a extensão da tela principal e quando terminasse de cadastrar ou utilizar voltasse para a tela principal, não faço nem idei de como fazer isso, vi alguns tópicos sobre jInternal frame mas não sei como adaptar isso no meu projeto, vou anexalo abaixo, se alguem puder me dar uma força serei imensamente grato.

// Tela_Principal.java

import Cadastro.Cad_Acervo;
import Cadastro.Alunos;
import Cadastro.Funcionarios;
public class Tela_Principal extends javax.swing.JFrame {
    Data mostra_data;
    /** Creates new form Tela_Principal */
    public Tela_Principal() {
        initComponents();
        
        mostra_data = new Data();
        mostra_data.le_data();
        label_data.setText("Hoje é " +mostra_data.dia_semana + ", " +mostra_data.dia + " de "+ mostra_data.mes + " de "+ mostra_data.ano);
        
        mostra_data.le_hora();
        label_hora.setText(mostra_data.hora);
        
        timer1.start();
        
    }
    
   
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">                          
    private void initComponents() {
        timer1 = new org.netbeans.examples.lib.timerbean.Timer();
        jPanel1 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        label_data = new javax.swing.JLabel();
        label_hora = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jMenuBar1 = new javax.swing.JMenuBar();
        menu_cadastros = new javax.swing.JMenu();
        menu_usuários = new javax.swing.JMenu();
        menuitem_alunos = new javax.swing.JMenuItem();
        menuitem_funcionários = new javax.swing.JMenuItem();
        menuitem_visitantes = new javax.swing.JMenuItem();
        jSeparator1 = new javax.swing.JSeparator();
        menuitem_acervo = new javax.swing.JMenuItem();
        menu_uilitarios = new javax.swing.JMenu();
        menuitem_relatorios = new javax.swing.JMenuItem();
        menuitem_ajuda = new javax.swing.JMenuItem();
        menu_sair = new javax.swing.JMenu();

        timer1.addTimerListener(new org.netbeans.examples.lib.timerbean.TimerListener() {
            public void onTime(java.awt.event.ActionEvent evt) {
                timer1OnTime(evt);
            }
        });

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Biblioteca Drummond");
        setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        jPanel1.setBackground(new java.awt.Color(229, 244, 244));
        jPanel2.setBackground(new java.awt.Color(0, 0, 153));
        jButton1.setIcon(new javax.swing.ImageIcon("C:\\Users\\Tiago\\Biblioteca_Drummond\\Imagens\\users.png"));
        jButton1.setText("Acesso Usu\u00e1rios");

        jButton2.setIcon(new javax.swing.ImageIcon("C:\\Users\\Tiago\\Biblioteca_Drummond\\Imagens\\worker.png"));
        jButton2.setText("Acesso Funcion\u00e1rios");

        jButton3.setIcon(new javax.swing.ImageIcon("C:\\Users\\Tiago\\Biblioteca_Drummond\\Imagens\\pesquisar.png"));
        jButton3.setText("Consultar Acervo");

        jButton4.setIcon(new javax.swing.ImageIcon("C:\\Users\\Tiago\\Biblioteca_Drummond\\Imagens\\reservas.png"));
        jButton4.setText("Reservas");
        jButton4.setToolTipText("");

        jButton5.setIcon(new javax.swing.ImageIcon("C:\\Users\\Tiago\\Biblioteca_Drummond\\Imagens\\atualizar.png"));
        jButton5.setText("Entrada e Sa\u00edda");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButton3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButton4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButton5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jButton1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton4)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton5)
                .addContainerGap(12, Short.MAX_VALUE))
        );

        jLabel1.setIcon(new javax.swing.ImageIcon("C:\\Users\\Tiago\\Biblioteca_Drummond\\Imagens\\livros.gif"));

        label_data.setText("Data: ");

        label_hora.setText("Hora:");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(40, 40, 40)
                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 453, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(6, 6, 6)
                        .addComponent(label_hora))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(348, 348, 348)
                        .addComponent(label_data)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(label_data)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(37, 37, 37)
                        .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(412, Short.MAX_VALUE)
                .addComponent(label_hora))
        );

        jLabel2.setIcon(new javax.swing.ImageIcon("C:\\Users\\Tiago\\Biblioteca_Drummond\\Imagens\\Biblioteca.jpg"));

        menu_cadastros.setMnemonic('c');
        menu_cadastros.setText("Cadastros");
        menu_usuários.setIcon(new javax.swing.ImageIcon("C:\\Users\\Tiago\\Biblioteca_Drummond\\Imagens\\users.png"));
        menu_usuários.setText("Usu\u00e1rios");
        menu_usuários.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menu_usuáriosActionPerformed(evt);
            }
        });

        menuitem_alunos.setText("Alunos");
        menuitem_alunos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuitem_alunosActionPerformed(evt);
            }
        });

        menu_usuários.add(menuitem_alunos);

        menuitem_funcionários.setText("Funcion\u00e1rios");
        menuitem_funcionários.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuitem_funcionáriosActionPerformed(evt);
            }
        });

        menu_usuários.add(menuitem_funcionários);

        menuitem_visitantes.setText("Visitantes");
        menu_usuários.add(menuitem_visitantes);

        menu_cadastros.add(menu_usuários);

        menu_cadastros.add(jSeparator1);

        menuitem_acervo.setIcon(new javax.swing.ImageIcon("C:\\Users\\Tiago\\Biblioteca_Drummond\\Imagens\\livros.png"));
        menuitem_acervo.setText("Acervo");
        menuitem_acervo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuitem_acervoActionPerformed(evt);
            }
        });

        menu_cadastros.add(menuitem_acervo);

        jMenuBar1.add(menu_cadastros);

        menu_uilitarios.setMnemonic('u');
        menu_uilitarios.setText("Utilit\u00e1rios");
        menuitem_relatorios.setIcon(new javax.swing.ImageIcon("C:\\Users\\Tiago\\Acervo\\Imagens\\relatório.png"));
        menuitem_relatorios.setText("Relat\u00f3rios");
        menuitem_relatorios.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuitem_relatoriosActionPerformed(evt);
            }
        });

        menu_uilitarios.add(menuitem_relatorios);

        menuitem_ajuda.setIcon(new javax.swing.ImageIcon("C:\\Users\\Tiago\\Acervo\\Imagens\\help.png"));
        menuitem_ajuda.setText("Ajuda");
        menu_uilitarios.add(menuitem_ajuda);

        jMenuBar1.add(menu_uilitarios);

        menu_sair.setMnemonic('s');
        menu_sair.setText("Sair");
        menu_sair.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                menu_sairMouseClicked(evt);
            }
        });

        jMenuBar1.add(menu_sair);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 741, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addGap(10, 10, 10)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        pack();
    }// </editor-fold>                        
    
    private void menuitem_acervoActionPerformed(java.awt.event.ActionEvent evt) {                                                
        new Cad_Acervo().show();
    }                                               
    
    private void menuitem_funcionáriosActionPerformed(java.awt.event.ActionEvent evt) {                                                      
        new Funcionarios().show();
    }                                                     
    
    private void menuitem_alunosActionPerformed(java.awt.event.ActionEvent evt) {                                                
        new Alunos().show();
    }                                               
    
    private void menu_usuáriosActionPerformed(java.awt.event.ActionEvent evt) {                                              
        
        
    }                                             
    
    private void menu_sairMouseClicked(java.awt.event.MouseEvent evt) {                                       
        System.exit(0);
    }                                      
    
    private void timer1OnTime(java.awt.event.ActionEvent evt) {                              
        mostra_data.le_hora();
        label_hora.setText(mostra_data.hora);
    }                             
    
    private void menuitem_relatoriosActionPerformed(java.awt.event.ActionEvent evt) {                                                    

    }                                                   
    
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Tela_Principal().setVisible(true);
            }
        });
    }
    
    // Variables declaration - do not modify                     
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JLabel label_data;
    private javax.swing.JLabel label_hora;
    private javax.swing.JMenu menu_cadastros;
    private javax.swing.JMenu menu_sair;
    private javax.swing.JMenu menu_uilitarios;
    private javax.swing.JMenu menu_usuários;
    private javax.swing.JMenuItem menuitem_acervo;
    private javax.swing.JMenuItem menuitem_ajuda;
    private javax.swing.JMenuItem menuitem_alunos;
    private javax.swing.JMenuItem menuitem_funcionários;
    private javax.swing.JMenuItem menuitem_relatorios;
    private javax.swing.JMenuItem menuitem_visitantes;
    private org.netbeans.examples.lib.timerbean.Timer timer1;
    // End of variables declaration                   
    
}

4 Respostas

S

Olá amigo

veja este exemplo de um frame principal de sistema em MDI:

import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.beans.PropertyVetoException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.UIManager.LookAndFeelInfo;
import javax.swing.AbstractAction;
import javax.swing.JFrame;

public class FramePrincipal extends JFrame implements ActionListener, KeyListener {

    private MDIDesktopPane desktop = new MDIDesktopPane();
//    private JMenuBar menuBar = new JMenuBar();
    private JMenu fileMenu = new JMenu("File");
    private JMenuItem newMenu = new JMenuItem("New");
    private JScrollPane scrollPane = new JScrollPane();
    public JToolBar toolBar;
    private AbstractAction actionNew;
    private AbstractAction actionOpen;
    private AbstractAction actionSave;
    private AbstractAction actionExit;
    private AbstractAction actionClientes;
    private AbstractAction actionOrdemServico;
    private AbstractAction actionMarcas;
    private AbstractAction actionTipoequipamento;
    public int getHeight;
    public Boolean telaClientes = false;
    public int larguraBotao = 100;
    public int alturaBotao = 50;
    public static final String FontNames[] = {"Serif", "SansSerif", "Courier"};
    protected Font fonts[];
    protected JMenuItem[] fontMenus;
    protected JCheckBoxMenuItem boldMenu = new JCheckBoxMenuItem("Bold");
    protected JCheckBoxMenuItem italicMenu = new JCheckBoxMenuItem("Italic");
    ImageIcon sairButtonIcon = createImageIcon("resources/exit24.png");
    ImageIcon clienteButtonIcon = createImageIcon("resources/kontact_contacts.png");
    ImageIcon ordemservicoButtonIcon = createImageIcon("resources/systemsettings.png");
    ImageIcon sobreButtonIcon = createImageIcon("resources/stockhelp.png");
    static FrameClientes frameClientes;
    static FrameMarcas frameMarcas;
    static FrameOrdemServico frameOrdemServico;
    public JLabel LabelDataHora;
    public JLabel LabelUsuario;

    public FramePrincipal() {
//        menuBar.add(fileMenu);
        super("SAT - Sistema de Assistência Técnica V. 1.0");

        javax.swing.UIManager.put("OptionPane.yesButtonText", "Sim");
        javax.swing.UIManager.put("OptionPane.noButtonText", "Não");
        javax.swing.UIManager.put("OptionPane.okButtonText", "Ok");
        javax.swing.UIManager.put("OptionPane.cancelButtonText", "Cancelar");

        fonts = new Font[FontNames.length];
        for (int i = 0; i < FontNames.length; i++) {
            fonts[i] = new Font(FontNames[i], Font.PLAIN, 12);
        }

        int inset = 50;
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        getHeight = screenSize.height;
        setBounds(inset, inset,
                screenSize.width - inset * 2,
                screenSize.height - inset * 2);
        JMenuBar menuBar = createMenuBar();
        menuBar.add(new WindowMenu(desktop));
//        fileMenu.add(newMenu);
        setJMenuBar(menuBar);
        //setTitle("MDI Test");
        scrollPane.getViewport().add(desktop);
        getContentPane().setLayout(new BorderLayout());
        getContentPane().add(scrollPane, BorderLayout.CENTER);
        getContentPane().add(toolBar, BorderLayout.NORTH);


        JLabel LabelUsuario = new JLabel();
        JLabel LabelDataHora = new JLabel();

        //        tfIdCliente.setBounds(10,25,30,20);
        //       tfNomeCliente.setBounds(80,25,400,20);


        LabelUsuario.setText("Usuário:                Data: ");
        LabelUsuario.setBounds(110, 01, 10, 30);
        LabelDataHora.setText("Data: ");
        LabelDataHora.setBounds(200, 01, 280, 30);

        StatusBar statusBar = new StatusBar();
        statusBar.add(LabelUsuario);
        getContentPane().add(statusBar, BorderLayout.SOUTH);


        getContentPane().add(desktop);

        addWindowListener(new WindowAdapter() {

            public void windowClosing(WindowEvent e) {
                quit();
            }
        });
        newMenu.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent ae) {
                desktop.add(new TextFrame());
            }
        });
        desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
        FramePrincipal1.setDefaultLookAndFeelDecorated(true);
        LookAndFeelInfo[] lafs = (LookAndFeelInfo[]) UIManager.getInstalledLookAndFeels();

        desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
        this.setVisible(true);
        this.setExtendedState(JFrame.MAXIMIZED_BOTH);

        listenKeyboard(getComponents());

    }

    public static void main(String[] args) throws InterruptedException, ClassNotFoundException {
        createAndShowGUI();

    }

    public static ImageIcon createImageIcon(String path) {
        java.net.URL imgURL = FrameModelo.class.getResource(path);
        if (imgURL != null) {
            return new ImageIcon(imgURL);
        } else {
            System.err.println("Couldn't find file: " + path);
            return null;
        }
    }

    protected JMenuBar createMenuBar() {
        final JMenuBar menuBar = new JMenuBar();

        JMenu assistencia = new JMenu("Assistência");
        assistencia.setMnemonic('A');

        //ImageIcon iconNew = new ImageIcon(clienteButtonIcon);

//        JMenu menu = new JMenu("Assistência");
//        menu.setMnemonic(KeyEvent.VK_A);
//        menu.setMnemonic('A');

        actionClientes = new AbstractAction("Clientes ", clienteButtonIcon) {

            public void actionPerformed(ActionEvent e) {
                acaoBotoes(e);
            }
        };

//        JMenuItem item = assistencia.add(actionClientes);
        JMenuItem item = new JMenuItem("Clientes");
        item.setMnemonic(KeyEvent.VK_C);
        item.setAccelerator(KeyStroke.getKeyStroke(
                KeyEvent.VK_C, ActionEvent.ALT_MASK));
        item.setActionCommand("clientes");
        item.setIcon(clienteButtonIcon);
        item.addActionListener(this);
        assistencia.add(item);

        actionOrdemServico = new AbstractAction("Ordem de Serviço ", ordemservicoButtonIcon) {

            public void actionPerformed(ActionEvent e) {
                acaoBotoes(e);
            }
        };

//        item = assistencia.add(actionOrdemServico);
        item = new JMenuItem("Ordem Serviço");
        item.setMnemonic(KeyEvent.VK_O);
        item.setAccelerator(KeyStroke.getKeyStroke(
                KeyEvent.VK_O, ActionEvent.ALT_MASK));
        item.setActionCommand("ordemservico");
        item.setIcon(ordemservicoButtonIcon);
        item.addActionListener(this);
        assistencia.add(item);

        actionMarcas = new AbstractAction("Marcas ", clienteButtonIcon) {

            public void actionPerformed(ActionEvent e) {
                acaoBotoes(e);
            }
        };

//        item = assistencia.add(actionMarcas);
        item = new JMenuItem("Marcas");
        item.setActionCommand("marcas");
        item.setMnemonic(KeyEvent.VK_M);
        item.setAccelerator(KeyStroke.getKeyStroke(
                KeyEvent.VK_M, ActionEvent.ALT_MASK));
        item.setIcon(ordemservicoButtonIcon);
        item.addActionListener(this);
        assistencia.add(item);

        assistencia.addSeparator();

        actionExit = new AbstractAction("Sair", sairButtonIcon) {

            public void actionPerformed(ActionEvent e) {
                acaoBotoes(e);
            }
        };

//        item = assistencia.add(actionExit);
        item = new JMenuItem("Sair");
        item.setActionCommand("sair");
        item.setMnemonic(KeyEvent.VK_F4);
        item.setAccelerator(KeyStroke.getKeyStroke(
                KeyEvent.VK_F4, ActionEvent.ALT_MASK));
        item.setActionCommand("quit");
        item.setIcon(sairButtonIcon);
        item.addActionListener(this);

        item.setMnemonic('S');
        assistencia.add(item);

        menuBar.add(assistencia);

        toolBar = new JToolBar();

        JButton btn1 = toolBar.add(actionClientes);
        btn1.setToolTipText("Cadastro de Clientes");
        btn1.setActionCommand("clientes");
        btn1.setIcon(clienteButtonIcon);
        btn1.setText("F2-Clientes");
        btn1.setPreferredSize(new Dimension(50, 50));
        btn1.setMaximumSize(new Dimension(larguraBotao, alturaBotao));

        JButton btn2 = toolBar.add(actionOrdemServico);
        btn2.setToolTipText("Ordem de Serviço");
        btn2.setIcon(ordemservicoButtonIcon);
        btn2.setActionCommand("ordemservico");
        btn2.setText("F3-Ordem   ");
        btn2.setPreferredSize(new Dimension(50, 50));
        btn2.setMaximumSize(new Dimension(larguraBotao, alturaBotao));

        JButton btn3 = toolBar.add(actionMarcas);
        btn3.setToolTipText("Cadastro de Marcas");
        btn3.setIcon(ordemservicoButtonIcon);
        btn3.setActionCommand("marcas");
        btn3.setText("F4-Marcas  ");
        btn3.setPreferredSize(new Dimension(50, 50));
        btn3.setMaximumSize(new Dimension(larguraBotao, alturaBotao));

        getContentPane().add(toolBar, BorderLayout.NORTH);


        ActionListener fontListener = new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                //    updateMonitor();
            }
        };

        JMenu mFont = new JMenu("Font");
        mFont.setMnemonic('o');

        ButtonGroup group = new ButtonGroup();
        fontMenus = new JMenuItem[FontNames.length];
        for (int k = 0; k < FontNames.length; k++) {
            int m = k + 1;
            fontMenus[k] = new JRadioButtonMenuItem(m + " " + FontNames[k]);
            boolean selected = (k == 0);
            fontMenus[k].setSelected(selected);
            fontMenus[k].setMnemonic('1' + k);
            fontMenus[k].setFont(fonts[k]);
            fontMenus[k].addActionListener(fontListener);
            group.add(fontMenus[k]);
            mFont.add(fontMenus[k]);
        }

        mFont.addSeparator();

        boldMenu.setMnemonic('b');
        Font fn = fonts[1].deriveFont(Font.BOLD);
        boldMenu.setFont(fn);
        boldMenu.setSelected(false);
        boldMenu.addActionListener(fontListener);
        mFont.add(boldMenu);

        italicMenu.setMnemonic('i');
        fn = fonts[1].deriveFont(Font.ITALIC);
        italicMenu.setFont(fn);
        italicMenu.setSelected(false);
        italicMenu.addActionListener(fontListener);
        mFont.add(italicMenu);

        menuBar.add(mFont);

        getContentPane().add(toolBar, BorderLayout.NORTH);

        return menuBar;
    }


    public void acaoBotoes(ActionEvent e) {
        if ("clientes".equals(e.getActionCommand())) { //new
            try {
                //new
                createFrameClientes();
            } catch (Exception ex) {
                Logger.getLogger(FramePrincipal_OK.class.getName()).log(Level.SEVERE, null, ex);
            }
        }

        if ("marcas".equals(e.getActionCommand())) { //new
            try {
                //new
                createFrameMarcas();
            } catch (Exception ex) {
                Logger.getLogger(FramePrincipal_OK.class.getName()).log(Level.SEVERE, null, ex);
            }

        }

        if ("ordemservico".equals(e.getActionCommand())) { //new
            try {
                //new
                createFrameOrdemServico();
            } catch (Exception ex) {
                Logger.getLogger(FramePrincipal_OK.class.getName()).log(Level.SEVERE, null, ex);
            }

        }
        if ("sair".equals(e.getActionCommand())) { //new
            int i = JOptionPane.showOptionDialog(null, "Tem certeza que deseja sair?", "Sair do Sistema", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, JOptionPane.NO_OPTION);
            if (i == JOptionPane.YES_OPTION) {
                quit();
            }
        }

    }

    protected void createFrameClientes() throws PropertyVetoException, Exception {

        if (frameClientes == null) {
            frameClientes = new FrameClientes();
            frameClientes.setVisible(true); //necessary as of 1.3
            desktop.add(frameClientes);
            frameClientes.pack();
            desktop.getDesktopManager().maximizeFrame(frameClientes);
        } else {
            frameClientes.setVisible(true);
        }
        try {
            frameClientes.setSelected(true);
        } catch (java.beans.PropertyVetoException e) {
        }
    }

    protected void createFrameOrdemServico() throws PropertyVetoException, Exception {

        if (frameOrdemServico == null) {
            frameOrdemServico = new FrameOrdemServico();
            frameOrdemServico.setVisible(true); //necessary as of 1.3
            desktop.add(frameOrdemServico);
            frameOrdemServico.pack();
            desktop.getDesktopManager().maximizeFrame(frameOrdemServico);
        } else {
            frameOrdemServico.setVisible(true);
        }
        try {
            frameOrdemServico.setSelected(true);
        } catch (java.beans.PropertyVetoException e) {
        }
    }

    protected void createFrameMarcas() throws PropertyVetoException, Exception {

        if (frameMarcas == null) {
            frameMarcas = new FrameMarcas();
            frameMarcas.setVisible(true);
            desktop.add(frameMarcas);
            frameMarcas.pack();
            desktop.getDesktopManager().maximizeFrame(frameMarcas);
        } else {
            frameMarcas.setVisible(true); //necessary as of 1.3
        }
        try {
            frameMarcas.setSelected(true);
        } catch (java.beans.PropertyVetoException e) {
        }
    }

    protected void quit() {
        int i = JOptionPane.showOptionDialog(null, "Tem certeza que deseja sair?", "Sair do Sistema", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, JOptionPane.NO_OPTION);
        if (i == JOptionPane.YES_OPTION) {
            System.exit(0);
        }
    }

    private static void createAndShowGUI() throws InterruptedException, ClassNotFoundException {
        //Make sure we have nice window decorations.

        JFrame.setDefaultLookAndFeelDecorated(true);

        //Create and set up the window.
        FramePrincipal farameprincipal = new FramePrincipal();
        farameprincipal.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        farameprincipal.setExtendedState(MAXIMIZED_BOTH);
        //Display the window.
        farameprincipal.setVisible(true);
    }

    private void implementarTeclado() {
        for (int i = 0; i < getContentPane().getComponentCount(); i++) {
            getContentPane().getComponent(i).addKeyListener(this);
        }
    }

    public void F1() {
        System.out.println("Eu fui chamado! VIVA!!!!!!!!");
        JOptionPane.showMessageDialog(null, "Olha o PROMPT!");
    }

    public void listenKeyboard(Component[] cs) {
        for (Component c : cs) {
            c.addKeyListener(this);
        }
    }

    public void keyPressed(KeyEvent e) {
        if (e.getKeyCode() == KeyEvent.VK_F1) {
            F1();
        }
    }

    public void keyReleased(KeyEvent e) {
    }

    public void keyTyped(KeyEvent e) {
    }

    public void actionPerformed(ActionEvent e) {
        if ("clientes".equals(e.getActionCommand())) { //new
            try {
                //new
                createFrameClientes();
            } catch (Exception ex) {
                Logger.getLogger(FramePrincipal_OK.class.getName()).log(Level.SEVERE, null, ex);
            }
        }

        if ("marcas".equals(e.getActionCommand())) { //new
            try {
                //new
                createFrameMarcas();
            } catch (Exception ex) {
                Logger.getLogger(FramePrincipal_OK.class.getName()).log(Level.SEVERE, null, ex);
            }

        }

        if ("ordemservico".equals(e.getActionCommand())) { //new
            try {
                //new
                createFrameOrdemServico();
            } catch (Exception ex) {
                Logger.getLogger(FramePrincipal_OK.class.getName()).log(Level.SEVERE, null, ex);
            }

        }
        if ("sair".equals(e.getActionCommand())) { //new
            int i = JOptionPane.showOptionDialog(null, "Tem certeza que deseja sair?", "Sair do Sistema", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, JOptionPane.NO_OPTION);
            if (i == JOptionPane.YES_OPTION) {
                quit();
            }
        }

//        throw new UnsupportedOperationException("Not supported yet.");
    }
}

espero que lhe ajude

Silvio Guedes

ambuzr

cara sofri um pouco tambem com isso oh, apanhei e apanhei e encontrei uma forma facil de fazer

c tem q enteder a logica dos swings
Inicie um Form de um jFrame que sera o principal, adicione dentro do jFrame um jdesktop e copile(F9).
Crie um novo forme de JinternalFrame nao dentro frame principal e sim seprado em outra classe
desenhe todo seu jinternalframe metodos e tal em seguida copile F9 o mesmo, nao pode haver erro na classe ok.

agora volte o jFrame Principal e arraste literalmente a classe pra dentro do desenho(isso mesmo ce vai clicar na classe do jinternalframe e segura e arrastar pra dentro da do desenho como c faz com um botao, um jtextfild etcs) onde ta o jdesktopane e segure ate q apareca o desenho entao vc solta , voce tera adicionado no jframe principal o jinternal frame da outras classe, toda alteracao q vc fizer no jinternalframe da ourta classe vai tambem ser feita nessa afinal vc criou um objeto do mesmo.

qualquer duvidas tamo ai vlw

S

Olá amigo

vc deve estar usando a forma visual arrastar e soltar, este fonte acima é feito na mão mesmo. Comecei a usar o netbeans da mesma forma que vc, então resolvi mudar.

este exemplo acima funciona sim até uns dois meses atrás eu usava.

agora se vc que desenvolver sistemas usando MDI então confiram o OpenSwing, já vem com um monte de coisa pronta inclusive MDI, boa sorte.

Para aplicações desktop eu uso OpenSwing.

http://oswing.sourceforge.net/

Um abraço

Silvio Guedes

T

Sem comentários, nem acredito que consegui realizar essa parte do TGI pessual, vocês são d++++++++ mesmo, muito obrigado pela ajuda espero um dia poder ajudar também abraços

Criado 21 de outubro de 2009
Ultima resposta 25 de out. de 2009
Respostas 4
Participantes 3