Java基础之在窗口中绘图——绘制曲线(CurveApplet 1)
Applet程序。
定义自由曲线的类有两个,其中一个定义二次曲线,另一个定义三次曲线。这些自由曲线是用一系列线段定义的参数化曲线。二次曲线段用方程定义,方程包含独立变量x的平方。三次曲线也用方程定义,方程包含独立变量x的立方。
QuadCurve2D:二次曲线的抽象基类,曲线用两个端点和一个用来定义两端切线的控制点来定义。切线是从端点到控制点的直线。
CubicCurve2D:三次曲线的抽象基类,曲线用两个端点和两个用来定义两端切线的控制点来定义。切线是从端点到对应控制点的直线。
import javax.swing.*;
import java.awt.*;
import java.awt.geom.*; @SuppressWarnings("serial")
public class CurveApplet extends JApplet {
// Initialize the applet
@Override
public void init() {
pane = new CurvePane(); // Create pane containing curves
Container content = getContentPane(); // Get the content pane // Add the pane displaying the curves to the content pane for the applet
content.add(pane); // BorderLayout.CENTER is default position
} // Class defining a pane on which to draw
class CurvePane extends JComponent {
// Constructor
public CurvePane() {
quadCurve = new QuadCurve2D.Double( // Create quadratic curve
startQ.x, startQ.y, // Segment start point
control.x, control.y, // Control point
endQ.x, endQ.y); // Segment end point cubicCurve = new CubicCurve2D.Double( // Create cubic curve
startC.x, startC.y, // Segment start point
controlStart.x, controlStart.y, // Control pt for start
controlEnd.x, controlEnd.y, // Control point for end
endC.x, endC.y); // Segment end point
} @Override
public void paint(Graphics g) {
Graphics2D g2D = (Graphics2D)g; // Get a 2D device context // Draw the curves
g2D.setPaint(Color.BLUE);
g2D.draw(quadCurve);
g2D.draw(cubicCurve);
}
} // Points for quadratic curve
private Point2D.Double startQ = new Point2D.Double(50, 75); // Start point
private Point2D.Double endQ = new Point2D.Double(150, 75); // End point
private Point2D.Double control = new Point2D.Double(80, 25); // Control point // Points for cubic curve
private Point2D.Double startC = new Point2D.Double(50, 150); // Start point
private Point2D.Double endC = new Point2D.Double(150, 150); // End point
private Point2D.Double controlStart = new Point2D.Double(80, 100); // 1st cntrl point
private Point2D.Double controlEnd = new Point2D.Double(160, 100); // 2nd cntrl point
private QuadCurve2D.Double quadCurve; // Quadratic curve
private CubicCurve2D.Double cubicCurve; // Cubic curve
private CurvePane pane = new CurvePane(); // Pane to contain curves
}
<html>
<head>
</head>
<body bgcolor="000000">
<center>
<applet
code = "CurveApplet.class"
width = "300"
height = "300"
>
</applet>
</center>
</body>
</html>
Java基础之在窗口中绘图——绘制曲线(CurveApplet 1)的更多相关文章
- Java基础之在窗口中绘图——绘制星星(StarApplet 1)
Applet程序. 可以把更复杂的几何形状定义为GeneralPath类型的对象.GeneralPath可以是直线.Quad2D曲线和Cubic2D曲线的结合体,甚至可以包含其他GeneralPath ...
- Java基础之在窗口中绘图——绘制圆弧和椭圆(Sketcher 3 drawing arcs and ellipses)
控制台程序. import javax.swing.JComponent; import java.util.*; import java.awt.*; import java.awt.geom.*; ...
- Java基础之在窗口中绘图——绘制直线和矩形(Sketcher 2 drawing lines and rectangles)
控制台程序. import javax.swing.JComponent; import java.util.*; import java.awt.*; import java.awt.geom.*; ...
- Java基础之在窗口中绘图——移动曲线的控制点(CurveApplet 3 moving the control points)
Applet程序. import javax.swing.*; import java.awt.*; import java.awt.geom.*; import javax.swing.event. ...
- Java基础之在窗口中绘图——显示曲线的控制点(CurveApplet 2 displaying control points)
Applet程序. import javax.swing.*; import java.awt.*; import java.awt.geom.*; @SuppressWarnings("s ...
- Java基础之在窗口中绘图——利用多态性使用鼠标自由绘图(Sketcher 7 with a crosshair cursor)
控制台程序. 在Sketcher中创建形状时,并不知道应该以什么顺序创建不同类型的形状,这完全取决于使用Sketcher程序生成草图的人.因此需要绘制形状,对它们执行其他操作而不必知道图形是什么.当然 ...
- Java基础之在窗口中绘图——使用模型/视图体系结构在视图中绘图(Sketcher 1 drawing a 3D rectangle)
控制台程序. 在模型中表示数据视图的类用来显示草图并处理用户的交互操作,所以这种类把显示方法和草图控制器合并在一起.不专用于某个视图的通用GUI创建和操作在SketcherFrame类中处理. 模型对 ...
- Java基础之在窗口中绘图——填充星型(StarApplet 2 filled stars)
Applet程序. import javax.swing.*; import java.awt.*; import java.awt.geom.GeneralPath; @SuppressWarnin ...
- Java基础之在窗口中绘图——渐变填充(GradientApplet 1)
Applet程序. import javax.swing.*; import java.awt.*; import java.awt.geom.*; @SuppressWarnings("s ...
随机推荐
- Grand Theft Auto V (侠盗列车手5)图形研究
原文地址:http://www.adriancourreges.com/blog/2015/11/02/gta-v-graphics-study/ 原文的简介: GTA(侠盗猎车)系列自从1997 ...
- 第二章、 Linux 如何学习
第二章. Linux 如何学习 最近更新日期:2009/08/06 1. Linux当前的应用角色 1.1 企业环境的利用 1.2 个人环境的使用 Linux当前的应用角色 在第一章Linux是什么当 ...
- C与C++连续赋值的区别
int a,b,c,d; a = b = ; // ( a!=b?a:b) = 1000;//如果a不等于b 那么a = 100;这句话执行完 a还是等于5,b= 100: printf(" ...
- Ruby--CSV
1. 解析CSV: (1)读取文件:csv = CSV.read("#{Rails.root}/public/data/statecountycity.csv", :headers ...
- Oracle 语句常见错误
Merge into的注意点之ORA-30926:无法在源表中获得一组稳定的行? merge into 的内部处理是将table_source 的每一条记录和table_target的每一条记录对比匹 ...
- love yy-kiss 医生出差二期
医生出差二期,做了一半撤出去做互联网医院了 http://confluence.haodf.net/pages/viewpage.action?pageId=15801359 医生出差二期 没设置数 ...
- an optimal solution to the problem
http://www.personal.kent.edu/~rmuhamma/Algorithms/MyAlgorithms/Greedy/greedyIntro.htm Greedy Introdu ...
- P1434 滑雪
水题,记忆化搜索,队列bfs均可 我们定义f[i][j]为到(i, j)的最长路径.然后就不难得出状态转移方程,然后使用无脑dfs,或者有脑递推都是可以的. #include <bits/std ...
- find grep 组合使用
1. 查找所有".h"文件 find /PATH -name "*.h" 2. 查找所有".h"文件中的含有"helloworld ...
- JQuery..bind命名空间
先看手册,由于bind方法有三个参数(type,[data],fn),所以手册上这么介绍: .bind() 方法是用于往文档上附加行为的主要方式.所有JavaScript事件对象, 比如focus, ...