当前位置: 技术问答>java相关
简单问题,在线等待,马上给分。
来源: 互联网 发布时间:2015-05-31
本文导语: 下面的程序有个错误,提示是: my83.ActionLis should be declared abstract;it does not define actionPerformed(java.awt.event.ActionEvent)in my83.ActionLis。 以下是程序: import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing...
下面的程序有个错误,提示是:
my83.ActionLis should be declared abstract;it does not define actionPerformed(java.awt.event.ActionEvent)in my83.ActionLis。
以下是程序:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.*;
public class my83 extends JFrame
{
String[] field={"姓名","语文","英语","数学","总分"};
Object[][] data={{"张小只",new Integer(80),new Integer(70),new Integer(60),new Integer(210)}};
DefaultTableModel tmodel=new DefaultTableModel(data,field);
JTable table1=new JTable(tmodel);
JButton button1=new JButton("添加");
JButton button2=new JButton("删除");
public static void main(String args[])
{
my83 frame1=new my83();
frame1.setTitle("use jtable insert or delete data");
frame1.setSize(500,490);
frame1.setVisible(true);
}
public my83()
{
super();
addWindowListener(new WindowAdapter ()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
getContentPane().setLayout(new FlowLayout());
getContentPane().add(new JScrollPane(table1));
button1.addActionListener(new ActionLis(1));
button2.addActionListener(new ActionLis(2));
getContentPane().add(button1);
getContentPane().add(button2);
}
class ActionLis implements ActionListener
{
int select;
public ActionLis(int select)
{
this.select=select;
}
public void actonPerformed(ActionEvent e)
{
if(select==1)
{
String name=JOptionPane.showInputDialog("请输入学生姓名:");
int score1=Integer.parseInt(
JOptionPane.showInputDialog("请输入语文成绩:"));
int score2=Integer.parseInt(
JOptionPane.showInputDialog("请输入英语成绩:"));
int score3=Integer.parseInt(
JOptionPane.showInputDialog("请输入数学成绩:"));
int total=score1+score2+score3;
Object newdata[]={name,new Integer(score1),new
Integer(score2),new Integer(score3),new Integer(total)};
tmodel.addRow(newdata);
}
else if(select==2)
{
int delrow=table1.getSelectedRow();
tmodel.removeRow(delrow);
}
}
}
}
my83.ActionLis should be declared abstract;it does not define actionPerformed(java.awt.event.ActionEvent)in my83.ActionLis。
以下是程序:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.*;
public class my83 extends JFrame
{
String[] field={"姓名","语文","英语","数学","总分"};
Object[][] data={{"张小只",new Integer(80),new Integer(70),new Integer(60),new Integer(210)}};
DefaultTableModel tmodel=new DefaultTableModel(data,field);
JTable table1=new JTable(tmodel);
JButton button1=new JButton("添加");
JButton button2=new JButton("删除");
public static void main(String args[])
{
my83 frame1=new my83();
frame1.setTitle("use jtable insert or delete data");
frame1.setSize(500,490);
frame1.setVisible(true);
}
public my83()
{
super();
addWindowListener(new WindowAdapter ()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
getContentPane().setLayout(new FlowLayout());
getContentPane().add(new JScrollPane(table1));
button1.addActionListener(new ActionLis(1));
button2.addActionListener(new ActionLis(2));
getContentPane().add(button1);
getContentPane().add(button2);
}
class ActionLis implements ActionListener
{
int select;
public ActionLis(int select)
{
this.select=select;
}
public void actonPerformed(ActionEvent e)
{
if(select==1)
{
String name=JOptionPane.showInputDialog("请输入学生姓名:");
int score1=Integer.parseInt(
JOptionPane.showInputDialog("请输入语文成绩:"));
int score2=Integer.parseInt(
JOptionPane.showInputDialog("请输入英语成绩:"));
int score3=Integer.parseInt(
JOptionPane.showInputDialog("请输入数学成绩:"));
int total=score1+score2+score3;
Object newdata[]={name,new Integer(score1),new
Integer(score2),new Integer(score3),new Integer(total)};
tmodel.addRow(newdata);
}
else if(select==2)
{
int delrow=table1.getSelectedRow();
tmodel.removeRow(delrow);
}
}
}
}
|
我知道了
你的actionPerformed
写错了
你的actionPerformed
写错了
|
大哥,你调用actionPerformed方法写错了
class里面定义的是actonPerformed
少了个i
==============================================================
如上所言,并非完全正确,请从建议的角度、用怀疑的眼光批判地接收
class里面定义的是actonPerformed
少了个i
==============================================================
如上所言,并非完全正确,请从建议的角度、用怀疑的眼光批判地接收
|
用下面的代替你的那句话。
public void actionPerformed(ActionEvent e)
public void actionPerformed(ActionEvent e)