程序如下:
import java.awt.*;
import java.awt.event.*;
public class frame1 extends Frame implements ActionListener
{
Label L;
Button B;
frame1()
{
super("ldfkjsa");
setVisible(true);
L=new Label("");
B=new Button("显示");
add(B);
add(L);
pack();
B.addActionListener(this);
}
public void ActionPerformed(ActionEvent e)
{
if(e.getSource()==B)
{
L.setText("我出来了");
}
}
public static void main(String s[])
{
frame1 f1=new frame1();
}
}
编译的时候出现这样的错误:
frame1 is not abstract and does not override abstract method actio frame.java
import java.awt.*;
import java.awt.event.*;
public class frame1 extends Frame implements ActionListener
{
Label L;
Button B;
frame1()
{
super("ldfkjsa");
setVisible(true);
L=new Label("");
B=new Button("显示");
add(B);
add(L);
pack();
B.addActionListener(this);
}
public void ActionPerformed(ActionEvent e)
{
if(e.getSource()==B)
{
L.setText("我出来了");
}
}
public static void main(String s[])
{
frame1 f1=new frame1();
}
}
编译的时候出现这样的错误:
frame1 is not abstract and does not override abstract method actio frame.java
修改成
public void actionPerformed(ActionEvent e)
import java.awt.event.*;
import javax.swing.*;
public class frame1 extends JFrame implements ActionListener
{
Label L;
Button B;
JPanel p=new JPanel();frame1()
{
super( "ldfkjsa ");
L=new Label(" ");
B=new Button( "显示 ");
p.add(B);
p.add(L);
this.add(p);
B.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==B)
{
L.setText( "我出来了 ");
}
}
public static void main(String s[])
{
frame1 f1=new frame1();
f1.setSize(400,300);
f1.setVisible(true);
}
}