import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class MyList extends Applet implements ItemListener
{
Label lbl1, lbl2, lblwork, lblsalary;
List lstwork, lstsalary;
String[] strwork={"服務業", "財金相關", "資訊業", "自由業", "學生", "其他"};
String[] strsalary={"1萬~3萬", "3萬~5萬", "6萬~8萬", "9萬~10萬", "10萬以上"};
public void init()
{
setLayout(new GridLayout(3, 2));
lbl1 = new Label("選擇您的職業(可複選)");
lbl2 = new Label("選擇您的月薪");
lblwork = new Label();
lblsalary = new Label();
lstwork=new List(4, true);
for (int i=0; i lstwork.add(strwork[i]);
lstsalary=new List(4);
for (int i=0; i lstsalary.add(strsalary[i]);
lstwork.addItemListener(this);
lstsalary.addItemListener(this);
add(lbl1);
add(lbl2);
add(lstwork);
add(lstsalary);
add(lblwork);
add(lblsalary);
}
public void itemStateChanged(ItemEvent ie)
{
if(ie.getSource()==lstwork)
{
String[] msg=lstwork.getSelectedItems();
String s="";
for(int i=0; i s += msg[i] + ", ";
lblwork.setText("您每個月的所得是" + s);;
}
else
{
lblsalary.setText("您的職業是" + lstsalary.getSelectedItem());
}
}
}
創作者介紹

My Life Going By My Style

Neo Chao 發表在 痞客邦 PIXNET 留言(0) 人氣()