java代码实现二维图形 java代码实现二维图形转换
JAVA程序编写。 定义一个抽象类shape ,用来表示一般图形。
Java程序:
成都创新互联公司是一家专业提供南康企业网站建设,专注与成都网站设计、做网站、H5响应式网站、小程序制作等业务。10年已为南康众多企业、政府机构等服务。创新互联专业的建站公司优惠进行中。
public class Main {
public static void main(String[] args) {
Shape s = null;
s = new Circle(3);
System.out.println("圆的面积:" + s.area());
System.out.println("圆的周长:" + s.perimeter());
}
}
/**
* 形状类:抽象类
* @author developer
* @version 2017.05.23
*/
abstract class Shape {
/**
* 计算形状的面积
* @return 形状的面积
*/
abstract double area();
/**
* 计算形状的周长
* @return 形状的周长
*/
abstract double perimeter();
}
/**
* 圆类
* @author developer
* @version 2017.05.23
*/
class Circle extends Shape {
/**
* 半径
*/
protected double radius;
/**
* 构造方法
* @param radius 半径
*/
public Circle(double radius) {
this.radius = radius;
}
@Override
double area() {
return Math.PI * radius * radius;
}
@Override
double perimeter() {
return 2 * Math.PI * radius;
}
}
运行测试:
圆的面积:28.274333882308138
圆的周长:18.84955592153876
Java绘制二维折线图
MapCalendar,Double map= new HashMapCalendar,Double();
时间和值组成的集合。
用JAVA语言写一个二维平面图形(如长方形)的平移,旋转,缩放的程序.
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.geom.*;
/**
* @author Hardneedl
*/
class RectTransform extends JFrame {
private static final Dimension minSize = new Dimension(300, 200);
private static final Dimension maxSize = new Dimension(1024, 768);
private static final Dimension preferredSize = new Dimension(600, 400);
public Dimension getMaximumSize() {return maxSize;}
public Dimension getMinimumSize() {return minSize;}
public Dimension getPreferredSize() {return preferredSize;}
public String getTitle() {return "Frame Title";}
private AffineTransform af = new AffineTransform();
private Stroke stroke = new BasicStroke(2.0f);
private Rectangle rct = new Rectangle(40,140,200,140);
private JComponent canvas = new JComponent(){
protected void paintComponent(Graphics g) {
super.paintComponent(g);
g.setColor(Color.BLACK);
g.fillRect(0,0,getWidth(),getHeight());
Graphics2D g2d = (Graphics2D)g.create();
g2d.setColor(Color.YELLOW);
g2d.setTransform(af);
g2d.setStroke(stroke);
g2d.draw(rct);
g2d.dispose();
}
};
RectTransform() throws HeadlessException {
init();
doLay();
attachListeners();
}
private void init() {
}
private void doLay() {
Container container = getContentPane();
JPanel panel = new JPanel(new FlowLayout(FlowLayout.CENTER,30,5));
panel.add(new JButton( new AfAction("move", AffineTransform.getTranslateInstance(100,100)) ));
panel.add(new JButton( new AfAction("rotate", AffineTransform.getRotateInstance(Math.PI/3,40,120) ) ));
panel.add(new JButton( new AfAction("zoomIn", AffineTransform.getScaleInstance(2,2)) ));
panel.add(new JButton( new AfAction("ZoomOut", AffineTransform.getScaleInstance(.5d,.5d)) ));
panel.add(new JButton( new AfAction("Original", new AffineTransform()) ) );
container.add(panel,BorderLayout.NORTH);
container.add(canvas,BorderLayout.CENTER);
pack();
}
private void attachListeners() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
private class AfAction extends AbstractAction {
private AffineTransform aff;
private AfAction(String n,AffineTransform af) {
super(n);
this.aff = af;
}
public void actionPerformed(ActionEvent e) {
af.setTransform(aff);
if(canvas.isVisible()) canvas.paintImmediately(0,0,getWidth(),getHeight());
}
}
public static void main(String[] args) {
new RectTransform().setVisible(true);
}
}
java 简单图形实现 要求: 实现各种二维图形的基本操作,要求采用图形用户界面
我是来拿分的,基础的编程而已,花在JAVA上的时间不够,希望你能找到答案,不过学好JAVA还是要靠自己
用JAVA定义一个二维数组的地图
地图拥用个二维数组,A,B的逻辑分别判断,Aif(i(数组高度)= 0,j != 0 )(j--),if(j = 0,i = 0)(i ++),if(i != 0,j == 0)(j ++)if(i == 10, j == 10)(i --)B的逻辑与A反下,就可以了
java做的一个二维曲线坐标图
方法1、对数坐标系下画图;semilogx,semilogy,loglog
方法2、求差值并画图;
方法3、局部放大;
网页名称:java代码实现二维图形 java代码实现二维图形转换
URL链接:http://azwzsj.com/article/docicdi.html