在jbuilder中把标题栏隐藏掉之后 实现拖动窗口

在jbuilder中把标题栏隐藏掉之后 实现拖动窗口

ID:15753473

大小:23.50 KB

页数:3页

时间:2018-08-05

在jbuilder中把标题栏隐藏掉之后 实现拖动窗口_第1页
在jbuilder中把标题栏隐藏掉之后 实现拖动窗口_第2页
在jbuilder中把标题栏隐藏掉之后 实现拖动窗口_第3页
资源描述:

《在jbuilder中把标题栏隐藏掉之后 实现拖动窗口》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库

1、1楼gtlang78()回复于2006-11-2909:35:32得分80importjava.awt.*;importjava.awt.event.MouseEvent;importjavax.swing.JFrame;importjavax.swing.JLabel;importjavax.swing.event.MouseInputAdapter;publicclassUndecoratedFrameextendsJFrame{privatestaticfinalintTITLE_HEIGHT=20;publicUndecoratedFr

2、ame()throwsHeadlessException{super();setUndecorated(true);MouseHandlerml=newMouseHandler();addMouseListener(ml);addMouseMotionListener(ml);}publicUndecoratedFrame(Stringtitle)throwsHeadlessException{super(title);setUndecorated(true);MouseHandlerml=newMouseHandler();addMouseL

3、istener(ml);addMouseMotionListener(ml);}publicInsetsgetInsets(){returnnewInsets(TITLE_HEIGHT,1,1,1);}publicvoidpaint(Graphicsg){super.paint(g);g.setColor(newColor(0,0,128));g.drawRect(0,0,getWidth()-1,getHeight()-1);g.fillRect(0,0,getWidth(),TITLE_HEIGHT);FontMetricsfm=g.get

4、FontMetrics();g.setColor(Color.white);g.drawString(getTitle(),2,(TITLE_HEIGHT-fm.getHeight())/2+fm.getAscent());}privateclassMouseHandlerextendsMouseInputAdapter{privatePointpoint;publicvoidmousePressed(MouseEvente){if(e.getY()<=TITLE_HEIGHT){this.point=e.getPoint();}}public

5、voidmouseDragged(MouseEvente){if(point!=null){setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));Pointp=e.getPoint();intdx=p.x-point.x;intdy=p.y-point.y;intx=getX();inty=getY();setLocation(x+dx,y+dy);}}publicvoidmouseReleased(MouseEvente){point=null;setCursor(Cursor.g

6、etDefaultCursor());}}publicstaticvoidmain(String[]args){JFramef=newUndecoratedFrame("UndecoratedFrame");f.getContentPane().add(newJLabel("HelloWorld!",JLabel.CENTER),BorderLayout.CENTER);f.setSize(400,400);f.setLocationRelativeTo(null);f.setDefaultCloseOperation(JFrame.EXIT_

7、ON_CLOSE);f.setVisible(true);}}

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。