【发布时间】:2014-04-02 23:18:27
【问题描述】:
在学习 Java GUI 的基础知识的同时,我试图弄清楚如何在 Swing GUI 的面板中使用 DrawPolygon。
这是生成 Swing GUI 面板的代码:
polygonArea = new javax.swing.JPanel(){
protected void poly(Graphics g) {
int xpoints[] = {35, 10, 25, 60, 20};
int ypoints[] = {105, 25, 5, 105, 25};
int xpoints2[] = {60, 70, 92, 80, 82};
int ypoints2[] = {105, 25, 5, 105, 25};
int xpoints3[] = {102, 98, 145, 107};
int ypoints3[] = {5, 105, 105, 100};
int npoints = 5;
int npointsl = 4;
g.fillPolygon(xpoints, ypoints, npoints);
g.fillPolygon(xpoints2, ypoints2, npoints);
g.fillPolygon(xpoints3, ypoints3, npointsl);
}
};
polygonArea.setBackground(new java.awt.Color(240, 240, 240));
基于从 Netbeans 生成的 GUI。我真的是 Java 新手,但是当我启动文件时,它看起来像这样:
http://i.stack.imgur.com/4KsIo.jpg
而不是单独显示的 poly 函数:
http://i.stack.imgur.com/XrAsK.png
抱歉,如果这是一个非常明显的错误,任何帮助将不胜感激!
(由于声誉问题,无法发布图片)
【问题讨论】:
标签: java swing user-interface drawing