JAVA编程题的设计思路

import java.awt.*;
import java.awt.event.*;
import javax.swing.JOptionPane;
class WindowList extends Frame implements ItemListener, ActionListener {
List list;
Label label;
TextField text;
Button add, del, delall;
Checkbox box1, box2;
CheckboxGroup group;
WindowList()
{ setLayout(new FlowLayout());
label = new Label("商务0602 曾斌 2008年6月21日");
list = new List();
text = new TextField(8);
add = new Button("添加");
del = new Button("删除");
group = new CheckboxGroup();
delall = new Button("全部删除");
box1 = new Checkbox("单选", true, group);
box2 = new Checkbox("多选", false, group);
add.addActionListener(this);
text.addActionListener(this);
del.addActionListener(this);
delall.addActionListener(this);
list.addItemListener(this);
box1.addItemListener(this);
box2.addItemListener(this);
add(label);
add(list);
add(del);
add(text);
add(add);
add(delall);
add(box1);
add(box2);
delall.addActionListener(this);
setSize(260, 400);
setVisible(true);
validate();
}
public void itemStateChanged(ItemEvent e)
{ if (e.getSource() == list)
{ String name[] = list.getSelectedItems();
int index[] = list.getSelectedIndexes();

}
if (e.getSource() == box1)
{ if (box1.getState() == true)
{ list.setMultipleMode(false);
}
}
if (e.getSource() == box2)
{ if (box2.getState() == true)
{ list.setMultipleMode(true);
}
}
}
public void actionPerformed(ActionEvent e)
{ if (e.getSource() == add || e.getSource() == text)
{ String name = text.getText();
if (name.length() > 0)
{ list.add(name);
}
}
else if (e.getSource() == del)
{ String items[] = list.getSelectedItems();
if (list != null && items.length > 0)
{ for(int i = 0;i<items.length;i++)
{ list.remove(items[i]);
}
}
}
else if(e.getSource()==delall)
{list.removeAll();
}
}
}
public class zuoye2
{ public static void main(String args[])
{ new WindowList();
}
}

大家帮忙看看这个程序的设计思路应该怎么写?模式最好是“先...再...然后...最后...”

第1个回答  2008-06-26
先继承Frame模板,在实现listener监听器接口。然后在模板中添加控件,设置布局。最后通过监听器判断控件是否发生变化(如单击(onclick),改变(onchange)等)