the image I want to put in the window n appears what I do?

Asked

Viewed 18 times

-1

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;

public class Janela extends JFrame  {


    ImageIcon imagem = new ImageIcon(getClass().getResource("parado 1.jpeg"));
    JLabel label = new JLabel(imagem);
    public Janela() {

        add(label);


        JFrame jf = new JFrame();
        jf.setTitle("teste");
        jf.setSize(500,400);
        jf.setVisible(true);
        jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        jf.setLocationRelativeTo(null);
        jf.setResizable(true);
        jf.setLayout(null);
    }

}

1 answer

0

Try So:

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;

public class Janela extends JFrame {

    ImageIcon imagem = new ImageIcon(getClass().getResource("/parado 1.jpeg"));
    JLabel label = new JLabel(imagem);

    public Janela() {
        JFrame jf = new JFrame();
        jf.add(label);
        jf.setTitle("teste");
        jf.setSize(500, 400);
        jf.setVisible(true);
        jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        jf.setLocationRelativeTo(null);
        jf.setResizable(true);
        jf.setLayout(null);
    }

}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.