import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Zvirata extends JFrame{
//Container obsah;
String[] zvirata = { "Pes", "Kočka", "Prase"};
JComboBox cb;
JLabel l1 = new JLabel();
ImageIcon obrazek;
public Zvirata(){
init();
obsah();
setVisible(true);
}
public void init(){
setTitle("Zvířata");
setSize(515,475);
setLocationRelativeTo(null);
/*obsah = getContentPane();//obsah formuláře
obsah.setBackground(Color.RED);*/
setLayout(new FlowLayout());
setDefaultCloseOperation(3);
}
@SuppressWarnings("unchecked")
public void obsah(){
cb = new JComboBox(zvirata);
obrazek = new ImageIcon("Pes.png");
l1.setIcon(obrazek);
add(cb);
add(l1);
cb.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
String s = cb.getSelectedItem().toString();
obrazek = new ImageIcon(s+".png");
l1.setIcon(obrazek);
}
});
}
public static void main(String[] args){
Zvirata z = new Zvirata();
}
}