欢迎来到天天文库
浏览记录
ID:9811889
大小:295.93 KB
页数:7页
时间:2018-05-10
《java绘制自定义窗体》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、java自定义窗体大家都说java图形界面不尽人意,相比C#,VB的快捷方便简直不可同日而语。但是如果仔细研究的话,也不尽然,我们通过代码同样可以实现自己想要的漂亮界面。下面就给大家介绍一下,如何使用java自己定义一个去除系统边框,使用自己喜欢的图片作为窗体主体的方法。简述一下方法步骤:1.去除系统边框2.为窗体设置一个放置组件的容器JPanel,并设置布局3.向容器中添加标题栏,然后添加鼠标监听事件4.加入主体部分此程序为java经典案例之一,初级必学,在此分享给大家,感谢那些帮助我,启发我的朋友们!impo
2、rtjava.awt.BorderLayout;importjava.awt.Dimension;importjava.awt.FlowLayout;importjava.awt.Graphics;importjava.awt.GridLayout;importjava.awt.Image;importjava.awt.Point;importjava.awt.event.ActionEvent;importjava.awt.event.ActionListener;importjava.awt.event.It
3、emEvent;importjava.awt.event.ItemListener;importjava.awt.event.MouseAdapter;importjava.awt.event.MouseEvent;importjava.awt.event.MouseMotionAdapter;importjava.io.File;importjava.io.IOException;importjavax.imageio.ImageIO;importjavax.swing.ImageIcon;importjava
4、x.swing.JButton;importjavax.swing.JFrame;importjavax.swing.JPanel;importjavax.swing.JToggleButton;publicclassMyImgFrameextendsJFrame{JPanelcontentPanel;PointpressedPoint;publicMyImgFrame()throwsIOException{this.setUndecorated(true);this.setDefaultCloseOperati
5、on(EXIT_ON_CLOSE);this.setBounds(200,80,400,380);this.setVisible(true);//this.pack();contentPanel=newJPanel();contentPanel.setBorder(null);contentPanel.setLayout(newBorderLayout(0,0));this.setContentPane(contentPanel);MyBacPaneltopPanel=newMyBacPanel();Imaget
6、opimg=ImageIO.read(newFile("E:\Images\15.jpg"));Dimensiondim=newDimension(topimg.getWidth(this),topimg.getHeight(this));topPanel.setPreferredSize(dim);topPanel.setImg(topimg);topPanel.addMouseMotionListener(newMouseMotionAdapter(){publicvoidmouseDragged(Mou
7、seEvente){topPanel_mouseDragged(e);}});topPanel.addMouseListener(newMouseAdapter(){publicvoidmousePressed(MouseEvente){topPanel_mousePressed(e);}});contentPanel.add(topPanel,BorderLayout.NORTH);topPanel.setLayout(newFlowLayout(FlowLayout.RIGHT,5,5));JPanelcon
8、trolJP=newJPanel();controlJP.setPreferredSize(newDimension(60,22));controlJP.setOpaque(false);topPanel.add(controlJP);controlJP.setLayout(newGridLayout(1,0,0,0));JButtonminJB=newJButton()
此文档下载收益归作者所有