I'm doing a simulation of a cinema and I'm trying to add an image to a JFrame from a Thread but the image does not appear in the window, this is the code I made
import java.awt.Image;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
public class taquilla implements Runnable {
public taquilla() {
// TODO Auto-generated constructor stub
}
public static void main(String[] args) {
// TODO Auto-generated method stub
}
@Override
public void run() {
JLabel taquillero = new JLabel("");
Image img= new ImageIcon("Taquillero.png").getImage();
ImageIcon img2=new ImageIcon(img.getScaledInstance(200, 100, Image.SCALE_SMOOTH));
taquillero.setIcon(img2);
taquillero.setBounds(100,10,30,30);
taquillero.setSize(taquillero.getPreferredSize());
simulador.ventanasim.add(taquillero);
}
}
In another class is where I start the Thread with this code
public simulator () {
super("Simulador Cinema");
setExtendedState(MAXIMIZED_BOTH);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setLayout(null);
panelImagen p = new panelImagen();
p.setBorder(new EmptyBorder(5,5,5,5));
p.setLayout(new BorderLayout(0,0));
setContentPane(p);
Thread taquilla[] = new Thread[BotonSetup.empletaq];
for(int i=0;i<BotonSetup.empletaq;i++) {
taquilla[i] = new Thread(taquillas1);
taquilla[i].start();
}
}