余慧吧 关注:45贴子:2,748
  • 7回复贴,共1

噫,好闲啊

只看楼主收藏回复

终于不会悲伤了,天气不错啊


来自Android客户端1楼2015-09-12 15:56回复
    撒比


    IP属地:江苏来自Android客户端2楼2015-09-20 19:26
    收起回复
      package button;
      import java.awt.Color;
      import java.awt.event.ActionEvent;
      import java.awt.event.ActionListener;
      import javax.swing.JButton;
      import javax.swing.JFrame;
      import javax.swing.JPanel;
      @SuppressWarnings("serial")
      public class ButtonFrame extends JFrame{
      private JPanel buttonPanel;
      private static final int DEFAULT_WIDTH = 300;
      private static final int DEFAULT_HEDITH = 200;
      public ButtonFrame(){
      setSize(DEFAULT_WIDTH, DEFAULT_HEDITH);
      JButton yellowButton = new JButton("Yellow");
      JButton blueButton = new JButton("Blue");
      JButton redButton = new JButton("Red");
      buttonPanel = new JPanel();
      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楼2015-11-04 20:09
      收起回复