Zoom interaction, Text background color, and the effect of transparency : Curve « 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 » CurveScreenshots 
Zoom interaction, Text background color, and the effect of transparency
Zoom interaction, Text background color, and the effect of transparency

import java.awt.*;

import javax.swing.*;

import no.geosoft.cc.graphics.*;



/**
 * G demo program. Demonstrates:
 *
 * <ul>
 *   <li> Custom world extent
 *   <li> Zoom interaction
 *   <li> Text background color
 *   <li> The effect of transparency
 *   <li> Annotation layout algorithm
 * </ul>
 
 @author <a href="mailto:jacob.dreyer@geosoft.no">Jacob Dreyer</a>
 */   
public class Demo5 extends JFrame
{
  /**
   * Class for creating the demo canvas and hande Swing events.
   */   
  public Demo5()
  {
    super ("G Graphics Library - Demo 5");
    setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
    
    // Create the GUI
    JPanel topLevel = new JPanel();
    topLevel.setLayout (new BorderLayout());
    getContentPane().add (topLevel);        

    JPanel buttonPanel = new JPanel();
    buttonPanel.add (new JLabel ("Zoom with rubberband and mouse buttons"));
    topLevel.add (buttonPanel,   BorderLayout.NORTH);

    // Create the graphic canvas
    GWindow window = new GWindow (new Color (240230230));
    topLevel.add (window.getCanvas(), BorderLayout.CENTER);    
    
    // Create scene with default viewport and world extent settings
    GScene scene = new GScene (window, "Scene");
    scene.setWorldExtent (0.0, -Math.PI / 2.05.0 * Math.PI, 1.0 * Math.PI);

    // Create curve object
    GObject curve = new Curve();
    scene.add (curve);

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

    window.startInteraction (new ZoomInteraction (scene));
  }


  
  /**
   * Defines the geometry and presentation for the sample
   * graphics object.
   */   
  public class Curve extends GObject
  {
    private GSegment  curve_;

    
    public Curve()
    {
      curve_ = new GSegment();
      addSegment (curve_);

      GStyle curveStyle = new GStyle();
      curveStyle.setForegroundColor (new Color (25500));
      curveStyle.setLineWidth (12);      
      setStyle (curveStyle);

      GStyle textStyle = new GStyle();
      textStyle.setForegroundColor (new Color (255255255));
      textStyle.setBackgroundColor (new Color (0.0f0.0f0.0f0.3f));
      textStyle.setFont (new Font ("Dialog", Font.BOLD, 14));
      
      for (int i = 0; i < 10; i++) {
        GText text = new GText ("Text " + i, GPosition.LEFT | GPosition.EAST);
        text.setStyle (textStyle);
        curve_.addText (text);
      }
    }
    

    
    public void draw()
    {
      int nPoints = 500;

      double[] x = new double[nPoints];
      double[] y = new double[nPoints];      

      double step = Math.PI * 10.0 / nPoints;
      for (int i = 0; i < nPoints; i++) {
        x[i= i * step;
        y[i= Math.sin (x[i]);
      }

      curve_.setGeometry (x, y);
    }
  }
  


  public static void main (String[] args)
  {
    new Demo5();
  }
}

           
       
G-DrawCurve.zip( 204 k)
Related examples in the same category
1. Draw SplineDraw Spline
2. Animated GraphAnimated Graph
3. Epsilon DeltaEpsilon Delta
4. Families Of GraphsFamilies Of Graphs
5. Integral CurvesIntegral Curves
6. Trace curveTrace curve
7. Input the function and draw the curveInput the function and draw the curve
8. Scatter PlotScatter Plot
w_ww___._j_a__v__a__2__s__._c_o_m___ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.