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)的更多相关文章

  1. Java基础之在窗口中绘图——绘制星星(StarApplet 1)

    Applet程序. 可以把更复杂的几何形状定义为GeneralPath类型的对象.GeneralPath可以是直线.Quad2D曲线和Cubic2D曲线的结合体,甚至可以包含其他GeneralPath ...

  2. Java基础之在窗口中绘图——绘制圆弧和椭圆(Sketcher 3 drawing arcs and ellipses)

    控制台程序. import javax.swing.JComponent; import java.util.*; import java.awt.*; import java.awt.geom.*; ...

  3. Java基础之在窗口中绘图——绘制直线和矩形(Sketcher 2 drawing lines and rectangles)

    控制台程序. import javax.swing.JComponent; import java.util.*; import java.awt.*; import java.awt.geom.*; ...

  4. Java基础之在窗口中绘图——移动曲线的控制点(CurveApplet 3 moving the control points)

    Applet程序. import javax.swing.*; import java.awt.*; import java.awt.geom.*; import javax.swing.event. ...

  5. Java基础之在窗口中绘图——显示曲线的控制点(CurveApplet 2 displaying control points)

    Applet程序. import javax.swing.*; import java.awt.*; import java.awt.geom.*; @SuppressWarnings("s ...

  6. Java基础之在窗口中绘图——利用多态性使用鼠标自由绘图(Sketcher 7 with a crosshair cursor)

    控制台程序. 在Sketcher中创建形状时,并不知道应该以什么顺序创建不同类型的形状,这完全取决于使用Sketcher程序生成草图的人.因此需要绘制形状,对它们执行其他操作而不必知道图形是什么.当然 ...

  7. Java基础之在窗口中绘图——使用模型/视图体系结构在视图中绘图(Sketcher 1 drawing a 3D rectangle)

    控制台程序. 在模型中表示数据视图的类用来显示草图并处理用户的交互操作,所以这种类把显示方法和草图控制器合并在一起.不专用于某个视图的通用GUI创建和操作在SketcherFrame类中处理. 模型对 ...

  8. Java基础之在窗口中绘图——填充星型(StarApplet 2 filled stars)

    Applet程序. import javax.swing.*; import java.awt.*; import java.awt.geom.GeneralPath; @SuppressWarnin ...

  9. Java基础之在窗口中绘图——渐变填充(GradientApplet 1)

    Applet程序. import javax.swing.*; import java.awt.*; import java.awt.geom.*; @SuppressWarnings("s ...

随机推荐

  1. GDC2016 【巫师3 狂猎】的游戏事件工作流

    巫师3 狂猎(The Witcher 3: Wild Hunt )的游戏事件工作流   http://game.watch.impress.co.jp/docs/news/20160320_74916 ...

  2. DNS:www.flickr.com

    203.84.197.9 203.84.197.25 203.84.197.26 203.84.197.27

  3. phpstorm8注册码

    phpstorm8注册码 phpstorm 8 注册码   用户名:Learn Programming License key:(包括LICENSE BEGIN和LICENSE END部分) ==== ...

  4. what is php?

    PHP is a popular general-purpose scripting language that is especially suited to web development. Fa ...

  5. laravel 数据填充

    编写填充器 php artisan make:seeder UserTableSeeder 修改Laravel安装时自带的DatabaseSeeder类,添加一个数据库插入语句到run方法: < ...

  6. (转)js闭包初入门

    先看一段JS代码: 1 2 3 4 5 6 7 8 9 10 11 12 13 function a(){             var num = 0;             function  ...

  7. session和cookie区别

    <?php session_start(); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//E ...

  8. Bluetooth GATT介绍

    目录 1. 介绍 2 内容 2.1 Configured Broadcast 2.2 GATT Profile Hierarchy 3 Service Interoperability Require ...

  9. C++ 简单 Hash容器的实现

    主要实现了以整数为关键字的hash,以key%m_nSize为哈希函数,以(hash(key)+i)%m_nSize重新寻址,并附带了elf_hash的实现,使用过程中可灵活修改. #ifndef _ ...

  10. 常用yum命令

    yum list 查询所有可用软件包 yum search 关键字 查询和关键字相关的包 yum -y install 包名 加上-y自动回答yes yum -y update 包名 升级  yum ...