jpanel做出不规则图像比如说是等腰梯形

ykf23278 2010-01-12 09:02:30
要求用JDK1.5以下的版本做出一个不规则图形
要求的效果是等腰梯形,上长为400,底长为360,高为20,腰的度数为45度
期待高手解答
不胜感激
...全文
307 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
ykf23278 2010-01-13
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 bayougeng 的回复:]
java要是这点事都不能做,早被唾弃了。
[/Quote]
就是AIP不熟悉了,要用的时候就是难找
找到了就出来了
哎 是我自己的悲剧了
nj_dobetter 2010-01-12
  • 打赏
  • 举报
回复
drawPolygon()
顶!
ykf23278 2010-01-12
  • 打赏
  • 举报
回复
将多边形填充颜色

protected void paintComponent(Graphics g) {
Graphics2D g2d = (Graphics2D) g.create();
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
g2d.setColor(Color.RED);
int x[] = { 0, 400, 380, 19, 0 };
int y[] = { 0, 0, 19, 19, 0 };
int nPoints = 4;
Polygon poly=new Polygon(x, y, nPoints);
g2d.fillPolygon(poly);
g2d.drawPolygon(poly);
}
bobo364 2010-01-12
  • 打赏
  • 举报
回复
好了我mark下这个问题,有人再问就直接复制了
ykf23278 2010-01-12
  • 打赏
  • 举报
回复
哈哈 总算被我找到方法了,哎 搞个东西真难的


public class NewPanel extends JPanel {

public NewPanel() {
this.setLayout(null);
this.setSize(400, 20);
this.setVisible(true);
this.setLocation(100, 50);
}

protected void paintComponent(Graphics g) {
Graphics2D g2d = (Graphics2D) g.create();
int h = this.getHeight();
int w = this.getWidth();
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
/*RoundRectangle2D.Float r2d = new RoundRectangle2D.Float(0, 0, w, h, h,
h);*/
Shape clip = g2d.getClip();
// g2d.setColor(Color.RED);
// g2d.setBackground(Color.RED);
//g2d.clip(r2d);
// g2d.fillRect(0, 0, w, h);
g2d.setClip(clip);
//g2d.drawRoundRect(0, 0, w-1, h-1, 40, h);
int x[]={0,400,380,19,0};
int y[]={0,0,19,19,0};
int nPoints=4;
g2d.drawPolygon(x, y, nPoints);
}

}
ykf23278 2010-01-12
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 jeikyzhou 的回复:]
你的要求是在dialog/frame 里面画一个不规则图形,还是要整个dialog/frame是不规则的?
[/Quote]
是用JPanel画出一个不图形,再放到JFrame中去,最好是画出来的,不要放个图片那地方
非常感谢你的关注
jeikyzhou 2010-01-12
  • 打赏
  • 举报
回复
你的要求是在dialog/frame 里面画一个不规则图形,还是要整个dialog/frame是不规则的?
ykf23278 2010-01-12
  • 打赏
  • 举报
回复
怎么没有人回答下哦
bayougeng 2010-01-12
  • 打赏
  • 举报
回复
java要是这点事都不能做,早被唾弃了。

62,621

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧