Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-28-2008, 11:27 PM
Moderator
 
Join Date: Nov 2007
Posts: 1,657
Java Tip will become famous soon enoughJava Tip will become famous soon enough
Demonstration of drawing lines in SWT
Code:
import org.eclipse.swt.*; import org.eclipse.swt.events.*; import org.eclipse.swt.widgets.*; import org.eclipse.swt.layout.*; /** * This class demonstrates drawing lines */ public class LineExample { /** * Runs the application */ public void run() { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Line 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()); // Create a canvas to draw on Canvas canvas = new Canvas(shell, SWT.NONE); // Add a handler to do the drawing canvas.addPaintListener(new PaintListener() { public void paintControl(PaintEvent e) { // Get the canvas and its size Canvas canvas = (Canvas) e.widget; int maxX = canvas.getSize().x; int maxY = canvas.getSize().y; // Calculate the middle int halfX = (int) maxX / 2; int halfY = (int) maxY / 2; // Set the drawing color to blue e.gc.setForeground(e.display.getSystemColor(SWT.COLOR_BLUE)); // Set the width of the lines to draw e.gc.setLineWidth(10); // Draw a vertical line halfway across the canvas e.gc.drawLine(halfX, 0, halfX, maxY); // Draw a horizontal line halfway down the canvas e.gc.drawLine(0, halfY, maxX, halfY); } }); } /** * The application entry point * * @param args the command line arguments */ public static void main(String[] args) { new LineExample().run(); } }
__________________
Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
to our beloved Java Forums! (closes on July 27, 2008)
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Demonstration of drawing points. It draws a sine wave Java Tip SWT 0 06-28-2008 11:25 PM
Demonstration of drawing polygons Java Tip SWT 0 06-28-2008 11:24 PM
Demonstration of drawing an Arc in SWT Java Tip SWT 0 06-28-2008 11:24 PM
How to get the count of all the lines in a file Java Tip java.io 0 04-06-2008 09:45 PM
how to edit lines. jason27131 New To Java 1 08-01-2007 06:41 AM


All times are GMT +3. The time now is 10:05 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org