package entity;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Exec {
public static void main(String args[])
{
DemoWindow demo=new DemoWindow(" ");
demo.setVisible(true);
demo.setSize(300,200);
}
}
class DemoWindow extends JFrame implements ActionListener{
JButton jb1=new JButton("红");
JButton jb2=new JButton("绿");
JButton jb3=new JButton("蓝");
JPanel jp=new JPanel();
public DemoWindow(String title)
{
super(title);
setLayout(new GridLayout(1,0));
setLocation(400,300);
jp.add(jb1);
jp.add(jb2);
jp.add(jb3);
add(jp);
jb1.setBackground(Color.red);
jb2.setBackground(Color.green);
jb3.setBackground(Color.blue);
jb1.addActionListener(this);
jb2.addActionListener(this);
jb3.addActionListener(this);
}
public void actionPerformed(ActionEvent e) {
if(e.getSource()==jb1)
{
jp.setBackground(Color.red);
}
if(e.getSource()==jb2)
{
jp.setBackground(Color.green);
}
if(e.getSource()==jb3)
{
jp.setBackground(Color.blue);
}
}
}
其实还是背景色嘛 只不过是圆形的有范围大小的背景色
如果你一定不要背景色.. 就加个背景色 然后给圆加前景色就是..