如何使用 Java2D 绘制一个简单的 3D 房子?我想画房子的侧壁,让它看起来像一个简单的 3D 绘图。
// House.java
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GradientPaint;
import java.awt.geom.Rectangle2D;
public class House extends Canvas{
House(){
setSize(800,600);
}
public void paint(Graphics g){
// house - foundation
g.setColor(new Color(0xCDBE70));
g.fillRect(148,500,304,50);
// house - front
g.setColor(new Color(0xFFEC8B));
g.fillRect(150,350,300,150);
// house - side
}
}
//ShowHouse.java
import java.awt.Frame;
import java.awt.AWTEvent;
import java.awt.event.WindowEvent;
public class ShowHouse extends Frame{
public static void main(String arg[]){
new ShowHouse();
}
ShowHouse(){
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
setLocation(250,50);
House canvas = new House();
add(canvas);
pack();
setVisible(true);
}
public void processWindowEvent(WindowEvent event){
if(event.getID() == WindowEvent.WINDOW_CLOSING)
System.exit(0);
}
}