import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class SOfile extends JFrame
{
public JTextField filename = new JTextField(),dir = new JTextField();
public JButton open = new JButton("Open"),save = new JButton("Save");
public SOfile()
{
JPanel p = new JPanel();
p.add(open);
open.addActionListener(new Open());
p.add(save);
save.addActionListener(new Save());
Container cp = getContentPane();
cp.add(p,BorderLayout.SOUTH);
filename.setEditable(false);
dir.setEditable(false);
p = new JPanel();
p.setLayout(new GridLayout(2,1));
p.add(filename);
p.add(dir);
cp.add(p,BorderLayout.NORTH);
}
class Open implements ActionListener
{ public void actionPerforemd(ActionEvent e)
{
JFileChooser fc = new JFileChooser();
int rval = fc.showOpenDialog(SOfile.this);
if (rval == JFileChooser.APPROVE_OPTION)
{
filename.setText(fc.getSelectedFile().getName());
dir.setText(fc.getCurrentDirectory().toString());
}
if (rval == JFileChooser.CANCEL_OPTION)
{
filename.setText("You pressed cancel");
dir.setText("");
}
}
}
class Save implements ActionListener
{ public void actionPerforemd(ActionEvent e)
{
JFileChooser fc = new JFileChooser();
int rval = fc.showOpenDialog(SOfile.this);
if (rval == JFileChooser.APPROVE_OPTION)
{
filename.setText(fc.getSelectedFile().getName());
dir.setText(fc.getCurrentDirectory().toString());
}
if (rval == JFileChooser.CANCEL_OPTION)
{
filename.setText("You pressed cancel");
dir.setText("");
}
}
} public static void main(String[] args)
{
new SOfile();
}
}
错误如下:
SOfile.Open is not abstract and dose not override abstract method actionPerformed
SOfile.Save is not abstract and dose not override abstract method actionPerformed
import java.awt.*;
import java.awt.event.*;
public class SOfile extends JFrame
{
public JTextField filename = new JTextField(),dir = new JTextField();
public JButton open = new JButton("Open"),save = new JButton("Save");
public SOfile()
{
JPanel p = new JPanel();
p.add(open);
open.addActionListener(new Open());
p.add(save);
save.addActionListener(new Save());
Container cp = getContentPane();
cp.add(p,BorderLayout.SOUTH);
filename.setEditable(false);
dir.setEditable(false);
p = new JPanel();
p.setLayout(new GridLayout(2,1));
p.add(filename);
p.add(dir);
cp.add(p,BorderLayout.NORTH);
}
class Open implements ActionListener
{ public void actionPerforemd(ActionEvent e)
{
JFileChooser fc = new JFileChooser();
int rval = fc.showOpenDialog(SOfile.this);
if (rval == JFileChooser.APPROVE_OPTION)
{
filename.setText(fc.getSelectedFile().getName());
dir.setText(fc.getCurrentDirectory().toString());
}
if (rval == JFileChooser.CANCEL_OPTION)
{
filename.setText("You pressed cancel");
dir.setText("");
}
}
}
class Save implements ActionListener
{ public void actionPerforemd(ActionEvent e)
{
JFileChooser fc = new JFileChooser();
int rval = fc.showOpenDialog(SOfile.this);
if (rval == JFileChooser.APPROVE_OPTION)
{
filename.setText(fc.getSelectedFile().getName());
dir.setText(fc.getCurrentDirectory().toString());
}
if (rval == JFileChooser.CANCEL_OPTION)
{
filename.setText("You pressed cancel");
dir.setText("");
}
}
} public static void main(String[] args)
{
new SOfile();
}
}
错误如下:
SOfile.Open is not abstract and dose not override abstract method actionPerformed
SOfile.Save is not abstract and dose not override abstract method actionPerformed
实现ActionListener接口要实现
public void actionPerformed(ActionEvent e)方法
看你写的是什么
public void actionPerforemd(ActionEvent e)
SOfile.Open is not abstract and dose not override abstract method actionPerformed
SOfile.Save is not abstract and dose not override abstract method actionPerformed 楼上的说的有点过了
关键是出一次错就要记住,下次碰到能已最快的速度反应过来知道是什么错误
我会注意的。。
谢谢allen830826的批评指正。
更感谢husl的鼓励和鞭策。
谢谢