galera o q eu errei aqui por q meu retângulo não aparece, nossa eu vou surtar com esse negocio de inserir imagem.
public class Principal {
private static final long serialVersionUID = 1L;
public JFrame frame = new JFrame();
Componentes c = new Componentes();
public Principal() {
frame.setSize(400, 400);
frame.setTitle("Elaine");
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLayout(null);
frame.add(c);
c.startImage();
frame.setVisible(true);
}
public static void main(String[] args) {
Principal p = new Principal();
}
}
////////////////////////////
public class Componentes extends JPanel {
ImageIcon imagem = new ImageIcon(getClass().getResource("imagem.jpg"));
BufferedImage buffered;
public Graphics2D g2;
public Componentes() {
buffered = new BufferedImage(200, 200, BufferedImage.TYPE_INT_RGB);
g2 = (Graphics2D) buffered.getGraphics();
}
public void startImage() {
render1();
}
public void render1() {
g2.setColor(Color.BLUE);
g2.fillRect(20, 20, 50, 50);
}
public void paintComponent(Graphics2D g) {
g.drawImage(buffered, 0, 0, null);
}
}

