怎样用java语言实现这些图形的设计~~~
发布网友
发布时间:2022-05-19 00:46
我来回答
共5个回答
热心网友
时间:2023-11-25 15:13
给你段代码参考下,用drawPolygon可以花多边形,drawRect画矩形
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Polygon;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class DrawDemo extends JPanel {
public void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g;
// 画大矩形
g2d.drawRect(10, 15, 200, 200);
// 小矩形
g2d.drawRect(15, 20, 90, 60);
g2d.drawRect(20, 30, 50, 40);
Polygon p = new Polygon();
p.addPoint(80,40);
p.addPoint(80,60);
p.addPoint(100,50);
g2d.drawPolygon(p);
}
public static void main(String[] args) {
DrawDemo rects = new DrawDemo();
JFrame frame = new JFrame("画图");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(rects);
frame.setSize(500, 400);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
}
热心网友
时间:2023-11-25 15:13
给你段代码参考下,用drawPolygon可以花多边形,drawRect画矩形
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Polygon;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class DrawDemo extends JPanel {
public void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g;
// 画大矩形
g2d.drawRect(10, 15, 200, 200);
// 小矩形
g2d.drawRect(15, 20, 90, 60);
g2d.drawRect(20, 30, 50, 40);
Polygon p = new Polygon();
p.addPoint(80,40);
p.addPoint(80,60);
p.addPoint(100,50);
g2d.drawPolygon(p);
}
public static void main(String[] args) {
DrawDemo rects = new DrawDemo();
JFrame frame = new JFrame("画图");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(rects);
frame.setSize(500, 400);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
}
热心网友
时间:2023-11-25 15:14
// 在内存中创建图象
int width=60, height=20;
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
// 获取图形上下文
Graphics g = image.getGraphics();
// 设定背景色
g.setColor(getRandColor(200,250));
g.fillRect(0, 0, width, height);
// 设定字体
g.setFont(new Font("Times New Roman",Font.PLAIN,18));
// 画边框
//g.setColor(new Color());
//g.drawRect(0,0,width-1,height-1);
用这个类来画就行了
热心网友
时间:2023-11-25 15:14
高山仰止
你都到这个境界了。。。。
热心网友
时间:2023-11-25 15:15
强悍!大哥级的啊。我还用NetBeans画text呢。
热心网友
时间:2023-11-25 15:14
// 在内存中创建图象
int width=60, height=20;
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
// 获取图形上下文
Graphics g = image.getGraphics();
// 设定背景色
g.setColor(getRandColor(200,250));
g.fillRect(0, 0, width, height);
// 设定字体
g.setFont(new Font("Times New Roman",Font.PLAIN,18));
// 画边框
//g.setColor(new Color());
//g.drawRect(0,0,width-1,height-1);
用这个类来画就行了
热心网友
时间:2023-11-25 15:14
高山仰止
你都到这个境界了。。。。
热心网友
时间:2023-11-25 15:15
用Autocad不好么
热心网友
时间:2023-11-25 15:15
强悍!大哥级的啊。我还用NetBeans画text呢。
热心网友
时间:2023-11-25 15:15
用Autocad不好么