显示绘图多边形 : 二维图形 « SWT-JFace-Eclipse « Java

En
Java
1. 图形用户界面
2. 三维图形动画
3. 高级图形
4. 蚂蚁编译
5. Apache类库
6. 统计图
7. 
8. 集合数据结构
9. 数据类型
10. 数据库JDBC
11. 设计模式
12. 开发相关类
13. EJB3
14. 电子邮件
15. 事件
16. 文件输入输出
17. 游戏
18. 泛型
19. GWT
20. Hibernate
21. 本地化
22. J2EE平台
23. 基于J2ME
24. JDK-6
25. JNDI的LDAP
26. JPA
27. JSP技术
28. JSTL
29. 语言基础知识
30. 网络协议
31. PDF格式RTF格式
32. 映射
33. 常规表达式
34. 脚本
35. 安全
36. Servlets
37. Spring
38. Swing组件
39. 图形用户界面
40. SWT-JFace-Eclipse
41. 线程
42. 应用程序
43. Velocity
44. Web服务SOA
45. 可扩展标记语言
Java 教程
Java » SWT-JFace-Eclipse » 二维图形屏幕截图 
显示绘图多边形
显示绘图多边形


//Send questions, comments, bug reports, etc. to the authors:

//Rob Warner (rwarner@interspatial.com)
//Robert Harris (rbrt_harris@yahoo.com)

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;

/**
 * This class demonstrates drawing polygons
 */
public class PolygonExample {
  private Text txtWidth = null;
  private Text txtHeight = null;

  /**
   * Runs the application
   */
  public void run() {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Polygon Example");
    createContents(shell);
    shell.open();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) {
        display.sleep();
      }
    }
    display.dispose();
  }

  /**
   * Creates the main window's contents
   
   @param shell the main window
   */
  private void createContents(Shell shell) {
    shell.setLayout(new FillLayout(SWT.VERTICAL));

    // Create the canvas to draw the polygons on
    Canvas drawingCanvas = new Canvas(shell, SWT.NONE);
    drawingCanvas.addPaintListener(new PolygonExamplePaintListener());
  }

  /**
   * This class gets the user input and draws the requested oval
   */
  private class PolygonExamplePaintListener implements PaintListener {
    public void paintControl(PaintEvent e) {
      // Get the canvas for drawing and its dimensions
      Canvas canvas = (Canvase.widget;
      int x = canvas.getBounds().width;
      int y = canvas.getBounds().height;

      // Set the drawing color
      e.gc.setBackground(e.display.getSystemColor(SWT.COLOR_BLACK));

      // Create the points for drawing a triangle in the upper left
      int[] upper_left = 0020000200};

      // Create the points for drawing a triangle in the lower right
      int[] lower_right = x, y, x, y - 200, x - 200, y};

      // Draw the triangles
      e.gc.fillPolygon(upper_left);
      e.gc.fillPolygon(lower_right);
    }
  }

  /**
   * The application entry point
   
   @param args the command line arguments
   */
  public static void main(String[] args) {
    new PolygonExample().run();
  }
}

           
       
Related examples in the same category
1. SWT二维图表:流程SWT二维图表:流程
2. 使用Java2D关于SWT或Draw2D图形上下文使用Java2D关于SWT或Draw2D图形上下文
3. SWT二维的UnicodeSWT二维的Unicode
4. SWT二维简单演示SWT二维简单演示
5. SWT绘制二维SWT绘制二维
6. SWT Draw2D实例
7. 异或异或
8. 动画动画
9. 阿尔法渐变阿尔法渐变
10. 绘制绘制
11. 绘制文本演示绘制文本演示
12. GC创建
13. 调色板调色板
14. 透明度透明度
15. Draw2D样本Draw2D样本
16. 类分析仪类分析仪
17. 演示动画。使用双缓冲。演示动画。使用双缓冲。
18. 演示绘制圆弧演示绘制圆弧
19. 显示绘图点。它吸引了正弦波显示绘图点。它吸引了正弦波
20. 绘制回合矩形绘制回合矩形
21. 显示有关显示装置显示有关显示装置
22. 显示构造器的应用显示构造器的应用
23. 演示了如何利用垂直文本演示了如何利用垂直文本
24. 实用方法绘制图形
25. 显示绘图线显示绘图线
26. 演示动画演示动画
27. 演示如何绘制文字演示如何绘制文字
28. 显示绘图椭圆形显示绘图椭圆形
29. 演示了如何利用文字颜色演示了如何利用文字颜色
30. SWT涂料
31. SWT图形范例SWT图形范例
32. SWT的OpenGL片段:绘制方
33. 图纸与变革,路径和alpha混合图纸与变革,路径和alpha混合
34. 绘制线条和多边形具有不同风格绘制线条和多边形具有不同风格
35. GC:实现一个简单的涂抹程序GC:实现一个简单的涂抹程序
36. GC:测量一个字符串GC:测量一个字符串
37. GC:绘制厚线GC:绘制厚线
38. 如何绘制直接在SWT控制如何绘制直接在SWT控制
www.java2java.com | Contact Us
Copyright 2010 - 2030 Java Source and Support. All rights reserved.
All other trademarks are property of their respective owners.