Board index » jbuilder » Changing the square?

Changing the square?


2003-10-18 04:32:01 AM
jbuilder1
How can I get the gu?to look lıke somethıng other than a square or
rectangle? What if I wanted the gui to be round or triangular? Is this
possible?
 
 

Re:Changing the square?

"myjava33" < XXXX@XXXXX.COM >writes:
Quote
How can I get the gu?to look lıke somethıng other than a square or
rectangle? What if I wanted the gui to be round or triangular? Is this
possible?
Not in Java without calling the native APIs that newer versions of
Windowes use to create the "dynamically decorated" windows.
 

Re:Changing the square?

myjava33 wrote:
Quote
How can I get the gu?to look lıke somethıng other than a square or
rectangle? What if I wanted the gui to be round or triangular? Is this
possible?


You know, I'm pretty sure I have seen an example of this. And I'm
pretty sure it involved the use of GlassPane. But I can't find it now.
It may have been a widget that you have to buy.
Sorry my memory is so bad :-)
--
Regards,
Lori Olson (TeamB)
------------
Save yourself, and everyone else, some time and search the
newsgroups and the FAQ-O-Matic before posting your next
question.
Google Advanced Newsgroup Search
www.google.ca/advanced_group_search
Other Newsgroup Searches:
www.borland.com/newsgroups/ngsearch.html
Joi Ellis's FAQ-O-Matic:
www.visi.com/~gyles19/fom-serve/cache/1.html
 

{smallsort}

Re:Changing the square?

"Lori M Olson (TeamB)" < XXXX@XXXXX.COM >schrieb im Newsbeitrag
Quote
myjava33 wrote:
>How can I get the gu?to look lıke somethıng other than a square or
>rectangle? What if I wanted the gui to be round or triangular? Is this
>possible?
>
>

You know, I'm pretty sure I have seen an example of this. And I'm
pretty sure it involved the use of GlassPane. But I can't find it now.
It may have been a widget that you have to buy.

Sorry my memory is so bad :-)

Yes, it can be done and is often done for java game programmings etc., even
it's not very responsive/fast for bigger window surfaces/areas. AFAIK there
are also some other different techniques for this available. However I only
tried myself out to do similar things with undecorated windows and partly
transparent windows. Mainly, since I use such techniques in an actually (yet
not publicly distributed/available) JBuilder OT, which is a sort of JBuilder
screen capture add-on tool . - I'am not sure if I ever will officially
publish that JB Screencapture OT, but maybe some day I will do so.
Ok, here is a much simpler code example for a transparent non-rectangular
movable window, for tryouts:
---------------------- start of code ---------------------
// Demo for an oval transparent "looking through the glass" window.
// When started the window can be moved around with the mouse,
// note that this demo app has to be killed the hard way, so I recommend
// to start and stop it from inside of a JB via a project runtime
configuration.
import java.awt.AWTException;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.awt.Robot;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;
import java.awt.image.BufferedImage;
import javax.swing.JWindow;
public class OvalWindowDemo extends JWindow implements MouseMotionListener
{
private int ox = 0;
private int oy = 0;
private int W = 100;
private int H = 100;
private Robot robot;
private BufferedImage [] underneath = new BufferedImage[2];
private int flipflop = 0;
private BufferedImage canvas; // for flicker free drawing
private Rectangle strip = new Rectangle();
public OvalWindowDemo ()
{
ox = 100; oy = 100;
Rectangle bounds = new Rectangle(ox,oy,W,H);
setBackground( new Color(0,0,0,0) );
setForeground( Color.MAGENTA );
setBounds( bounds );
underneath[0] = new BufferedImage( W, H, BufferedImage.TYPE_INT_BGR );
underneath[1] = new BufferedImage( W, H, BufferedImage.TYPE_INT_BGR );
try
{
robot = new Robot();
BufferedImage tmp = robot.createScreenCapture( bounds );
underneath[0].getGraphics().drawImage(tmp,0,0,null);
underneath[1].getGraphics().drawImage(tmp,0,0,null);
}
catch( AWTException e )
{
e.printStackTrace();
}
canvas = new BufferedImage( W, H, BufferedImage.TYPE_INT_BGR );
addMouseMotionListener( this );
System.gc();
}
public static void main( String [] args )
{
OvalWindowDemo cs = new OvalWindowDemo();
cs.show();
}
public void initialize()
{
}
public void update( Graphics g ) { paint( g ); }
public void paint( Graphics g )
{
Graphics2D gc = (Graphics2D) canvas.getGraphics();
gc.drawImage( underneath[flipflop], 0 ,0 , null );
gc.setColor( Color.MAGENTA );
gc.setRenderingHint( RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON );
gc.drawOval(10,10,80,80);
setLocation( ox, oy );
g.drawImage( canvas, 0 ,0 , null );
}
// ***Interface implementations***
// MouseMotionListener for interactive movement
public void mouseDragged( MouseEvent e )
{
// Determine new window location
int nx = ox+e.getX()-W/2;
int ny = oy+e.getY()-H/2;
int dx = nx-ox;
int dy = ny-oy;
if( dx == 0 && dy ==0 )
return;
// Construct new 'underneath' image
int flop = 1-flipflop;
Graphics g = underneath[flop].getGraphics();
g.drawImage( underneath[flipflop], -dx, -dy, null);
// Grab new background strips
if( dx>0 )
{
strip.x = nx+W-dx;
strip.y = ny;
strip.width = dx;
strip.height = H;
g.drawImage( robot.createScreenCapture( strip ), W-dx, 0, null );
}
else if ( dx < 0 )
{
strip.x = nx;
strip.y = ny;
strip.width = -dx;
strip.height = H;
g.drawImage( robot.createScreenCapture( strip ), 0, 0, null );
}
if( dy>0 )
{
strip.x = dx>0 ? nx : nx-dx;
strip.y = ny+H-dy;
strip.width = W-Math.abs(dx); // optimize
strip.height = dy;
g.drawImage( robot.createScreenCapture( strip ), dx>0?0:-dx, H-dy,
null );
}
else if ( dy < 0 )
{
strip.x = dx>0 ? nx : nx-dx;
strip.y = ny;
strip.width = W-Math.abs(dx); // optimize it
strip.height = -dy;
g.drawImage( robot.createScreenCapture( strip ), dx>0?0:-dx, 0, null );
}
flipflop = flop;
ox = nx;
oy = ny;
paint( getGraphics() );
}
public void mouseMoved( MouseEvent e )
{
}
}
---------------------- end of code ---------------------
I hope that it at least points you into the desired direction...? I also
once had build up a different undecorated window based example (one with a
sort of selectable window like border, a close button and so on...), which
doesn't used such transparency levels at all, but I would have to search
through all of my Java/JB dev backup CDs first in order to find that
example. - No need to say, that I'am actually tooo lazy to do so.
-Valentino
 

Re:Changing the square?

Thanks!!! This is really a great help. I'm assuming that it is possible to
put buttons on here? I'm going to try this and see what happens.
"Valentino Kyriakides" < XXXX@XXXXX.COM >wrote in message
Quote

"Lori M Olson (TeamB)" < XXXX@XXXXX.COM >schrieb im Newsbeitrag
news: XXXX@XXXXX.COM ...
>myjava33 wrote:
>>How can I get the gu?to look lıke somethıng other than a square or
>>rectangle? What if I wanted the gui to be round or triangular? Is this
>>possible?
>>
>>
>
>You know, I'm pretty sure I have seen an example of this. And I'm
>pretty sure it involved the use of GlassPane. But I can't find it now.
>It may have been a widget that you have to buy.
>
>Sorry my memory is so bad :-)
>

Yes, it can be done and is often done for java game programmings etc.,
even
it's not very responsive/fast for bigger window surfaces/areas. AFAIK
there
are also some other different techniques for this available. However I
only
tried myself out to do similar things with undecorated windows and partly
transparent windows. Mainly, since I use such techniques in an actually
(yet
not publicly distributed/available) JBuilder OT, which is a sort of
JBuilder
screen capture add-on tool . - I'am not sure if I ever will officially
publish that JB Screencapture OT, but maybe some day I will do so.


Ok, here is a much simpler code example for a transparent non-rectangular
movable window, for tryouts:

---------------------- start of code ---------------------

// Demo for an oval transparent "looking through the glass" window.
// When started the window can be moved around with the mouse,
// note that this demo app has to be killed the hard way, so I recommend
// to start and stop it from inside of a JB via a project runtime
configuration.

import java.awt.AWTException;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.awt.Robot;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;
import java.awt.image.BufferedImage;
import javax.swing.JWindow;


public class OvalWindowDemo extends JWindow implements MouseMotionListener
{
private int ox = 0;
private int oy = 0;
private int W = 100;
private int H = 100;
private Robot robot;
private BufferedImage [] underneath = new BufferedImage[2];
private int flipflop = 0;
private BufferedImage canvas; // for flicker free drawing
private Rectangle strip = new Rectangle();

public OvalWindowDemo ()
{
ox = 100; oy = 100;
Rectangle bounds = new Rectangle(ox,oy,W,H);
setBackground( new Color(0,0,0,0) );
setForeground( Color.MAGENTA );
setBounds( bounds );
underneath[0] = new BufferedImage( W, H, BufferedImage.TYPE_INT_BGR );
underneath[1] = new BufferedImage( W, H, BufferedImage.TYPE_INT_BGR );
try
{
robot = new Robot();
BufferedImage tmp = robot.createScreenCapture( bounds );
underneath[0].getGraphics().drawImage(tmp,0,0,null);
underneath[1].getGraphics().drawImage(tmp,0,0,null);
}
catch( AWTException e )
{
e.printStackTrace();
}
canvas = new BufferedImage( W, H, BufferedImage.TYPE_INT_BGR );
addMouseMotionListener( this );
System.gc();
}
public static void main( String [] args )
{
OvalWindowDemo cs = new OvalWindowDemo();
cs.show();
}

public void initialize()
{
}
public void update( Graphics g ) { paint( g ); }
public void paint( Graphics g )
{
Graphics2D gc = (Graphics2D) canvas.getGraphics();
gc.drawImage( underneath[flipflop], 0 ,0 , null );
gc.setColor( Color.MAGENTA );
gc.setRenderingHint( RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON );
gc.drawOval(10,10,80,80);
setLocation( ox, oy );
g.drawImage( canvas, 0 ,0 , null );
}

// ***Interface implementations***

// MouseMotionListener for interactive movement

public void mouseDragged( MouseEvent e )
{
// Determine new window location
int nx = ox+e.getX()-W/2;
int ny = oy+e.getY()-H/2;

int dx = nx-ox;
int dy = ny-oy;
if( dx == 0 && dy ==0 )
return;
// Construct new 'underneath' image
int flop = 1-flipflop;
Graphics g = underneath[flop].getGraphics();
g.drawImage( underneath[flipflop], -dx, -dy, null);
// Grab new background strips
if( dx>0 )
{
strip.x = nx+W-dx;
strip.y = ny;
strip.width = dx;
strip.height = H;
g.drawImage( robot.createScreenCapture( strip ), W-dx, 0, null );
}
else if ( dx < 0 )
{
strip.x = nx;
strip.y = ny;
strip.width = -dx;
strip.height = H;
g.drawImage( robot.createScreenCapture( strip ), 0, 0, null );
}
if( dy>0 )
{
strip.x = dx>0 ? nx : nx-dx;
strip.y = ny+H-dy;
strip.width = W-Math.abs(dx); // optimize
strip.height = dy;
g.drawImage( robot.createScreenCapture( strip ), dx>0?0:-dx, H-dy,
null );
}
else if ( dy < 0 )
{
strip.x = dx>0 ? nx : nx-dx;
strip.y = ny;
strip.width = W-Math.abs(dx); // optimize it
strip.height = -dy;
g.drawImage( robot.createScreenCapture( strip ), dx>0?0:-dx, 0, null );
}

flipflop = flop;
ox = nx;
oy = ny;
paint( getGraphics() );
}
public void mouseMoved( MouseEvent e )
{
}

}

---------------------- end of code ---------------------

I hope that it at least points you into the desired direction...? I also
once had build up a different undecorated window based example (one with a
sort of selectable window like border, a close button and so on...), which
doesn't used such transparency levels at all, but I would have to search
through all of my Java/JB dev backup CDs first in order to find that
example. - No need to say, that I'am actually tooo lazy to do so.


-Valentino