控制台程序。

 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 g2D.setPaint(Color.RED); // Draw in red // Position width and height of first rectangle
Point2D.Float p1 = new Point2D.Float(50.0f, 10.0f);
float width1 = 60;
float height1 = 80; // Create and draw the first rectangle
Rectangle2D.Float rect = new Rectangle2D.Float(p1.x, p1.y, width1, height1);
g2D.draw(rect); // Position width and height of second rectangle
Point2D.Float p2 = new Point2D.Float(150.0f, 100.0f);
float width2 = width1 + 30;
float height2 = height1 + 40; // Create and draw the second rectangle
g2D.draw(new Rectangle2D.Float(
(float)(p2.getX()), (float)(p2.getY()), width2, height2));
g2D.setPaint(Color.BLUE); // Draw in blue // Draw lines to join corresponding corners of the rectangles
Line2D.Float line = new Line2D.Float(p1,p2);
g2D.draw(line); p1.setLocation(p1.x + width1, p1.y);
p2.setLocation(p2.x + width2, p2.y);
g2D.draw(new Line2D.Float(p1,p2)); p1.setLocation(p1.x, p1.y + height1);
p2.setLocation(p2.x, p2.y + height2);
g2D.draw(new Line2D.Float(p1,p2)); p1.setLocation(p1.x - width1, p1.y);
p2.setLocation(p2.x - width2, p2.y);
g2D.draw(new Line2D.Float(p1, p2)); g2D.drawString("Lines and rectangles", 60, 250); // Draw some text } private Sketcher theApp; // The application object
}

其他部分与上一例相同。

最新文章

  1. 为支持ASP.NET5跨平台,Jexus再添新举措
  2. Linux less 命令
  3. Java注解和代理实现
  4. ubuntu-E:Encountered a section with no Package: header的解决办法
  5. JSP 资源与网站
  6. Android开发系列之按钮事件的4种写法
  7. FZU 2233 ~APTX4869 贪心+并查集
  8. zoj 1671 Walking Ant【简单bfs】
  9. 通过C# 打开一个应用程序
  10. HDU 3123-GCC(递推)
  11. 单链表---java实现
  12. JQuery获取图片大小并控制图片文件上传大小以及上图片文件时如何预览图片
  13. vue-cli2.9.1如何自动打开浏览器及实现手机调试
  14. JavaScript数据结构和算法----队列
  15. vue通过extend动态创建全局组件(插件)学习小记
  16. tinkpad e450c 进入 BIOS
  17. 3.复杂的viewpager
  18. 关于Android如何创建空文件夹,以及mkdir和mkdirs的区别
  19. vs2015 编译google v8
  20. cocos2d-x retain和release倒底怎么玩?

热门文章

  1. UIbutton 和UIview 切单角
  2. Oracle Merge Into 用法详解
  3. sql语句 当前时间查找重复 时间戳转换
  4. miniproject black jack--Fail
  5. simplify the design of the hardware forming the interface between the processor and thememory system
  6. data-"mit.edu-Thinking In C++"
  7. JAVA Callable
  8. SQL Server加密存储过程的破解
  9. nrf51822裸机教程-IIC
  10. FW Docker为容器分配指定物理网段的静态IP