Import java. AWT .*;
Import java. AWT. event. mouseevent;
Import javax. Swing. jframe;
Import javax. Swing. jlabel;
Import javax. Swing. event. mouseinputadapter;
Public class undecoratedframe extends jframe
{
Private Static final int title_height = 20;
Public undecoratedframe () throws headlessexception
{
Super ();
Setundecorated (true );
Mousehandler ML = new mousehandler ();
Addmouselistener (ML );
Addmousemotionlistener (ML );
}
Public undecoratedframe (String title) throws headlessexception
{
Super (title );
Setundecorated (true );
Mousehandler ML = new mousehandler ();
Addmouselistener (ML );
Addmousemotionlistener (ML );
}
Public insets getinsets ()
{
Return new insets (title_height, 1, 1, 1 );
}
Public void paint (Graphics g)
{
Super. Paint (g );
G. setcolor (new color (0, 0,128 ));
G. drawrect (0, 0, getwidth ()-1, getheight ()-1 );
G. fillrect (0, 0, getwidth (), title_height );
Fontmetrics fm = G. getfontmetrics ();
G. setcolor (color. White );
G. drawstring (gettitle (), 2, (title_height-FM. getheight ()/2 + FM. getascent ());
}
Private class mousehandler extends mouseinputadapter
{
Private point;
Public void mousepressed (mouseevent E)
{
If (E. Gety () <= title_height ){
This. Point = E. getpoint ();
}
}
Public void mousedragged (mouseevent E)
{
If (point! = NULL ){
Setcursor (cursor. getpredefinedcursor (cursor. move_cursor ));
Point P = E. getpoint ();
Int dx = p. x-point. X;
Int DY = P. Y-point. Y;
Int x = getx ();
Int y = Gety ();
Setlocation (x + dx, Y + dy );
}
}
Public void mousereleased (mouseevent E)
{
Point = NULL;
Setcursor (cursor. getdefacurcursor ());
}
}
Public static void main (string [] ARGs)
{
Jframe F = new undecoratedframe ("undecorated frame ");
F. getcontentpane (). Add (New jlabel ("Hello world! ", Jlabel. Center), borderlayout. center );
F. setsize (400,400 );
F. setlocationrelativeto (null );
F. setdefaclocloseoperation (jframe. exit_on_close );
F. setvisible (true );
}
}