望高人帮忙改一个Java程序
以下是我的代码,其中有一个语句不知道怎么写,就是不知道怎样删除info列表框中当前所选的项目//cx.javaimportjava.awt.event.*;importj...
以下是我的代码,其中有一个语句不知道怎么写,就是不知道怎样删除info列表框中当前所选的项目
//cx.java
import java.awt.event.*;
import java.awt.*;
public class cx extends WindowAdapter
implements ActionListener,Itemlistener
{
Frame f;
TextField number,name;
Checkbox x1,x2;
Choice cx,n;
List infor;
Button addInfor,deleteInfor;
public static void main(String args[])
{
(new cx()).display();
}
public void display()
{
Panel p1,p2,p3;
CheckboxGroup cg;
f=new Frame("菜单输入窗口");
f.setSize(480,200);
f.setLocation(200,140);
f.setBackground(color.red);
GridLayout f=new GridLayout(1,2);
infor=new List();
f.add(infor);
p1=new Panel();
p1.setLayout(new GridLayout(6,1));
f.add(p1);
number=new TextField("编号");
name=new TextField("菜名");
cg=new CheckboxGroup();
x1=new Checkbox("打折",cg,true);
x1=new Checkbox("否",cg,false);
cx=new Choice();
cx.addItem("炒菜类");
cx.addItem("烧菜类");
cx.addItem("冷菜类");
cx.addItemListener(this);
n=new Choice();
n.addItem("干煸豆角");
cx.addItem("鸡蛋西红柿");
addInfor=new Button("增加");
deleteInfor=new Button("删除");
addInfor.addActionListener(this);
deleteInfor.addActionListener(this);
p1.add(number);
p1.add(name);
p2=new Panel();
p2.setLayout(new GridLayout(1,2));
p2.add(x1);
p2.add(x2);
p2.add(p2);
p2.add(cx);
p2.add(n);
p3=new Panel();
p3.setLayout(new GridLayout(1,2));
p3.add(addInfor);
p3.add(deleteInfor);
p1.add(p3);
f.addWindowListener(this);
f.setVisible(true);
}
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==addInfor)
{
String str;
str=number.getText()+" "+name.getText();
if(x1.getState())
str=str+" "+x1.getLable();
if(x2.getState())
str=str+" "+x2.getLable();
str=str+" "+cx.getSelectedItem();
str=str+" "+n.getSelectedItem();
infor.add(str);
}
if(e.getSource()==deleteInfor)
{
//removeElement();
public void remove(int position)
public int getSelectedIndex() //删除info列表框中当前所选的项目
}
}
public void itemStateChanged(ItemEvent e)
{
if(cx.getSelectedIndex()==0)
{
n.removeAll();
n.addItem("炒菜类");
n.addItem("烧菜类");
n.addItem("冷菜类");
}
if(cx.getSelectedIndex()==1)
{
n.removeAll();
n.addItem("干煸豆角");
n.addItem("鸡蛋西红柿");
}
}
} 展开
//cx.java
import java.awt.event.*;
import java.awt.*;
public class cx extends WindowAdapter
implements ActionListener,Itemlistener
{
Frame f;
TextField number,name;
Checkbox x1,x2;
Choice cx,n;
List infor;
Button addInfor,deleteInfor;
public static void main(String args[])
{
(new cx()).display();
}
public void display()
{
Panel p1,p2,p3;
CheckboxGroup cg;
f=new Frame("菜单输入窗口");
f.setSize(480,200);
f.setLocation(200,140);
f.setBackground(color.red);
GridLayout f=new GridLayout(1,2);
infor=new List();
f.add(infor);
p1=new Panel();
p1.setLayout(new GridLayout(6,1));
f.add(p1);
number=new TextField("编号");
name=new TextField("菜名");
cg=new CheckboxGroup();
x1=new Checkbox("打折",cg,true);
x1=new Checkbox("否",cg,false);
cx=new Choice();
cx.addItem("炒菜类");
cx.addItem("烧菜类");
cx.addItem("冷菜类");
cx.addItemListener(this);
n=new Choice();
n.addItem("干煸豆角");
cx.addItem("鸡蛋西红柿");
addInfor=new Button("增加");
deleteInfor=new Button("删除");
addInfor.addActionListener(this);
deleteInfor.addActionListener(this);
p1.add(number);
p1.add(name);
p2=new Panel();
p2.setLayout(new GridLayout(1,2));
p2.add(x1);
p2.add(x2);
p2.add(p2);
p2.add(cx);
p2.add(n);
p3=new Panel();
p3.setLayout(new GridLayout(1,2));
p3.add(addInfor);
p3.add(deleteInfor);
p1.add(p3);
f.addWindowListener(this);
f.setVisible(true);
}
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==addInfor)
{
String str;
str=number.getText()+" "+name.getText();
if(x1.getState())
str=str+" "+x1.getLable();
if(x2.getState())
str=str+" "+x2.getLable();
str=str+" "+cx.getSelectedItem();
str=str+" "+n.getSelectedItem();
infor.add(str);
}
if(e.getSource()==deleteInfor)
{
//removeElement();
public void remove(int position)
public int getSelectedIndex() //删除info列表框中当前所选的项目
}
}
public void itemStateChanged(ItemEvent e)
{
if(cx.getSelectedIndex()==0)
{
n.removeAll();
n.addItem("炒菜类");
n.addItem("烧菜类");
n.addItem("冷菜类");
}
if(cx.getSelectedIndex()==1)
{
n.removeAll();
n.addItem("干煸豆角");
n.addItem("鸡蛋西红柿");
}
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询