当前位置: 技术问答>java相关
一个java初级问题,关于编译的时候“java.awt.event”错误 ~*~
来源: 互联网 发布时间:2015-10-22
本文导语: 其中原码如下: import java.awt.*; import javax.swing.*; import java.awt.event.*; import MyWindowListener; public class MyComboBox extends JFrame implements ActionListener { private String iconGif[]={"1.jpg","2.jpg","3.jpg","4.jpg"}; private String name[]={"Home"...
其中原码如下:
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import MyWindowListener;
public class MyComboBox extends JFrame implements ActionListener
{
private String iconGif[]={"1.jpg","2.jpg","3.jpg","4.jpg"};
private String name[]={"Home","Classmate","Beauty","Jordon"};
private Icon icon[]={new ImageIcon(iconGif[0]),new ImageIcon(iconGif[1]),
new ImageIcon(iconGif[2]),new ImageIcon(iconGif[3])};
private JComboBox combobox=new JComboBox(name);
private JLabel label=new JLabel(icon[2]);
public MyComboBox()
{
super("JComboBox Test");
Container c=getContentPane();
c.add(combobox);
c.add(label);
c.setLayout(new FlowLayout());
combobox.setMaximumRowCount(3);
combobox.addItemListener(this);
setSize(660,480);
setVisible(true);
show();
}
public void actionPerformed(ActionEvent e)
{
label.setIcon(icon[combobox.getSelectedIndex()]);
}
public static void main(String args[])
{
MyComboBox app=new MyComboBox();
app.addWindowListener(new MyWindowListener());
}
}
**********************************************
我的JDK版本是1.3.02,编译的时候,出现一下错误,请指点下原因:
MyComboBox.java:21: 在 javax.swing.JComboBox 中的 addItemListener(java.awt.event
.ItemListener) 不能被应用到 (MyComboBox)
combobox.addItemListener(this);
^
1 个错误
谢谢!
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import MyWindowListener;
public class MyComboBox extends JFrame implements ActionListener
{
private String iconGif[]={"1.jpg","2.jpg","3.jpg","4.jpg"};
private String name[]={"Home","Classmate","Beauty","Jordon"};
private Icon icon[]={new ImageIcon(iconGif[0]),new ImageIcon(iconGif[1]),
new ImageIcon(iconGif[2]),new ImageIcon(iconGif[3])};
private JComboBox combobox=new JComboBox(name);
private JLabel label=new JLabel(icon[2]);
public MyComboBox()
{
super("JComboBox Test");
Container c=getContentPane();
c.add(combobox);
c.add(label);
c.setLayout(new FlowLayout());
combobox.setMaximumRowCount(3);
combobox.addItemListener(this);
setSize(660,480);
setVisible(true);
show();
}
public void actionPerformed(ActionEvent e)
{
label.setIcon(icon[combobox.getSelectedIndex()]);
}
public static void main(String args[])
{
MyComboBox app=new MyComboBox();
app.addWindowListener(new MyWindowListener());
}
}
**********************************************
我的JDK版本是1.3.02,编译的时候,出现一下错误,请指点下原因:
MyComboBox.java:21: 在 javax.swing.JComboBox 中的 addItemListener(java.awt.event
.ItemListener) 不能被应用到 (MyComboBox)
combobox.addItemListener(this);
^
1 个错误
谢谢!
|
combobox.addItemListener(this);
-->
combobox.addItemListener(new ItemListener() {
public void ItemStateChanged(ItemEvent e) {
………………
}
});
-->
combobox.addItemListener(new ItemListener() {
public void ItemStateChanged(ItemEvent e) {
………………
}
});
|
参数要求是ItemListener,而不是ActionListener