求助:帮学校做一个系统

05-10-08 zts5678
帮学校做一个物理系统,做一个界面遇到问题,代码如下:
package face;

import java.awt.*;
import javax.swing.JPanel;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;


public class Try extends JPanel {
List list1=new List(14,true);

public Try() {
//super("CheckList Example");
String[] strs = {"swing", "home", "basic", "metal"};//复选框里的数据

final JList list = new JList( createData(strs) );//放入数据
JPanel jp1=new JPanel();

JPanel jp2=new JPanel(new BorderLayout ());
JPanel jp3=new JPanel(new BorderLayout ());
JPanel jp4=new JPanel(new BorderLayout ());
list.setCellRenderer(new CheckListRenderer());
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
list.setBorder(new EmptyBorder(0,4,0,0));
list.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
int index = list.locationToIndex(e.getPoint());
CheckableItem item = (CheckableItem)list.getModel().getElementAt(index);
item.setSelected(! item.isSelected());
Rectangle rect = list.getCellBounds(index, index);
list.repaint(rect);
}
});
JScrollPane sp = new JScrollPane(list);

final JTextArea textArea = new JTextArea(12,11);
JLabel jb1=new JLabel("所有仪器");
JLabel jb2=new JLabel(" 现有仪器");
JLabel jb3=new JLabel(" 不要仪器");
//List list1=new List();
//list1.enable(false);
textArea.enable(false);
JScrollPane textarea = new JScrollPane(textArea);
JScrollPane textPanel = new JScrollPane(list1);
JButton printButton = new JButton(">>");
printButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {//按钮事件,加入数据
ListModel model = list.getModel();
int n = model.getSize();
//List list1=new List();
for (int i=0;i<n;i++) {
CheckableItem item = (CheckableItem)model.getElementAt(i);



if (item.isSelected()) {
list1.addItem(item.toString());
//textArea.append(System.getProperty("line.separator"));
System.out.println(item.toString());
String a=item.toString();



}
}
}
});
JButton clearButton = new JButton(">>");//清空文本框
clearButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
//textArea.setText("");

int a=list1.getSelectedIndex();
list1.remove(a);
String bb=list1.getItem(a);
System.out.println(bb);
// textArea.append(bb);
//while()
//int c=a[1];
/* int f;
for(int b=0;b<a.length;b++)
{

//System.out.println(a);
f=a;
list1.remove(f-1);
//
System.out.println(b);
}//list1.remove(0);list1.remove(1);list1.remove(2);
*/



}
});
JPanel panel = new JPanel(new GridLayout(2,1));
panel.add(printButton);
panel.add(clearButton);
jp2.add(jb1, BorderLayout.NORTH);
jp2.add(sp, BorderLayout.CENTER);
//jp2.add(panel, BorderLayout.EAST);
//this.add(panel, BorderLayout.EAST);
jp3.add(printButton,BorderLayout.WEST);
jp3.add(textPanel, BorderLayout.CENTER);
jp3.add(jb2, BorderLayout.NORTH);
jp4.add(jb3, BorderLayout.NORTH);
jp4.add(textarea, BorderLayout.CENTER);
jp4.add(clearButton,BorderLayout.WEST);
this.add(jp2, BorderLayout.WEST);
this.add(jp3, BorderLayout.CENTER);
this.add(jp4, BorderLayout.EAST);
}
private CheckableItem[] createData(String[] strs) {//放入数据的方法
int n = strs.length;
CheckableItem[] items = new CheckableItem[n];
for (int i=0;i<n;i++) {
items = new CheckableItem(strs);
}
return items;
}

class CheckableItem {
private String str;
private boolean isSelected;

public CheckableItem(String str) {
this.str = str;
isSelected = false;
}

public void setSelected(boolean b) {
isSelected = b;
}

public boolean isSelected() {
return isSelected;
}

public String toString() {
return str;
}
}

class CheckListRenderer extends JCheckBox implements ListCellRenderer {

public CheckListRenderer() {
setBackground(UIManager.getColor("List.textBackground"));
setForeground(UIManager.getColor("List.textForeground"));
}

public Component getListCellRendererComponent(JList list, Object value,
int index, boolean isSelected, boolean hasFocus) {
setEnabled(list.isEnabled());
setSelected(((CheckableItem)value).isSelected());
setFont(list.getFont());
setText(value.toString());
return this;
}
}

public static void main(String args[]) {
Try frame1 = new Try();
JFrame frame = new JFrame("成绩管理");
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
frame.getContentPane().add(frame1);
frame.pack();
frame.setVisible(true);

}
}
想作出在‘所有仪器’里选中想要的,然后点击按钮》》,
选中的转到‘现有仪器’,在现有仪器中点击想删除的,点击按钮》》然后转到
‘不要仪器’
但是遇到问题了,请各位高手指点。谢谢