怎么做出图中的图形,求给出具体代码,谢谢了
2个回答
展开全部
按照你的要求编写的Polygon和Polyline的Java程序如下
import java.awt.Graphics;
import javax.swing.JFrame;
public class D extends JFrame{
int[] xPoints={40,70,60,45,20};
int[] yPoints={20,40,80,45,60};
int nPoints=5;
D(){
super("Polygon and Polyline");
setSize(400,200);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
setVisible(true);
}
public void paint(Graphics g){
super.paint(g);
g.translate(50,50);
g.drawPolygon(xPoints, yPoints, nPoints);
g.translate(200,0);
g.drawPolyline(xPoints, yPoints, nPoints);
}
public static void main(String[] args) {
new D();
}
}
运行结果
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |