日期:2014-05-20  浏览次数:20736 次

超级郁闷~~ 谁能帮我看看啊 11点结帖
//一个列表和组合框的例子
import   javax.swing.event.*;
import   javax.swing.*;
import   java.awt.*;
import   java.awt.event.*;
public   class   ListComboxEaxmple   extends   JFrame   {
static   JFrame   myFrame;
ListComboxEaxmple(){
setLayout(new   GridLayout(2,2));
JList   list   =   new   JList(new   ListModeExample());
list.setVisibleRowCount(4);

JScrollPane   pane   =   new   JScrollPane();
pane.setViewportView(list);
add(pane);

JComboBox   combox   =   new   JComboBox(new   ComboModelExample());
add(combox);
}
public   static   void   main(String[]   args)   {
myFrame   =   new   JFrame( "列表框和组合框实例 ");
ListComboxEaxmple   jt   =   new   ListComboxEaxmple();
myFrame.getContentPane().add( "Crenter ",jt);
myFrame.setSize(200,200);
myFrame.addWindowListener(new   WindowAdapter(){
public   void   windowClosing(WindowEvent   e){
System.exit(0);
}
});
myFrame.setVisible(true);
}
}
class   ListModeExample   extends   AbstractListModel   {
String   values[]   =   { "张三 ", "李四 ", "王五 ", "周六 ", "赵七 ", "孙八 "};
public   Object   getElementAt(int   index){
return   values[index];
}

public   int   getSize()   {
return   values.length;
}
}
class   ComboModelExample   extends   ListModeExample   implements   ComboBoxModel   {
Object   item;
public   Object   getSelectedItem()   {
return   item;
}

public   void   setSelectedItem(Object   anItem)   {
item   =   anItem;
}

}


编译能通过,可不能运行
刚才发过了,没人帮忙啊,好心人近来看看啊
20少就再多加点,11点我们熄灯了就结贴,见者有份哈
新学JAVA,真不知道怎么改了
郁闷~~~~~~~~~~


------解决方案--------------------
没时间看,凑个数先
------解决方案--------------------
myFrame.getContentPane().add( "Crenter ",jt);

//ERR:adding a window to a container

------解决方案--------------------
主函数这么写:
public static void main(String[] args) {
myFrame = new ListComboxEaxmple();
myFrame.setSize(200,200);
myFrame.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
myFrame.setTitle( "列表框和组合框实例 ");
myFrame.setVisible(true);
}
------解决方案--------------------
提示信息不是已经写的很清楚了吗,楼上的