最近用jfreechart做图表,貌似jfreechart没有属性支持背景多中颜色,所以想用java panit什么的来画一个,大家有现成的Demo呗,有的话赐教一下吧   PS:不要渐变色,要的是区域三种颜色,如下图的这种效果,谢谢

解决方案 »

  1.   

    你要的效果import javax.swing.*;
    import java.awt.*;
    class ColorPanel extends JPanel
    {
    Color c1 =new Color(34,177,76);
    Color c2 =new Color(0,162,232);
    Color c3 =new Color(237,28,36);
    @Override
    public void paintComponent(Graphics g)
    {
    super.paintComponent(g);
    Dimension d = getSize();
    g.setColor(c1);
    g.fillRect(0,0,(int)d.getWidth(),(int)d.getHeight()/3);
    g.setColor(c2);
    g.fillRect(0,(int)d.getHeight()/3,(int)d.getWidth(),(int)d.getHeight()/3);
    g.setColor(c3);
    g.fillRect(0,(int)(d.getHeight()*(1.99)/3),(int)d.getWidth(),(int)d.getHeight()/3);
    }
    }
    public class ColorFrame extends JFrame
    {
    ColorFrame()
    {
    setBounds(0,0,800,600);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JPanel panel = new ColorPanel();
    add(panel);
    setVisible(true);
    } public static void main(String[] args) 
    {
    new ColorFrame();
    System.out.println("Hello World!");
    }
    }