码迷,mamicode.com
首页 > 其他好文 > 详细

颜色改变

时间:2019-05-31 13:18:41      阅读:100      评论:0      收藏:0      [点我收藏+]

标签:listener   jpa   方法   yellow   win   enter   eve   ide   自动生成   

package bbb;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;
public class myframe implements ActionListener{
    JFrame f;
    JPanel p1,p2;
    JButton b1,b2,b3;
public myframe(){
    JFrame f=new JFrame("颜色改变");
    JPanel p1= new JPanel();
    JPanel p2= new JPanel();
    p2.setBackground(Color.yellow);
    JButton b1=new JButton("红色");
    b1.addActionListener(this);
    JButton b2=new JButton("绿色");
    b2.addActionListener(this);
    JButton b3=new JButton("蓝色");
    b3.addActionListener(this);
    f.setLayout(new BorderLayout());
      p1.add(b1);
      p1.add(b2);
      p1.add(b3);
      f.add(p1,BorderLayout.NORTH);
      f.add(p2,BorderLayout.CENTER);
    f.setSize(500,500);
    f.setVisible(true);
}
public  static void main(String []args){
    new myframe();
}
@Override
public void actionPerformed(ActionEvent arg0) {
    // TODO 自动生成的方法存根
    if(arg0.getSource() == b1)
    p2.setBackground(Color.red);
    else if(arg0.getSource() == b2)
    p2.setBackground(Color.green);
    else if(arg0.getSource() == b3)
    p2.setBackground(Color.blue);
}
}

 

颜色改变

标签:listener   jpa   方法   yellow   win   enter   eve   ide   自动生成   

原文地址:https://www.cnblogs.com/YShen0/p/10954545.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!