倒数低2行:setBackground(bgColor);
这个方法怎么不是"点"出来的 就直接能用呢?import java.awt.*;
import java.awt.event.*;
public class MyButton {
public static void main(String[]args){
MyButtonFrame frm=new MyButtonFrame();
frm.show();
}
}
class MyButtonFrame extends Frame{
public MyButtonFrame(){
setTitle("测试");
setSize(300,200);
MyButtonPanel Panel=new MyButtonPanel();
add(Panel);
}
}
class MyButtonPanel extends Panel{
public MyButtonPanel(){
Button bButton=new Button("蓝");
add(bButton);
MyListenerAction bAction=new MyListenerAction(Color.blue);
bButton.addActionListener(bAction);
}
private class MyListenerAction implements ActionListener{
private Color bgColor;
public MyListenerAction(Color c){
bgColor=c;
}
public void actionPerformed(ActionEvent event){
setBackground(bgColor);
repaint();
}
}
}
这个方法怎么不是"点"出来的 就直接能用呢?import java.awt.*;
import java.awt.event.*;
public class MyButton {
public static void main(String[]args){
MyButtonFrame frm=new MyButtonFrame();
frm.show();
}
}
class MyButtonFrame extends Frame{
public MyButtonFrame(){
setTitle("测试");
setSize(300,200);
MyButtonPanel Panel=new MyButtonPanel();
add(Panel);
}
}
class MyButtonPanel extends Panel{
public MyButtonPanel(){
Button bButton=new Button("蓝");
add(bButton);
MyListenerAction bAction=new MyListenerAction(Color.blue);
bButton.addActionListener(bAction);
}
private class MyListenerAction implements ActionListener{
private Color bgColor;
public MyListenerAction(Color c){
bgColor=c;
}
public void actionPerformed(ActionEvent event){
setBackground(bgColor);
repaint();
}
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货