package TestChem;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
/**
*
* @author kian
*/
public class Chem3 extends JFrame implements ItemListener {
JComboBox cb;
JLabel lbl;
Icon i01, i02, i03, i04, i05, i06, i07, i08, i09, i10, i11, i12, i13, i14, i15, i16, i17, i18, i19, i20, i21, i22, i23, i24, i25, i26, i27, i28, i29, i30, i31, i32, i33, i34, i35;
//Main
public static void main(String ar[]) {
JFrame f = new Chem3();
f.setTitle("Created By Kian Kiani");
f.setDefaultCloseOperation(f.EXIT_ON_CLOSE);
f.setSize(200, 160);
f.setVisible(true);
}
//Frame
public Chem3() {
i01 = new ImageIcon(getClass().getResource("/images/ca.jpg"));
i02 = new ImageIcon(getClass().getResource("/images/k.jpg"));
i03 = new ImageIcon(getClass().getResource("/images/So.jpg"));
i04 = new ImageIcon(getClass().getResource("/images/Li.jpg"));
i05 = new ImageIcon(getClass().getResource("/images/mg.jpg"));
i06 = new ImageIcon(getClass().getResource("/images/fe.jpg"));
i07 = new ImageIcon(getClass().getResource("/images/ba.jpg"));
i08 = new ImageIcon(getClass().getResource("/images/cu.jpg"));
i09 = new ImageIcon(getClass().getResource("/images/shi.jpg"));
i10 = new ImageIcon(getClass().getResource("/images/p.jpg"));
i11 = new ImageIcon(getClass().getResource("/images/cr.jpg"));
i12 = new ImageIcon(getClass().getResource("/images/z.jpg"));
i13 = new ImageIcon(getClass().getResource("/images/a.jpg"));
i14 = new ImageIcon(getClass().getResource("/images/km.jpg"));
i15 = new ImageIcon(getClass().getResource("/images/km1.jpg"));
i16 = new ImageIcon(getClass().getResource("/images/am.jpg"));
i17 = new ImageIcon(getClass().getResource("/images/soc.jpg"));
i18 = new ImageIcon(getClass().getResource("/images/cl.jpg"));
i19 = new ImageIcon(getClass().getResource("/images/clc.jpg"));
i20 = new ImageIcon(getClass().getResource("/images/hcl.jpg"));
i21 = new ImageIcon(getClass().getResource("/images/sa.jpg"));
i22 = new ImageIcon(getClass().getResource("/images/su.jpg"));
i23 = new ImageIcon(getClass().getResource("/images/pa.jpg"));
i24 = new ImageIcon(getClass().getResource("/images/ppo.jpg"));
i25 = new ImageIcon(getClass().getResource("/images/si.jpg"));
i26 = new ImageIcon(getClass().getResource("/images/pb.jpg"));
i27 = new ImageIcon(getClass().getResource("/images/cc.jpg"));
i28 = new ImageIcon(getClass().getResource("/images/hip.jpg"));
i29 = new ImageIcon(getClass().getResource("/images/nia.jpg"));
i30 = new ImageIcon(getClass().getResource("/images/nio.jpg"));
i31 = new ImageIcon(getClass().getResource("/images/nis.jpg"));
i32 = new ImageIcon(getClass().getResource("/images/cb.jpg"));
i33 = new ImageIcon(getClass().getResource("/images/amo.jpg"));
i34 = new ImageIcon(getClass().getResource("/images/pc.jpg"));
i35 = new ImageIcon(getClass().getResource("/images/hg.jpg"));
cb = new JComboBox();
String[] strmenu = {"CaCO3", "KNO3", "Na2SO4", "LiCl", "MgO", "Fe(OH)3", "BaSO3", "Cu(NO2)2", "NaOH", "KOH", "Cr2S3",
"Zn3(PO4)2", "AgI", "KMno4", "K2MnO4", "(NH4)2Cr2O7", "Na2CrO4", "NaClO2", "Ca(ClO3)2", "HCl", "H2SO4", "H2SO3", "H3PO4",
"H3PO3", "Na2SiO3", "PbO2", "CaC2", "KClO", "HNO3", "HNO2", "NiSO4", "Ca(HCO3)2", "NH4NO3", "KClO4", "Hg(NO3)2"
};
for (int i = 0; i < strmenu.length; i++) {
cb.addItem(strmenu[i]);
}
cb.addItemListener(this);
lbl = new JLabel("", i01, JLabel.CENTER);
Container c = getContentPane();
c.add(cb, BorderLayout.NORTH);
c.add(lbl, BorderLayout.CENTER);
c.setBackground(Color.yellow);
}
//Event
public void itemStateChanged(ItemEvent ie) {
Container c = getContentPane();
int imgidx = cb.getSelectedIndex();
if (imgidx == 0) {
lbl.setIcon(i01);
} else if (imgidx == 1) {
lbl.setIcon(i02);
c.setBackground(Color.red);
} else if (imgidx == 2) {
lbl.setIcon(i03);
c.setBackground(Color.blue);
} else if (imgidx == 3) {
lbl.setIcon(i04);
c.setBackground(Color.green);
} else if (imgidx == 4) {
lbl.setIcon(i05);
c.setBackground(Color.orange);
} else if (imgidx == 5) {
lbl.setIcon(i06);
c.setBackground(Color.yellow);
} else if (imgidx == 6) {
lbl.setIcon(i07);
c.setBackground(Color.red);
} else if (imgidx == 7) {
lbl.setIcon(i08);
c.setBackground(Color.blue);
} else if (imgidx == 8) {
lbl.setIcon(i09);
c.setBackground(Color.green);
} else if (imgidx == 9) {
lbl.setIcon(i10);
c.setBackground(Color.orange);
} else if (imgidx == 10) {
lbl.setIcon(i11);
c.setBackground(Color.red);
} else if (imgidx == 11) {
lbl.setIcon(i12);
c.setBackground(Color.blue);
} else if (imgidx == 12) {
lbl.setIcon(i13);
c.setBackground(Color.orange);
} else if (imgidx == 13) {
lbl.setIcon(i14);
c.setBackground(Color.yellow);
} else if (imgidx == 14) {
lbl.setIcon(i15);
c.setBackground(Color.red);
} else if (imgidx == 15) {
lbl.setIcon(i16);
c.setBackground(Color.blue);
} else if (imgidx == 16) {
lbl.setIcon(i17);
c.setBackground(Color.green);
} else if (imgidx == 17) {
lbl.setIcon(i18);
c.setBackground(Color.orange);
} else if (imgidx == 18) {
lbl.setIcon(i19);
c.setBackground(Color.red);
} else if (imgidx == 19) {
lbl.setIcon(i20);
c.setBackground(Color.blue);
} else if (imgidx == 20) {
lbl.setIcon(i21);
c.setBackground(Color.orange);
} else if (imgidx == 21) {
lbl.setIcon(i22);
c.setBackground(Color.yellow);
} else if (imgidx == 22) {
lbl.setIcon(i23);
c.setBackground(Color.red);
} else if (imgidx == 23) {
lbl.setIcon(i24);
c.setBackground(Color.orange);
} else if (imgidx == 24) {
lbl.setIcon(i25);
c.setBackground(Color.red);
} else if (imgidx == 25) {
lbl.setIcon(i26);
c.setBackground(Color.blue);
} else if (imgidx == 26) {
lbl.setIcon(i27);
c.setBackground(Color.yellow);
} else if (imgidx == 27) {
lbl.setIcon(i28);
c.setBackground(Color.green);
} else if (imgidx == 28) {
lbl.setIcon(i29);
c.setBackground(Color.red);
} else if (imgidx == 29) {
lbl.setIcon(i30);
c.setBackground(Color.orange);
} else if (imgidx == 30) {
lbl.setIcon(i31);
c.setBackground(Color.blue);
} else if (imgidx == 31) {
lbl.setIcon(i32);
c.setBackground(Color.yellow);
} else if (imgidx == 32) {
lbl.setIcon(i33);
c.setBackground(Color.green);
} else if (imgidx == 33) {
lbl.setIcon(i34);
c.setBackground(Color.red);
} else if (imgidx == 34) {
lbl.setIcon(i35);
c.setBackground(Color.blue);
}
}
}
0
هیچ نظری موجود نیست:
ارسال یک نظر