import javax.swing.*; import java.applet.Applet; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class Figure3D extends Applet { private final static int[][][] figures = new int[4][][]; static { // Первая проекция figures[0] = new int[][]{ {30, 60, 30, 60}, {0, 0, 20, 0}, {0, 0, 0, 40}, {0, 20, 70, 20}, {40, 20, 70, 20}, {70, 0, 70, 40}, {20, 10, 50, 10}, {20, 0, 20, 10}, {50, 0, 50, 10}, {50, 0, 70, 0}, {55, 0, 55, 20}, {0, 40, 70, 40}, }; // Вторая проекция figures[1] = new int[][]{ {130, 60, 130, 60}, {0, 0, 15, 0}, {0, 0, 0, 40}, {15, 0, 15, 20}, {0, 40, 45, 40}, {15, 0, 45, 20}, {15, 20, 45, 20}, {45, 20, 45, 40}, }; // Третья проекция figures[2] = new int[][]{ {30, 130, 30, 130}, {0, 0, 70, 0}, {0, 15, 70, 15}, {0, 0, 0, 45}, {70, 0, 70, 45}, {0, 45, 70, 45}, {20, 0, 20, 15}, {50, 0, 50, 15}, {55, 15, 55, 45}, }; } @Override public void init() { JButton button1 = new JButton("Построить!"); button1.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { Graphics canvas = getGraphics(); canvas.setColor(Color.blue); for (int i = 0; i < 3; i++) { int[][] f = figures[i]; for (int j = 1; j < figures[i].length; j++) { canvas.drawLine(f[0][0] + f[j][0], f[0][1] + f[j][1], f[0][2] + f[j][2], f[0][3] + f[j][3]); } } int x0 = 110; int y0 = 110; canvas.setColor(Color.red); canvas.setFont(new Font("Areal", 1, 10)); canvas.drawString("Ортогональные проекции", 25, 270); canvas.drawString("X", x0 - 80, y0); canvas.drawString("Y", x0 + 100, y0); canvas.drawString("Z", x0 + 10, y0 - 90); canvas.drawString("Y", x0 + 10, y0 + 110); canvas.setColor(Color.black); canvas.drawLine(115, 220, 115, 20); canvas.drawLine(25, 115, 220, 115); canvas.setColor(Color.green); canvas.drawRect(10, 5, 220, 300); } }); this.add(button1); } }