⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 projection.java

📁 立方体透视投影绘图程序
💻 JAVA
字号:
package pjt;

import java.awt.*;
import java.awt.event.*;

import javax.swing.*;

public class Projection extends JFrame {

	private static final long serialVersionUID = 1L;

	JLabel l, l1, l2, l3, l4, l5;
	JTextField tf1, tf2, tf3, tf4;
	JButton b1, b2;
	Panel p;
	ProCanvas pc;
	Cube c;
	
	public Projection() {
		l = new JLabel("请输入视点");
		l.setBounds(3, 5, 90, 25);
		l1 = new JLabel("x:");
		l1.setBounds(3, 35, 20, 25);
		l2 = new JLabel("y:");
		l2.setBounds(3, 65, 20, 25);
		l3 = new JLabel("z:");
		l3.setBounds(3, 95, 20, 25);
		l4 = new JLabel("旋转角度:");
		l4.setBounds(3, 159, 90, 25);
		l5 = new JLabel("       鼠标左键点中\n图形自动旋转,抬起后停止");
		l5.setBounds(3, 245, 90, 50);
		tf1 = new JTextField(5);
		tf1.setBounds(25, 35, 50, 25);
		tf2 = new JTextField(5);
		tf2.setBounds(25, 65, 50, 25);
		tf3 = new JTextField(5);
		tf3.setBounds(25, 95, 50, 25);
		tf4 = new JTextField(5);
		tf4.setBounds(13, 185, 50, 25);
		b1 = new JButton("确定");
		b1.setBounds(13, 125, 60, 25);
		b1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if (tf1.getText().equals("")||tf2.getText().equals("")||tf3.getText().equals(""))
					JOptionPane.showMessageDialog(null, "请输入视点坐标!", "提示", JOptionPane.ERROR_MESSAGE); 
				else {
					int x, y, z;
					x = Integer.parseInt(tf1.getText());
					y = Integer.parseInt(tf2.getText());
					z = Integer.parseInt(tf3.getText());
					pc.setPlace(x, y, z);
					pc.project();
					pc.repaint();
				}
			}
		});
		b2 = new JButton("旋转");
		b2.setBounds(13, 215, 60, 25);
		b2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if (tf4.getText().equals(""))
					JOptionPane.showMessageDialog(null, "请输入旋转角度!", "提示", JOptionPane.ERROR_MESSAGE); 
				else {
					c.setTheta(Double.parseDouble(tf4.getText()));
					c.whirl();
					pc.project();
					pc.repaint();
				}
			}
		});
		p = new Panel();
		p.setLayout(null);
		p.setSize(100, 500);
		p.add(l);
		p.add(l1);
		p.add(tf1);
		p.add(l2);
		p.add(tf2);
		p.add(l3);
		p.add(tf3);
		p.add(b1);
		p.add(l4);
		p.add(tf4);
		p.add(b2);
		add(l5, "South");
		pc = new ProCanvas();
		pc.setBackground(Color.WHITE);
		add(pc, "Center");
		add(p, "East");

		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}
	
	public void create() {
		c = new Cube();
		c.create();
		pc.setPlace(200, 300, 600);
		pc.setPoint(c.px, c.py, c.pz);
		pc.project();
		pc.c = c;
		tf1.setText("200");
		tf2.setText("300");
		tf3.setText("600");
		tf4.setText("0");
	}
	
	public static void main(String[] args) {
		Projection main = new Projection();
		main.setTitle("三维透视投影——立方体");
		main.setSize(700, 600);
		main.setVisible(true);
		main.create();
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -