这个程序我在CMD里用appletviewer运行,结果有错误,提示是ComboBoxDemo.class不是public对象或没有公共构造函数!
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Example64{
public static void main(String[] args)
{ ComboBoxDemo myComboBoxGUI=new ComboBoxDemo();
}
}
class ComboBoxDemo extends JFrame implements ActionListener,ItemListener{
public static final int Width=350;
public static final int Height=150;
String porList[]={"踢足球","打篮球","打排球"};
JTextField text;
JComboBox comboBox;
public ComboBoxDemo() {
setSize(Width,Height);
setTitle("组合框使用示意程序");
Container conPane=getContentPane();
conPane.setBackground(Color.BLUE);
conPane.setLayout(new FlowLayout());
comboBox=new JComboBox(porList);
comboBox.addActionListener(this);
comboBox.addItemListener(this);
comboBox.setEditable(true);
conPane.add(comboBox);
text=new JTextField();
conPane.add(text);
comboBox.setVisible(true);
}
public void itemStateChanged(ItemEvent e)
{
if(e.getSource()==comboBox)
{
text.setText(comboBox.getSelectedItem().toString());
}
} public void actionPerformed(ActionEvent e)
{
if(e.getSource()==comboBox)
{
text.setText(comboBox.getSelectedItem().toString());
}
}
}
我的html文件是这么写的:
<html>
<body>
<applet
code="ComboBoxDemo.class" width=320 height=180>
</applet>
</body>
</html>
求技术分 |
|