Java Swing: não é possível carregar a imagem usando getResource
Estou tentando isolar onde poderia estar o problema ao tentar adicionar uma imagem ao diretório de classes. (Isso é feito quando exporto como JAR executável, a imagem é incluída no pacote).
Então, eu tenho o arquivo strawberry.jpg em 'C: \ Users \ sean \ workspace \ myApps \ src \ testing' Você poderia informar o que estou perdendo? Obrigado!
package testing;
import java.awt.*;
import javax.swing.*;
public class IconTest {
public static void main(String[] arguments) {
JFrame frame1 = new JFrame();
frame1.setTitle("Frame1");
frame1.setSize(500, 500);
frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
FlowLayout flo = new FlowLayout();
frame1.setLayout(flo);
JLabel label1 = new JLabel(new ImageIcon(
IconTest.class.getResource("strawberry.jpg")));
frame1.add(label1);
frame1.setVisible(true);
}
}