Netbeans - dúvidas - código [RESOLVIDO]

5 respostas
Rooney

[color=blue]Estou com um problema com esse código, ele ta sendo feito no netbeans e quando colocar para rodar o programa ele só aparece um frame cinza.

Alguém me ajuda por favor.

Se quiser me add no msn pra trocar idéias:[/color] [color=red][email removido][/color]

package AprendaBrincando;

import java.awt.Event;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * JFAb.java
 *
 * Created on 01/12/2009, 20:25:08
 */

/**
 *
 * @author Rony
 */
public class JFAb extends javax.swing.JFrame {

    /** Creates new form JFAb */
    public JFAb() {

        initComponents();
    }

    /** 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.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

        jLayeredPane1 = new javax.swing.JLayeredPane();
        BToPrograma = new javax.swing.JLabel();
        BT_somar = new javax.swing.JLabel();
        BT_subtrair = new javax.swing.JLabel();
        BT_multiplicar = new javax.swing.JLabel();
        BT_dividir = new javax.swing.JLabel();
        BT_desenvolvedores = new javax.swing.JLabel();
        criancas = new javax.swing.JLabel();
        ApreBrin = new javax.swing.JLabel();
        fundo = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setBackground(new java.awt.Color(255, 255, 255));
        setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        setResizable(false);

        jLayeredPane1.setBackground(new java.awt.Color(255, 255, 255));
        jLayeredPane1.setForeground(new java.awt.Color(255, 255, 255));
        jLayeredPane1.setForeground(new java.awt.Color(255, 255, 255));

        BToPrograma.setBackground(new java.awt.Color(255, 255, 255));
        BToPrograma.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/botoes/oPrograma/oPrograma1.png"))); // NOI18N
        BToPrograma.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                BToProgramaMouseClicked(evt);
            }
        });
        BToPrograma.setBounds(30, 50, 200, 50);
        jLayeredPane1.add(BToPrograma, javax.swing.JLayeredPane.DEFAULT_LAYER);

        BT_somar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/botoes/somar/bt1_somar.png"))); // NOI18N
        BT_somar.setBounds(30, 100, 200, 60);
        jLayeredPane1.add(BT_somar, javax.swing.JLayeredPane.DEFAULT_LAYER);

        BT_subtrair.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/botoes/subtrair/bt1_subtrair.png"))); // NOI18N
        BT_subtrair.setBounds(30, 160, 200, 50);
        jLayeredPane1.add(BT_subtrair, javax.swing.JLayeredPane.DEFAULT_LAYER);

        BT_multiplicar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/botoes/multiplicar/bt1_multiplicar.png"))); // NOI18N
        BT_multiplicar.setBounds(30, 210, 200, 60);
        jLayeredPane1.add(BT_multiplicar, javax.swing.JLayeredPane.DEFAULT_LAYER);

        BT_dividir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/botoes/dividir/bt1_dividir.png"))); // NOI18N
        BT_dividir.setBounds(30, 260, 200, 70);
        jLayeredPane1.add(BT_dividir, javax.swing.JLayeredPane.DEFAULT_LAYER);

        BT_desenvolvedores.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/botoes/desenvolvedores/desenvolvedores_1.png"))); // NOI18N
        BT_desenvolvedores.setBounds(30, 320, 200, 60);
        jLayeredPane1.add(BT_desenvolvedores, javax.swing.JLayeredPane.DEFAULT_LAYER);

        criancas.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/picture/crianca_1.png"))); // NOI18N
        criancas.setBounds(230, 50, 270, 320);
        jLayeredPane1.add(criancas, javax.swing.JLayeredPane.DEFAULT_LAYER);

        ApreBrin.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/picture/logo.png"))); // NOI18N
        ApreBrin.setBounds(260, 10, 270, 120);
        jLayeredPane1.add(ApreBrin, javax.swing.JLayeredPane.DEFAULT_LAYER);

        fundo.setBackground(new java.awt.Color(255, 255, 255));
        fundo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/picture/fundo_1.png"))); // NOI18N
        fundo.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        fundo.setBounds(0, -20, 550, 440);
        jLayeredPane1.add(fundo, javax.swing.JLayeredPane.DEFAULT_LAYER);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jLayeredPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 549, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jLayeredPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 402, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>

    private void BToProgramaMouseClicked(java.awt.event.MouseEvent evt) {
        // TODO add your handling code here:
        BToPrograma = new javax.swing.JLabel();

        BToPrograma.setIcon(new javax.swing.ImageIcon(getClass().getResource("src/imagens/botoes/oPrograma/oPrograma1.png"))); // NOI18N
        BToPrograma.addMouseListener(new java.awt.event.MouseAdapter() {

            public void MouseClicked(java.awt.event.MouseEvent evt) {

                BToPrograma.setIcon(new javax.swing.ImageIcon(getClass().getResource("src/imagens/botoes/oPrograma/oPrograma2.png"))); // NOVO ICONE QUANDO SELECIONADO
            }
        });
        BToPrograma.setBounds(30, 50, 200, 50);
        jLayeredPane1.add(BToPrograma, javax.swing.JLayeredPane.DEFAULT_LAYER);
}

    /**
    * @param args the command line arguments
    */

    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new JFAb().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify
    private javax.swing.JLabel ApreBrin;
    private javax.swing.JLabel BT_desenvolvedores;
    private javax.swing.JLabel BT_dividir;
    private javax.swing.JLabel BT_multiplicar;
    private javax.swing.JLabel BT_somar;
    private javax.swing.JLabel BT_subtrair;
    private javax.swing.JLabel BToPrograma;
    private javax.swing.JLabel criancas;
    private javax.swing.JLabel fundo;
    private javax.swing.JLayeredPane jLayeredPane1;
    // End of variables declaration

}

5 Respostas

ViniGodoy

Por favor, edite seu tópico e ponha seu código nas tags code:

Seu código aqui

Senão vai ser difícil de ler.

UMC

essas imagens estao com o caminho certo?
pq vc nao coloca o caminho completo Ex:C:/… a nivel de teste.
vlw
abs

UMC

cara e o seguinte acabo de copia sua classe e executar deu logico pq nao tenho suas imagens!!!
mais eu comentei todas elas e tive o resultado do seu erro!!
entao acredito q seja esse o erro coloque o caminho completo das imagens ou entao coloque as em um Package e set o caminho!
vlw
abs

ViniGodoy

Já verificou o que o colega pediu?

Geralmente o getResource não exige que você coloque /src

Tente tirar o /src do início do seu caminho para ver se dá certo.

Rooney

Criei um novo pacote e refiz com as mesmas imagens e mesmo código e deu certo.

Porém dessa vez fui executando toda vez que add novas coisas.

Vlw

:-o

Criado 8 de dezembro de 2009
Ultima resposta 10 de dez. de 2009
Respostas 5
Participantes 3