import java.awt.*;
import java.awt.event.*;
import javax.swing.*;public class WindowChoice extends JFrame implements ItemListener,ActionListener{
JComboBox choice;
JTextField text;
JTextArea area;
JButton add,del;
public WindowChoice(){
init();
setLocation(300,300);
setSize(800,600);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
void init(){
setLayout(new FlowLayout());
choice = new JComboBox();
text = new JTextField();
area = new JTextArea(10,10);
choice.addItem("音乐天地");
choice.addItem("网络游戏");
choice.addItem("单机游戏");
choice.addItem("聊天室");
add = new JButton("添加");
add = new JButton("删除");
add.addActionListener(this);
text.addActionListener(this);
    del.addActionListener(this);
choice.addItemListener(this);
add(choice);
add(text);
add(add);
add(new JScrollPane(area));
}
public void itemStateChanged(ItemEvent e){
String name = choice.getSelectedItem().toString();
int index = choice.getSelectedIndex();
area.setText("\n",+index+":"+name);

}
public void actionPerformed(ActionEvent e){
if(e.getSource() == add || e.getSource() == text){
String name = text.getText();
if(name.length()>0){
choice.addItem(name);
choice.setSelectedItem(name);
area.append("\n列表添加:"+name);

}

}
else if(e.getSource() == del){
area.append("\n列表删除:"+choice.getSelectedItem());
choice.remove(choice.getSelectedIndex());
}
}
}
这里出了什么问题啊      为什么不能运行 啊

解决方案 »

  1.   

    你代码里面有两处错误,还没写main函数,改成下面就可以了import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;public class WindowChoice extends JFrame implements ItemListener,ActionListener{
        JComboBox choice;
        JTextField text;
        JTextArea area;
        JButton add,del;
        public WindowChoice(){
            init();
            setLocation(300,300);
            setSize(800,600);
            setVisible(true);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        }
        void init(){
            setLayout(new FlowLayout());
            choice = new JComboBox();
            text = new JTextField();
            area = new JTextArea(10,10);
            choice.addItem("音乐天地");
            choice.addItem("网络游戏");
            choice.addItem("单机游戏");
            choice.addItem("聊天室");
            add = new JButton("添加");
            del = new JButton("删除");//这里有修改过
            add.addActionListener(this);
            text.addActionListener(this);
            del.addActionListener(this);
            choice.addItemListener(this);
            add(choice);
            add(text);
            add(add);
            add(new JScrollPane(area));
        }
        public void itemStateChanged(ItemEvent e){
            String name = choice.getSelectedItem().toString();
            int index = choice.getSelectedIndex();
            area.setText("\n"+index+":"+name);  //这里修改过    }
        public void actionPerformed(ActionEvent e){
            if(e.getSource() == add || e.getSource() == text){
                String name = text.getText();
                if(name.length()>0){
                    choice.addItem(name);
                    choice.setSelectedItem(name);
                    area.append("\n列表添加:"+name);            }        }
            else if(e.getSource() == del){
                area.append("\n列表删除:"+choice.getSelectedItem());
                choice.remove(choice.getSelectedIndex());
            }
        }    public static void main(String[] args) {
            new WindowChoice();
        }
    }
      

  2.   

    我写了main函数   在另一个文件中    类错误提示 :Multiple ers at this line
    - Breakpoint:WindowChoice
    - The serializable class WindowChoice does not declare a static final serialVersionUID field of 
     type long
    还有:choice = new JComboBox();
    Type safety: The method addItem(Object) belongs to the raw type JComboBox. References to generic type JComboBox<E> should be 
     parameterized
    和choice.addItem("音乐天地");
    Type safety: The method addItem(Object) belongs to the raw type JComboBox. References to generic type JComboBox<E> should be 
     parameterized
      

  3.   

    我写了main函数   在另一个文件中    类错误提示 :Multiple ers at this line
    - Breakpoint:WindowChoice
    - The serializable class WindowChoice does not declare a static final serialVersionUID field of 
     type long
    还有:choice = new JComboBox();
    Type safety: The method addItem(Object) belongs to the raw type JComboBox. References to generic type JComboBox<E> should be 
     parameterized
    和choice.addItem("音乐天地");
    Type safety: The method addItem(Object) belongs to the raw type JComboBox. References to generic type JComboBox<E> should be 
     parameterized
      

  4.   

    它显示的错误是
    choice = new JComboBox();
    Type safety: The method addItem(Object) belongs to the raw type JComboBox. References to generic type JComboBox<E> should be  
     parameterized
    和choice.addItem("音乐天地");
    Type safety: The method addItem(Object) belongs to the raw type JComboBox. References to generic type JComboBox<E> should be  
     parameterized
    这两个    还有类还像要我
    Multiple ers at this line
     - Breakpoint:WindowChoice
     - The serializable class WindowChoice does not declare a static final serialVersionUID field of  
    type long
      

  5.   

    这两个不是error吧,应该是warning,应该不妨碍运行程序的,你的图形界面跑不起来么?如果跑不起来,加我QQ 519582737 我这里没有任何问题