package FRAME;
import java.awt.Color;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
public class UseFrame8 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Frame8 obj new Frame8("FRAMME");
}
}
class Frame8 extends Frame implements ActionListener
{
String title;
public Frame8(String title)
{
super(title);
setTitle(title);
setVisible(true);
setSize(600,600);
setBackground(Color.CYAN);
JButton btn1= new JButton("Click me");
add(btn1);
btn1.addActionListener(this);
btn1.setBounds(50, 50, 50, 50);
MyWindowAdapter obj2= new MyWindowAdapter();
}
public void actionPerformed(ActionEvent e)
{
this.setBackground(Color.CYAN);
}
}
答案 0 :(得分:0)
按钮完全适用于你如何设置他。你只是点击它没有看到任何差异,因为你的背景已经是青色。
在actionPerformed中试试这个:
this.setBackground(Color.BLACK);