cacaopie 2015-05-14 12:57 采纳率: 14.3%
浏览 1560
已采纳

这个程序有问题吗?为什么编译不了?我是初学者,请各位大神帮我解决一下吧,谢谢了啊!

图片说明package button;

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

public class ButtonFrameTest {

/**
 * @param args
 */
public static void main(String[] args) {
    // TODO Auto-generated method stub
    EventQueue.invokeLater(new Runnable()
       {
           public void run()
           {
               JFrame frame=new ButtonFrame();
               frame.setTitle("ButtonFrame");
               frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
               frame.setVisible(true);
           }
       });
}

}
class ButtonFrame extends JFrame
{
private JPanel buttonPanel;
private static final int DEFAULT_WIDTH=300;
private static final int DEFAULT_HEIGHT=200;

public ButtonFrame()
{
    setSize(DEFAULT_WIDTH,DEFAULT_HEIGHT);

    JButton yellowButton=new JButton("Yellow");
    JButton blueButton=new JButton("Blue");
    JButton redButton=new JButton("Red");

    buttonPanel.add(yellowButton);
    buttonPanel.add(blueButton);
    buttonPanel.add(redButton);

    add(buttonPanel);

    ColorAction yellowAction=new ColorAction(Color.YELLOW);
    ColorAction blueAction=new ColorAction(Color.BLUE);
    ColorAction redAction=new ColorAction(Color.RED);

    yellowButton.addActionListener(yellowAction);
    blueButton.addActionListener(blueAction);
    redButton.addActionListener(redAction);

}
private class ColorAction implements ActionListener
{
    private Color backgroundColor;
    public ColorAction(Color c)
    {
        backgroundColor=c;
    }
    public void actionPerformed(ActionEvent event)
    {
        buttonPanel.setBackground(backgroundColor);
    }
}

}

  • 写回答

3条回答 默认 最新

  • danielinbiti 2015-05-14 13:07
    关注

    编译没问题,把你的编译错误贴出来

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度