PAGUE 6 MESES
LEVE 12 MESES
GARANTIR DESCONTO

Fórum botão do JIternalFrame não faz nada quando é clicado #573553

06/01/2017

0

Gente, o meu professor passou uma atividade, que deve ser feita extamete dessa forma.

ter dois pacotes, um para controle e outro para visão.

na visão eu tenho a tela inicial que aparecerá uma imagem de um triangulo, que ao ser clicado abre um JInternalFrame. Ao abrir o internalFrame, tem-se nele um botao que deve ser clicado e aparcer no console "fui clicado".

porém o internal frame aparece, mas quando clico no botão não aparece nada. mesmo tratando com o actioListenet e chamando-o no método. o que pode ser?

imagem1

quando clico no botão FUI CLICADO, não aparce nada no console.

imagem2

package visao;

public class TelaInicial extends JFrame {
    private ImageIcon imgTetraedroTP;
    private JLabel lblTetraedroTP;
    private JPanel contentPane;
    private JDesktopPane desktopPane;

    public TelaInicial() {
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setBounds(100, 100, 600, 600);
        contentPane = new JPanel();
        contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
        setContentPane(contentPane);
        contentPane.setLayout(null);

        lblTetraedroTP = new JLabel("New label");
        lblTetraedroTP.setBounds(23, 35, 147, 152);

        imgTetraedroTP = new ImageIcon(getClass().getResource("/imagem/Tetraedro.png"));
        Icon icone = new ImageIcon(imgTetraedroTP.getImage().getScaledInstance
                                  (lblTetraedroTP.getWidth(), lblTetraedroTP.getHeight(), Image.SCALE_DEFAULT));
        lblTetraedroTP.setIcon(icone);
        contentPane.add(lblTetraedroTP);

        desktopPane = new JDesktopPane();
        desktopPane.setBounds(0, 0, 600, 600);
        contentPane.add(desktopPane);

        setVisible(true);

    }
}




package visao;

public class TelaInterna extends JInternalFrame {

    private JButton btnFuiClicado;
    private JPanel panel;

    public TelaInterna() {

        setBounds(100, 100, 408, 230);
        panel = new JPanel();
        panel.setLayout(null);
        setContentPane(panel);

        panel.setBounds(0, 0, 392, 200);
        panel.setLayout(null);

        btnFuiClicado = new JButton("Fui clicado??");
        btnFuiClicado.setBounds(142, 81, 119, 23);
        panel.add(btnFuiClicado);

        setVisible(true);

    }

    public JButton getBtnFuiClicado() {
        return btnFuiClicado;
    }

}


package controle;


public class ControleTelaInicial extends JFrame implements MouseListener {

    private JPanel contentPane;
    private BufferedImage img;
    private TelaInicial ti;
    private TelaInterna teIn;

    public ControleTelaInicial(TelaInicial ti) throws IOException {
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setBounds(100, 100, 450, 300);
        contentPane = new JPanel();
        contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
        contentPane.setLayout(new BorderLayout(0, 0));

        img = ImageIO.read(getClass().getResource("/imagem/Tetraedro.png"));

        this.ti = ti;
        this.ti.getLblTetraedroTP().addMouseListener(this);

        setContentPane(contentPane);
    }

    @Override
    public void mousePressed(MouseEvent e) {

        int pixel = img.getRGB(e.getPoint().x, e.getPoint().y);
        if ((pixel >> 24) == 0x00) {
            return;
        } else {
            if (e.getSource() == this.ti.getLblTetraedroTP()) {

                teIn = new TelaInterna();
                new ControleTelaInterna(teIn);
                ti.getDesktopPane().add(teIn);

            }
        }
    }

    //todos os outros métodos de mouselistener

}



package controle;


import visao.TelaInterna;

public class ControleTelaInterna extends JInternalFrame implements ActionListener {

    private TelaInterna teInt;

    public ControleTelaInterna(TelaInterna teInt) {

        setBounds(100, 100, 450, 300);
        this.teInt = new TelaInterna();

        this.teInt.getBtnFuiClicado().addActionListener(this);

        setVisible(true);
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        if (e.getSource() == teInt.getBtnFuiClicado()) {
            System.out.println("fiu clicado");
        }

    }

}


package controle;

import visao.TelaInicial;

public class principal {

    public static void main(String[] args) throws IOException {
        new ControleTelaInicial(new TelaInicial());
    }
}
Gabriela

Gabriela

Responder

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar