重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
到你安装的JDK目录先找demo文件夹看看...如果没有的话,那就安装一个带有demo的JDK版本。
创新互联专业为企业提供常宁网站建设、常宁做网站、常宁网站设计、常宁网站制作等企业网站建设、网页设计与制作、常宁企业网站模板建站服务,10多年常宁做网站经验,不只是建网站,更提供有价值的思路和整体网络服务。
这里全都是官方示例,绝对值得参考学习。
可参考 孙博文 的一本书 分形算法与程序设计: Java实现 里面有3D的内容
貌似要下载 JAVA3D 的msi安装包 解压后得到jar包 JAVA 3D已经被淘汰 可能有点难找
用Java3D编程就行了 你先把那书上关于3D的代码 稍微看一下 编程的思路也就是 先建立一个场景(有光) 然后空间描点 画线 着色 之类的 可以参考具体的Java 3D 的书 貌似大多是英文的
编程也可以参考官方API文档
如果认可,请加分到100分,谢谢
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.util.*;
/**
* 点击按钮绘制圆点
* @author Hardneedl
*/
final class PaintDemo extends JFrame {
public String getTitle() {return "PaintDemo";}
static private final Dimension size = new Dimension(600,400);
public Dimension getPreferredSize() {return size;}
public Dimension getMaximumSize() {return size;}
public Dimension getMinimumSize() {return size;}
public Dimension getSize(){return size;}
/*画笔*/
private interface Brush {void paint(Graphics g);}
private class _Brush implements Brush,Observer {
private Point p;
public void paint(Graphics g) {
if(p==null)return;
Graphics g2=g.create();
//抗锯齿
((Graphics2D)g2).setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2.setColor(Color.YELLOW);
g2.fillArc(p.x,p.y, 10,10 ,0,360);
g2.dispose();
}
public void update(Observable o, Object arg) {
if (arg instanceof Point)p= (Point) arg;
}
}
private class PaintCanvas extends JComponent implements Observer{
private BufferedImage img = new BufferedImage(400,300,BufferedImage.TYPE_INT_RGB);
private Brush b;
private PaintCanvas(Brush b) {this.b=b;}
protected void paintComponent(Graphics g) {
super.paintComponent(g);
b.paint(img.getGraphics());
g.drawImage(img,0,0,this);
}
public void update(Observable o, Object arg) {
if("REPAINT".equals(arg)) repaint();
}
}
private class DrawAction extends AbstractAction{
private Point p = new Point(30,100);
private Observable observable = new Observable(){
public void notifyObservers(Object arg) {
setChanged();
super.notifyObservers(arg);
}
};
private DrawAction(Observer... observers) {
super("Draw Circle");
if(observers!=null)
for(Observer o : observers)
observable.addObserver(o);
}
public void actionPerformed(ActionEvent e) {
observable.notifyObservers(p);
observable.notifyObservers("REPAINT");
p.x+=30;p.y+=20;
}
}
PaintDemo() throws HeadlessException {
init();
attachListeners();
doLay();
}
private PaintCanvas canvas;
private _Brush brush;
private void init(){
canvas = new PaintCanvas(brush=new _Brush());
}
private void attachListeners(){
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
private void doLay(){
Container container = getContentPane();
container.add(new JButton(new DrawAction(brush,canvas)),BorderLayout.NORTH);
container.add(canvas,BorderLayout.CENTER);
pack();
setVisible(true);
}
public static void main(String[]args) {
System.setProperty("swing.defaultlaf","com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
SwingUtilities.invokeLater(
new Runnable(){
public void run() {
new PaintDemo();
}
}
);
}
}