importjava.awt.*;importjava.awt.event.*;publicclassshiyan1extendsFrameimplementsActionListener{Buttonbutton;Labellabel;publicshiyan1(Strings){super(s);setLayout(newGridLa...
import java.awt.*;
import java.awt.event.*;
public class shiyan1 extends Frame implements ActionListener{
Button button;Label label;
public shiyan1(String s){
super(s);
setLayout(new GridLayout(1,2));
button=new Button("Button");
label=new Label("Label");
add(button);
add(label);
setSize(250,100);
setVisible(true);
}
public void actionPerformed(ActionEvent e){//这段要怎么变一下呢?
String msg=new String("Clicked");
if(e.getSource()==button){
label.setText(msg);
}
}
public static void main(String[]args){
shiyan1 shiyan=new shiyan1("My First Frame");
}
}
1.我现在的问题是点击button后,label的值不会变,但是我要达到的效果是,单击按钮Button,标签显示Clicked
2.ActionPerformed与mouseClicked有什么区别呢,在上面的程序中如果我把ActionPerformed换成mouseClicked就会报错
展开