本帖最后由 吃阁子的猫 于 2013-8-15 14:56 编辑
public class Test3 {
/**
* @param args
*/
public static void main(String[] args) {
Test03_frame frame = new Test03_frame();
frame.setVisible(true);
}
}
class Test03_frame extends Frame{
/**
*
*/
private static final long serialVersionUID = 1L;
private Button redbutton;
private Button greenbutton;
private Button bulebutton;
Test03_frame(){
generateUI();
handEvent();
}
private void handEvent() {
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
MouseListener ms = new MouseAdapter(){
public void mouseEntered(MouseEvent e) {
Button button = (Button)e.getSource();
Color c = button.getBackground();
setBackground(c);
}
public void mouseExited(MouseEvent e) {
Button button = (Button)e.getSource();
setBackground(c); }
public void mouseClicked(MouseEvent e) {
Button button = (Button)e.getSource();
}
};
}
private void generateUI() {
setTitle("第三个窗口");
setSize(400,300);
setLocation(300,200);
setLayout(new FlowLayout());
redbutton = new Button("红");
greenbutton = new Button("绿");
bulebutton = new Button("蓝");
add(redbutton);
add(greenbutton);
add(bulebutton);
setVisible(true);
}
}
红色部分报错,但是有结果,为什么呢? |