I hate not knowing why something works. But I remember going through the Graphics totorial and seeing them do this in the constructor where they seem to draw the second image
BufferedImage img = ImageIO.read(imageSrc);
int w = img.getWidth(null);
int h = img.getHeight(null);
BufferedImage bi = new
BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
Graphics g = bi.getGraphics();
g.drawImage(img, 0, 0, null);
Here's the fix I made. I wish I could give more explanation, but feel free to check out the tutorial I linked
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
public class RoadNetwork extends JPanel {
BufferedImage tempicon;
BufferedImage truckicon;
public RoadNetwork() throws IOException {
tempicon = ImageIO.read(getClass().getResource("resources/stack_reverse.png"));
int w = tempicon.getWidth(null);
int h = tempicon.getHeight(null);
truckicon = new
BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
Graphics g = truckicon.getGraphics();
g.drawImage(tempicon, 0, 0, null);
}
protected void paintComponent(Graphics g) {
super.paintComponent(g);
//g.clearRect(0, 0, 600, 600); // insert window size parameters here
// for (int i = 0; i < AMEC.vehiclecounter; i++) {
// if (AMEC.vehicle[i].spawned == true && AMEC.vehicle[i].finished ==
// false) { // if the truck is somewhere on the plant
// g.drawImage(truckicon, AMEC.getcoord(i)[0], AMEC.getcoord(i)[1],
// this);
// }
// }
g.drawImage(truckicon, 100, 100, this);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable(){
public void run() {
try {
RoadNetwork roadnetwork = new RoadNetwork();
roadnetwork.setVisible(true);
JFrame frame = new JFrame();
frame.add(roadnetwork);
frame.setSize(600, 600);
frame.setVisible(true);
} catch (IOException es) {
es.printStackTrace();
}
}
});
}
}
Also, I was going to suggest @AndrewThompson's answer, but because I didn't know the reason you were using two BufferedImages, I didn't want to suggest it. You may have been trying to do what the tutorial was doing.