关于java.awt.event.ActionListener的覆盖问题
importjava.awt.*;importjava.awt.event.*;classWindowListextendsFrameimplementsItemList...
import java.awt.*;
import java.awt.event.*;
class WindowList extends Frame implements ItemListener,ActionListener {
List list1,list2;
TextArea text1,text2;
int index = 0;
WindowList() {
setLayout(new FlowLayout());
list1 = new List(3,false);
list2 = new List(3,false);
text1 = new TextArea(2,20);
text2 = new TextArea(2,20);
list1.add("计算1+2+...");
list1.add("计算1*1+2*2+...");
list1.add("计算1*1*1+2*2*2...");
for(int i=1;i<=100;i++) {
list2.add("前"+i+"项和");
}
add(list1);
add(list2);
add(text1);
add(text2);
list1.addItemListener(this);
list2.addActionListener(this);
setSize(400,200);
setVisible(true);
validate();
}
public void itemStateChanged(ItemEvent e) {
if(e.getItemSelectable()==list1) {
text1.setText(list1.getSelectedItem());
index=list1.getSelectedIndex();
}
}
public void actionPerformde(ActionEvent e) {
int n = list2.getSelectedIndex(),sum = 0;
String name = list2.getSelectedItem();
switch(index) {
case 0:
for(int i = 1;i<=n+1;i++) {
sum = sum+i;
}
case 1:
for(int i = 1;i<=n+1;i++) {
sum = sum*i;
}
case 2:
for(int i = 1;i<=n+1;i++) {
sum = sum+i*i*i;
}
break;
default:
sum = -100;
}
text2.setText(name +"等于"+sum);
}
}
public class WindowLi {
public static void main(String[] args) {
new WindowList();
}
}
当运行的时候,说“WindowList 不是抽象的,并且未覆盖 java.awt.event.ActionListener中的抽象方法 actionPerFormed(java.awt.event.ActionEvent) class WindowList extends Frame implements ItemListener,ActionListener“ 展开
import java.awt.event.*;
class WindowList extends Frame implements ItemListener,ActionListener {
List list1,list2;
TextArea text1,text2;
int index = 0;
WindowList() {
setLayout(new FlowLayout());
list1 = new List(3,false);
list2 = new List(3,false);
text1 = new TextArea(2,20);
text2 = new TextArea(2,20);
list1.add("计算1+2+...");
list1.add("计算1*1+2*2+...");
list1.add("计算1*1*1+2*2*2...");
for(int i=1;i<=100;i++) {
list2.add("前"+i+"项和");
}
add(list1);
add(list2);
add(text1);
add(text2);
list1.addItemListener(this);
list2.addActionListener(this);
setSize(400,200);
setVisible(true);
validate();
}
public void itemStateChanged(ItemEvent e) {
if(e.getItemSelectable()==list1) {
text1.setText(list1.getSelectedItem());
index=list1.getSelectedIndex();
}
}
public void actionPerformde(ActionEvent e) {
int n = list2.getSelectedIndex(),sum = 0;
String name = list2.getSelectedItem();
switch(index) {
case 0:
for(int i = 1;i<=n+1;i++) {
sum = sum+i;
}
case 1:
for(int i = 1;i<=n+1;i++) {
sum = sum*i;
}
case 2:
for(int i = 1;i<=n+1;i++) {
sum = sum+i*i*i;
}
break;
default:
sum = -100;
}
text2.setText(name +"等于"+sum);
}
}
public class WindowLi {
public static void main(String[] args) {
new WindowList();
}
}
当运行的时候,说“WindowList 不是抽象的,并且未覆盖 java.awt.event.ActionListener中的抽象方法 actionPerFormed(java.awt.event.ActionEvent) class WindowList extends Frame implements ItemListener,ActionListener“ 展开
展开全部
import java.awt.*;
import java.awt.event.*;
@SuppressWarnings("serial")
class WindowList extends Frame implements ItemListener,ActionListener {
List list1,list2;
TextArea text1,text2;
int index = 0;
WindowList() {
setLayout(new FlowLayout());
list1 = new List(3,false);
list2 = new List(3,false);
text1 = new TextArea(2,20);
text2 = new TextArea(2,20);
list1.add("计算1+2+...");
list1.add("计算1*1+2*2+...");
list1.add("计算1*1*1+2*2*2...");
for(int i=1;i<=100;i++) {
list2.add("前"+i+"项和");
}
add(list1);
add(list2);
add(text1);
add(text2);
list1.addItemListener(this);
list2.addActionListener(this);
setSize(400,200);
setVisible(true);
validate();
}
public void itemStateChanged(ItemEvent e) {
if(e.getItemSelectable()==list1) {
text1.setText(list1.getSelectedItem());
index=list1.getSelectedIndex();
}
}
public void actionPerformed(ActionEvent e) {
int n = list2.getSelectedIndex(),sum = 0;
String name = list2.getSelectedItem();
switch(index) {
case 0:
for(int i = 1;i<=n+1;i++) {
sum = sum+i;
}
case 1:
for(int i = 1;i<=n+1;i++) {
sum = sum*i;
}
case 2:
for(int i = 1;i<=n+1;i++) {
sum = sum+i*i*i;
}
break;
default:
sum = -100;
}
text2.setText(name +"等于"+sum);
}
}
一定要双击
应为单击时先触发第一个list1的itemStateChanged事件再单击一次才触发list2的itemStateChanged 事件,如果有必要的话 请把itemStateChanged改成别的事件 还有actionPerformed你写成actionPerformde请改过来 就行了
import java.awt.event.*;
@SuppressWarnings("serial")
class WindowList extends Frame implements ItemListener,ActionListener {
List list1,list2;
TextArea text1,text2;
int index = 0;
WindowList() {
setLayout(new FlowLayout());
list1 = new List(3,false);
list2 = new List(3,false);
text1 = new TextArea(2,20);
text2 = new TextArea(2,20);
list1.add("计算1+2+...");
list1.add("计算1*1+2*2+...");
list1.add("计算1*1*1+2*2*2...");
for(int i=1;i<=100;i++) {
list2.add("前"+i+"项和");
}
add(list1);
add(list2);
add(text1);
add(text2);
list1.addItemListener(this);
list2.addActionListener(this);
setSize(400,200);
setVisible(true);
validate();
}
public void itemStateChanged(ItemEvent e) {
if(e.getItemSelectable()==list1) {
text1.setText(list1.getSelectedItem());
index=list1.getSelectedIndex();
}
}
public void actionPerformed(ActionEvent e) {
int n = list2.getSelectedIndex(),sum = 0;
String name = list2.getSelectedItem();
switch(index) {
case 0:
for(int i = 1;i<=n+1;i++) {
sum = sum+i;
}
case 1:
for(int i = 1;i<=n+1;i++) {
sum = sum*i;
}
case 2:
for(int i = 1;i<=n+1;i++) {
sum = sum+i*i*i;
}
break;
default:
sum = -100;
}
text2.setText(name +"等于"+sum);
}
}
一定要双击
应为单击时先触发第一个list1的itemStateChanged事件再单击一次才触发list2的itemStateChanged 事件,如果有必要的话 请把itemStateChanged改成别的事件 还有actionPerformed你写成actionPerformde请改过来 就行了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
public void actionPerformde(ActionEvent e) {
这里是ed不是de.
这里是ed不是de.
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
错误是指没有实现按钮监听器里面的方法咯
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询