Sponsors: Michael Fertik - Best JAVA Web hosting Company & 30% off


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-25-2008, 02:28 PM
Java Tip's Avatar
Moderator
 
Join Date: Nov 2007
Posts: 1,691
Rep Power: 5
Java Tip will become famous soon enoughJava Tip will become famous soon enough
Default Non Rectangular Window in SWT
Code:
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Region;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;

public class NonRectangularClass {

  static int[] createCircle(int xOffset, int yOffset, int radius) {
    int[] circlePoints = new int[10 * radius];
    for (int loopIndex = 0; loopIndex < 2 * radius + 1; loopIndex++) {
      int xCurrent = loopIndex - radius;
      int yCurrent = (int) Math.sqrt(radius * radius - xCurrent
          * xCurrent);
      int doubleLoopIndex = 2 * loopIndex;

      circlePoints[doubleLoopIndex] = xCurrent + xOffset;
      circlePoints[doubleLoopIndex + 1] = yCurrent + yOffset;
      circlePoints[10 * radius - doubleLoopIndex - 2] = xCurrent
          + xOffset;
      circlePoints[10 * radius - doubleLoopIndex - 1] = -yCurrent
          + yOffset;
    }

    return circlePoints;
  }

  public static void main(String[] args) {
    final Display display = new Display();
    final Shell shell = new Shell(display, SWT.NO_TRIM);

    Region region = new Region();
    region.add(createCircle(50, 50, 50));
    region.subtract(createCircle(50, 50, 20));
    shell.setRegion(region);
    shell.setSize(region.getBounds().width, region.getBounds().height);
    shell.setBackground(display.getSystemColor(SWT.COLOR_BLUE));

    Button button = new Button(shell, SWT.PUSH);
    button.setText("Exit");
    button.setBounds(35, 6, 35, 20);
    button.addListener(SWT.Selection, new Listener() {
      public void handleEvent(Event event) {
        shell.close();
      }
    });

    shell.open();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch())
        display.sleep();
    }
    region.dispose();
    display.dispose();
  }
}
__________________
"The sole cause of man’s unhappiness is that he does not know how to stay quietly in his room." - Blaise Pascal
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

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

BB 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
Creating a non-rectangular shell to simulate transparency Java Tip SWT 0 07-25-2008 02:26 PM
Is there a way to have a window ontop of... Bandet Ace New To Java 2 07-03-2008 10:22 PM
JFace Window Java Tip SWT 0 07-02-2008 08:12 PM
Conversion between polar and rectangular coordinates Java Tip java.lang 0 04-16-2008 10:55 PM
refresh a different window marceldupont AWT / Swing 3 03-22-2008 02:44 AM


Java Forums is supported by the best jsp hosting.

All times are GMT +2. The time now is 07:56 AM.



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