The method addItem(String) is undefined for the type JComboBox 开发环境eclipse3.6+jdk1.6
程序:importjava.awt.BorderLayout;importjava.awt.event.*;importjava.awt.*;importjavax.sw...
程序:
import java.awt.BorderLayout;
import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
public class ComboBoxDemo extends JApplet implements ItemListener{
JPanel panel = new JPanel();
JComboBox os = new JComboBox(),
browser = new JComboBox();
JTextArea ta=new JTextArea(4,20);
JScrollPane jsp=new JScrollPane(ta);
public void init(){
os.addItem("windows"); //
os.addItem("linux");//
os.addItem("android");//
os.addItem("mac ox");//
browser.addItem("IE");//
browser.addItem("HF");//
browser.addItem("SE");//
panel.add(os);
panel.add(browser);
add(panel,BorderLayout.NORTH);
add(jsp,BorderLayout.CENTER);
os.addItemListener(this);//
browser.addItemListener(this);//
}
public void itemStateChanged(ItemEvent e) {
String s1 ="操作系统:",
s2 ="浏览器:";
s1 = s1+os.getSelectedItem()+"\n";//
s2 = s1+browser.getSelectedItem()+"\n";//
}
}
//是报错的地方 展开
import java.awt.BorderLayout;
import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
public class ComboBoxDemo extends JApplet implements ItemListener{
JPanel panel = new JPanel();
JComboBox os = new JComboBox(),
browser = new JComboBox();
JTextArea ta=new JTextArea(4,20);
JScrollPane jsp=new JScrollPane(ta);
public void init(){
os.addItem("windows"); //
os.addItem("linux");//
os.addItem("android");//
os.addItem("mac ox");//
browser.addItem("IE");//
browser.addItem("HF");//
browser.addItem("SE");//
panel.add(os);
panel.add(browser);
add(panel,BorderLayout.NORTH);
add(jsp,BorderLayout.CENTER);
os.addItemListener(this);//
browser.addItemListener(this);//
}
public void itemStateChanged(ItemEvent e) {
String s1 ="操作系统:",
s2 ="浏览器:";
s1 = s1+os.getSelectedItem()+"\n";//
s2 = s1+browser.getSelectedItem()+"\n";//
}
}
//是报错的地方 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询