Java怎么画出这样的背景 最近用jfreechart做图表,貌似jfreechart没有属性支持背景多中颜色,所以想用java panit什么的来画一个,大家有现成的Demo呗,有的话赐教一下吧 PS:不要渐变色,要的是区域三种颜色,如下图的这种效果,谢谢 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 你要的效果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!"); }} 直接运行jar文件出错,Cannot find the main class……求教 java 怎么获取硬件信息 关于netbeans的使用 java初学者,向各位前辈请教:有关异常处理的问题 java程序中的一个问题 JFrame中添加面板 关于Resource的获得问题(解决马上结贴) 关于socket的问题!谢谢 /** linux下怎么使用odbc?myodbc怎么配?怎么用? */ 小弟最近刚看完《java编程思想》,目前比较迷茫,还不知道自己到底应该往哪个方向发展? java中有关正则表达式的一个小问题 Eclipse 常用的快捷键有哪些呢
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!");
}
}