JAVA中类名不是抽象的,并且未覆盖抽象方法
importjava.awt.*;importjavax.swing.*;importjava.awt.event.*;publicclassComboBoxFramee...
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class ComboBoxFrame extends JFrame{
private String []citys = {"HongKong","Shanghai","Beijing","Xi'an"};
private JComboBox combCity = new JComboBox();
private JButton b = new JButton("Add City");
private JTextField t = new JTextField(15);
private int count = 0;
public ComboBoxFrame(){
setSize(new Dimension(200,175));
combCity.addItem("Shenzhen");
b.addActionListener(new ActionListener(){
public void acitonPerformed(ActionEvent e){
if(count < citys.length){
combCity.addItem(citys[count++]);
}
}
});
combCity.addActionListener(new ActionListener(){
public void acitonPerformed(ActionEvent e){
int index = ((JComboBox)e.getSource()).getSelectedIndex();
t.setText("index:" + index);
}
});
getContentPane().setLayout(new FlowLayout());
getContentPane().add(t);
getContentPane().add(combCity);
getContentPane().add(b);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable(){
public void run(){
try{
UIManager.setLookAndFeel(
UIManager.getSystemLookAndFeelClassName());
}catch(Exception exception){
exception.printStackTrace();
}
ComboBoxFrame comboboxframe = new ComboBoxFrame();
comboboxframe.setVisible(true);
}
});
}
}
Comboboxframe.java:14: 错误: <匿名ComboBoxFrame$1>不是抽象的, 并且未覆盖ActionLi
stener中的抽象方法actionPerformed(ActionEvent)
b.addActionListener(new ActionListener(){
注: Comboboxframe.java使用了未经检查或不安全的操作。
注: 有关详细信息, 请使用 -Xlint:unchecked 重新编译。 展开
import javax.swing.*;
import java.awt.event.*;
public class ComboBoxFrame extends JFrame{
private String []citys = {"HongKong","Shanghai","Beijing","Xi'an"};
private JComboBox combCity = new JComboBox();
private JButton b = new JButton("Add City");
private JTextField t = new JTextField(15);
private int count = 0;
public ComboBoxFrame(){
setSize(new Dimension(200,175));
combCity.addItem("Shenzhen");
b.addActionListener(new ActionListener(){
public void acitonPerformed(ActionEvent e){
if(count < citys.length){
combCity.addItem(citys[count++]);
}
}
});
combCity.addActionListener(new ActionListener(){
public void acitonPerformed(ActionEvent e){
int index = ((JComboBox)e.getSource()).getSelectedIndex();
t.setText("index:" + index);
}
});
getContentPane().setLayout(new FlowLayout());
getContentPane().add(t);
getContentPane().add(combCity);
getContentPane().add(b);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable(){
public void run(){
try{
UIManager.setLookAndFeel(
UIManager.getSystemLookAndFeelClassName());
}catch(Exception exception){
exception.printStackTrace();
}
ComboBoxFrame comboboxframe = new ComboBoxFrame();
comboboxframe.setVisible(true);
}
});
}
}
Comboboxframe.java:14: 错误: <匿名ComboBoxFrame$1>不是抽象的, 并且未覆盖ActionLi
stener中的抽象方法actionPerformed(ActionEvent)
b.addActionListener(new ActionListener(){
注: Comboboxframe.java使用了未经检查或不安全的操作。
注: 有关详细信息, 请使用 -Xlint:unchecked 重新编译。 展开
2个回答
2013-07-21
展开全部
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class ComboBoxFrame extends JFrame{
private String []citys = {"HongKong","Shanghai","Beijing","Xi'an"};
private JComboBox combCity = new JComboBox();
private JButton b = new JButton("Add City");
private JTextField t = new JTextField(15);
private int count = 0;
public ComboBoxFrame(){
setSize(new Dimension(200,175));
combCity.addItem("Shenzhen");
b.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
if(count < citys.length){
combCity.addItem(citys[count++]);
}
}
});
combCity.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
int index = ((JComboBox)e.getSource()).getSelectedIndex();
t.setText("index:" + index);
}
});
getContentPane().setLayout(new FlowLayout());
getContentPane().add(t);
getContentPane().add(combCity);
getContentPane().add(b);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable(){
public void run(){
try{
UIManager.setLookAndFeel(
UIManager.getSystemLookAndFeelClassName());
}catch(Exception exception){
exception.printStackTrace();
}
ComboBoxFrame comboboxframe = new ComboBoxFrame();
comboboxframe.setVisible(true);
}
});
}
}
COPY过去运行吧!
追问
咦 我怎么看了是完全一样的呀?不过可以运行
追答
你是手写的吧?哪是一样的?方法名字不一样,就没实现接口方法!
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询