控制台程序。

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

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

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

  2. Java基础之在窗口中绘图——绘制曲线(CurveApplet 1)

    Applet程序. 定义自由曲线的类有两个,其中一个定义二次曲线,另一个定义三次曲线.这些自由曲线是用一系列线段定义的参数化曲线.二次曲线段用方程定义,方程包含独立变量x的平方.三次曲线也用方程定义, ...

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

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

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

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

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

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

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

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

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

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

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

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

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

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

随机推荐

  1. ios-指纹识别

    - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event { //1. 判断系统版本 if ( ...

  2. Xamarin学习资源收集

    推荐入门视频 跨行動平台App開發概觀- 使用Xamarin+Visual Studio https://www.youtube.com/watch?v=ELuFTTn1gS4 中文产品介绍http: ...

  3. RT-Thread相同优先级线程的调度

    /* 静态线程的 线程堆栈*/ ]; ]; /* 静态线程的 线程控制块 */ static struct rt_thread thread_test1; static struct rt_threa ...

  4. 【转载】Linux系统与性能监控

    原文地址:http://kerrigan.sinaapp.com/post-7.html Linux System and Performance Monitoring http://www.hous ...

  5. General protection fault Exceptions in Linux/IA32 Systems

    Computer Systems A Programmer's Perspective Second Edition Exception number Description Exception cl ...

  6. Bootstrap 模态框插件

    一.基本使用 使用模态框的弹窗组件需要三层 div 容器元素,分别为 modal(模态声明层). dialog(窗口声明层).content(内容层).在内容层里面,还有三层,分别为 header(头 ...

  7. 简述AFN(AFNetWorking 2.X)的实现分析和简单使用【转】

    [转载] Axc注:版本为AFNetWorking 2.6    3.0需要修改大部分对象 一:声明本 人以前一直是使用ASI网络请求类库的.最近才开始了解使用AFNetworing这个类库.网上也肯 ...

  8. Windows下git使用代理服务器的设置方法

    在我朝独有的无敌GFW关照下(当然,也有可能IP被网站封了),要下载网络上开源的软件是非常困难的一件事情,在这种情况下,使用VPN或者代理服务器就非常有必要了.对于单个应用FQ来说,个人比较喜欢用FQ ...

  9. android提供ToolBar实现划动菜单的陷阱

    代码如下: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android: ...

  10. mongo安装、备份与常见命令整理

    http://zlboy888.blog.163.com/blog/static/315357072012919241104/ 1 下载安装包  官方下载地址:http://www.mongodb.o ...