Drag and Draw Demo : Drag Draw « Advanced Graphics « Java

Java
1. 2D Graphics GUI
2. 3D
3. Advanced Graphics
4. Ant
5. Apache Common
6. Chart
7. Collections Data Structure
8. Database SQL JDBC
9. Design Pattern
10. Development Class
11. Email
12. Event
13. File Input Output
14. Game
15. Hibernate
16. J2EE
17. J2ME
18. JDK 6
19. JSP
20. JSTL
21. Language Basics
22. Network Protocol
23. PDF RTF
24. Regular Expressions
25. Security
26. Servlets
27. Spring
28. Swing Components
29. Swing JFC
30. SWT JFace Eclipse
31. Threads
32. Tiny Application
33. Velocity
34. Web Services SOA
35. XML
Microsoft Office Word 2007 Tutorial
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Java » Advanced Graphics » Drag DrawScreenshots 
Drag and Draw Demo
Drag and Draw Demo

import java.io.File;
import java.awt.*;

import javax.swing.*;

import no.geosoft.cc.geometry.Geometry;
import no.geosoft.cc.graphics.*;



/**
 * G demo program. Demonstrates:
 *
 * <ul>
 * <li>Simple image handling
 * <li>Simple drawing interaction
 * </ul>
 
 @author <a href="mailto:jacob.dreyer@geosoft.no">Jacob Dreyer</a>
 */   
public class Demo10 extends JFrame
  implements GInteraction
{
  private GScene    scene_;
  private GSegment  route_;
  private int[]     xy_;
  
  
  public Demo10 (String imageFileName)
  {
    super ("G Graphics Library - Demo 10");    
    setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
    
    getContentPane().setLayout (new BorderLayout());
    getContentPane().add (new JLabel ("Draw line on map using mouse button 1"),
                          BorderLayout.NORTH);
    
    // Create the graphic canvas
    GWindow window = new GWindow();
    getContentPane().add (window.getCanvas(), BorderLayout.CENTER);
    
    // Create scane with default viewport and world extent settings
    scene_ = new GScene (window);

    // Create a graphic object
    GObject object = new TestObject (imageFileName);
    scene_.add (object);

    pack();
    setSize (new Dimension (500500));
    setVisible (true);

    window.startInteraction (this);
  }


  
  public void event (GScene scene, int event, int x, int y)
  {
    switch (event) {
      case GWindow.BUTTON1_DOWN :
        xy_ = new int[] {x, y};
        route_.setGeometry (xy_);
        scene_.refresh();
        break;

      case GWindow.BUTTON1_DRAG :
        int[] a = new int[xy_.length + 2];
        System.arraycopy (xy_, 0, a, 0, xy_.length);
        a[a.length-2= x;
        a[a.length-1= y;
        xy_ = a;
        route_.setGeometry (xy_);
        scene_.refresh();
        break;
    }
  }
  
  
  
  /**
   * Defines the geometry and presentation for a sample
   * graphic object.
   */   
  private class TestObject extends GObject
  {
    private GSegment segment_;
    
    
    TestObject (String imageFileName)
    {
      segment_ = new GSegment();
      addSegment (segment_);

      GImage image = new GImage (new File (imageFileName));
      image.setPositionHint (GPosition.SOUTHEAST);
      segment_.setImage (image);

      route_ = new GSegment();
      addSegment (route_);

      GStyle routeStyle = new GStyle();
      routeStyle.setForegroundColor (new Color (25500));
      routeStyle.setLineWidth (4);
      routeStyle.setAntialiased (true);
      route_.setStyle (routeStyle);
    }
    

  
    public void draw()
    {
      segment_.setGeometry (00);
      route_.setGeometry (xy_);
    }
  }
  


  public static void main (String[] args)
  {
    //if (args.length != 1) {
      //System.out.println ("Provide an image file name");
//      System.exit (0);
  //  }
    
    //new Demo10 (args[0]);
    new Demo10 ("logo.png");
  }
}

           
       
G-SimpleDragAndDraw.zip( 224 k)
Related examples in the same category
w___w__w___.j___a___v_a2_s___.__c___om__ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.