一个java程序的错误 高人指点

来源:百度知道 编辑:UC知道 时间:2024/07/07 08:28:29
想实现的功能:
点击按钮,改变label的颜色和文字,
并添加另一个label

程序编译通过 但运行出错.
望高人指点..

import java.awt.event.*;
import java.awt.*;
public class repaintDemo extends Frame implements ActionListener{
Label label1;
Label label2;
Button bt;
Panel p;
public repaintDemo(){
p=new Panel();
Label label1=new Label("徐雄皓是猪子!");
label1.setBackground(Color.red);
label1.setForeground(Color.blue);
Label label2=new Label("000");
Button bt=new Button("转换");
bt.addActionListener(this);
this.setLayout(new GridLayout(3,1,5,5));
this.add(label1);
this.add(bt);
this.add(p);
this.setSize(200,200);
this.setVisible(true);
this.setResizable(false);

addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
}

public void actionPerform

【【【【【错在没有弄清楚局部变量和成员变量
还有,类名请大写开头字母】】】】】
import java.awt.event.*;
import java.awt.*;

public class RepaintDemo extends Frame implements ActionListener {
Label label1;

Label label2;

Button bt;

Panel p;

public RepaintDemo() {
p = new Panel();
label1 = new Label("徐雄皓是猪子!");
label1.setBackground(Color.red);
label1.setForeground(Color.blue);
label2 = new Label("000");
bt = new Button("转换");
bt.addActionListener(this);
this.setLayout(new GridLayout(3, 1, 5, 5));
this.add(label1);
this.add(bt);
this.add(p);
this.setSize(200, 200);
this.setVisible(true);
this.setResizable(false);

addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEven