java Choice
importjava.awt.*;importjava.awt.event.*;classMyTest4implementsItemListener{publicstat...
import java.awt.*;
import java.awt.event.*;
class MyTest4 implements ItemListener
{
public static void main(String args[])
{
Frame f=new Frame();
f.setLayout(new FlowLayout());
Choice c=new Choice();
c.addItem("北京");
c.addItem("上海");
f.add(c);
c.addItemListener(new Pro());
Choice c1=new Choice();
f.add(c1);
f.setSize(500,500);
f.setVisible(true);
}
public void itemStateChanged(ItemEvent e)
{
if ((e.getSource()).getSelectedItem=="上海")
{
c1.addItem("-请选择-");
c1.addItem("黄浦区");
}
}
}
不知错在拿里??请大家帮帮忙,谢谢 展开
import java.awt.event.*;
class MyTest4 implements ItemListener
{
public static void main(String args[])
{
Frame f=new Frame();
f.setLayout(new FlowLayout());
Choice c=new Choice();
c.addItem("北京");
c.addItem("上海");
f.add(c);
c.addItemListener(new Pro());
Choice c1=new Choice();
f.add(c1);
f.setSize(500,500);
f.setVisible(true);
}
public void itemStateChanged(ItemEvent e)
{
if ((e.getSource()).getSelectedItem=="上海")
{
c1.addItem("-请选择-");
c1.addItem("黄浦区");
}
}
}
不知错在拿里??请大家帮帮忙,谢谢 展开
1个回答
展开全部
import java.awt.*;
import java.awt.event.*;
class MyTest4 implements ItemListener{
Frame f;
Choice c;
Choice c1;
public MyTest4(){
f=new Frame();
f.setLayout(new FlowLayout());
c=new Choice();
c.addItem("北京");
c.addItem("上海");
f.add(c);
c.addItemListener(this);
c1=new Choice();
c1.add(" ");
f.add(c1);
f.setSize(500,500);
f.setVisible(true);
}
public static void main(String args[]) {
MyTest4 mt = new MyTest4();
}
public void itemStateChanged(ItemEvent e){
if(e.getItem().equals("上海")){
c1.remove(" ");
c1.addItem("-请选择-");
c1.addItem("黄浦区");
}
}
}
import java.awt.event.*;
class MyTest4 implements ItemListener{
Frame f;
Choice c;
Choice c1;
public MyTest4(){
f=new Frame();
f.setLayout(new FlowLayout());
c=new Choice();
c.addItem("北京");
c.addItem("上海");
f.add(c);
c.addItemListener(this);
c1=new Choice();
c1.add(" ");
f.add(c1);
f.setSize(500,500);
f.setVisible(true);
}
public static void main(String args[]) {
MyTest4 mt = new MyTest4();
}
public void itemStateChanged(ItemEvent e){
if(e.getItem().equals("上海")){
c1.remove(" ");
c1.addItem("-请选择-");
c1.addItem("黄浦区");
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询