Java基础之在窗口中绘图——绘制圆弧和椭圆(Sketcher 3 drawing arcs and ellipses)
控制台程序。
import javax.swing.JComponent;
import java.util.*;
import java.awt.*;
import java.awt.geom.*; @SuppressWarnings("serial")
public class SketcherView extends JComponent implements Observer {
public SketcherView(Sketcher theApp) {
this.theApp = theApp;
} // Method called by Observable object when it changes
public void update(Observable o, Object rectangle) {
// Code to respond to changes in the model...
} // Method to draw on the view
@Override
public void paint(Graphics g) {
// Temporary code...
Graphics2D g2D = (Graphics2D)g; // Get a Java 2D device context
Point2D.Double position = new Point2D.Double(50,10); // Initial position
double width = 150; // Width of ellipse
double height = 100; // Height of ellipse
double start = 30; // Start angle for arc
double extent = 120; // Extent of arc
double diameter = 40; // Diameter of circle // Define open arc as an upper segment of an ellipse
Arc2D.Double top = new Arc2D.Double(position.x, position.y,
width, height,
start, extent,
Arc2D.OPEN); // Define open arc as lower segment of ellipse shifted up relative to 1st
Arc2D.Double bottom = new Arc2D.Double(
position.x, position.y - height + diameter,
width, height,
start + 180, extent,
Arc2D.OPEN); // Create a circle centered between the two arcs
Ellipse2D.Double circle1 = new Ellipse2D.Double(
position.x + width/2 - diameter/2,position.y,
diameter, diameter); // Create a second circle concentric with the first and half the diameter
Ellipse2D.Double circle2 = new Ellipse2D.Double(
position.x + width/2 - diameter/4, position.y + diameter/4,
diameter/2, diameter/2); // Draw all the shapes
g2D.setPaint(Color.BLACK); // Draw in black
g2D.draw(top);
g2D.draw(bottom); g2D.setPaint(Color.BLUE); // Draw in blue
g2D.draw(circle1);
g2D.draw(circle2);
g2D.drawString("Arcs and ellipses", 80, 100); // Draw some text } private Sketcher theApp; // The application object
}
其他部分与上一例同。
Java基础之在窗口中绘图——绘制圆弧和椭圆(Sketcher 3 drawing arcs and ellipses)的更多相关文章
- Java基础之在窗口中绘图——绘制星星(StarApplet 1)
Applet程序. 可以把更复杂的几何形状定义为GeneralPath类型的对象.GeneralPath可以是直线.Quad2D曲线和Cubic2D曲线的结合体,甚至可以包含其他GeneralPath ...
- Java基础之在窗口中绘图——绘制曲线(CurveApplet 1)
Applet程序. 定义自由曲线的类有两个,其中一个定义二次曲线,另一个定义三次曲线.这些自由曲线是用一系列线段定义的参数化曲线.二次曲线段用方程定义,方程包含独立变量x的平方.三次曲线也用方程定义, ...
- Java基础之在窗口中绘图——绘制直线和矩形(Sketcher 2 drawing lines and rectangles)
控制台程序. import javax.swing.JComponent; import java.util.*; import java.awt.*; import java.awt.geom.*; ...
- 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 ...
- 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 ...
随机推荐
- 郎科U208(主控 PS2251-50 HYNIX H27UCG8T2MYR)量产还原
6年前的一个U盘 记得还是参加某会议送的,当时做了量产 多做了一个光盘区,现在用不着了 想还原成普通U盘 忘了方法. 可见笔记的重要性 Chipgenius看了主控 PS2251-50 芯片是海力士 ...
- 看StackOverflow如何用25台服务器撑起5.6亿的月PV
问答社区网络 StackExchange 由 100 多个网站构成,其中包括了 Alexa 排名第 54 的 StackOverflow.StackExchang 有 400 万用户,每月 5.6 亿 ...
- Universal Serial Bus USB 3.0
Computer Systems A Programmer's Perspective Second Edition A Universal Serial Bus (USB) controller i ...
- android文字阴影效果(转)
关于android文字阴影,共有四个属性可以设置: android:shadowColor :阴影颜色 android:shadowDx :阴影x方向位移 android:shadowDy :阴影y方 ...
- Excel VBA
=COUNTIF(Y3:Y212,"=11") =SUMIF(Y3:Y212,"=11",AA3:AA212) =SUMPRODUCT((Y3:Y212=&qu ...
- Mac OS X 上启动 FTP/SFTP server,并设置 log level
木易小伟的博客| 木易小伟的博客 2013-08-13 5708 阅读 FTP Log SFTP Mac OS 系统配置 1. 启动FTP Server: 命令行下, sudo -s launch ...
- github添加SSH Key
1.背景介绍 缘由:在github上下载goagent时出现错误. 在终端使用命令:git clone git@github.com:phuslu/goagent.git 会报权限错误如下: Clon ...
- 其他常用HTML 片段
1.input placeholder 文字居中 字体大小+上下padding值等于设计稿宽度 设计稿中总高度为86px padding:27px 0;font-size:30px; 2.英文 ...
- [LeetCode]题解(python):118-Excel Sheet Column Title
题目来源 https://leetcode.com/problems/excel-sheet-column-title/ Given a positive integer, return its co ...
- php 显示某一个时间相当于当前时间在多少秒前,多少分钟前,多少小时前
/* *function:显示某一个时间相当于当前时间在多少秒前,多少分钟前,多少小时前 *timeInt:unix time时间戳 *format:时间显示格式 */ public function ...