java,php,asp.net,linux,javascript,mysql,mssql,oracle,编程

Swing做的QQ

  1 java code 这是一个登陆页面,可以注册,说明这两个功能是可以实现的,大家可以猜一猜这两个是用什么控件?JLabel or JTextField?其实都不是其实就是JPanel是不是很漂亮?
  2 现在看到的就是主界面了,大家不要己为这些按钮都只是画的而没有功能哦,大家看我点状态按钮.说明是可以用的,这里的其它几个面板待开发中..
  3 我现在打开的是聊天窗口,这里面的功能也还不是很完善,大家知道我刚才点的这两个按钮功能是用什么控件完成的吗?不要己为是JSplitPane完成的哦,
  4 也是我自己定义的控件JSplitPane虽然可以完成以上功能,但是做出来的东东太难看了.再看下面这一条,哈哈,和QQ的面板是不是非常""?
  5 再看一个功能,看到没?自动隐藏功能..
  6 好了,演示就到这里,下面我介绍几个常用函数:
  7 2,下面我给出几个我这个JQchat里面用到的几个函数.
  8 *a******************************************************************************************
  9 /**
 10 这里我现在设置的是windows风格,风格调用代码是:SystemStyles.setWindowsStyle(frame);
 11  * 设置Windows风格界面
 12  * @param comp
 13  */
 14 public static void setWindowsStyle(Component comp) {
 15     try {
 16         UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
 17         initGlobalFontSetting(getFont());
 18         SwingUtilities.updateComponentTreeUI(comp);
 19     } catch (Exception e) {
 20         e.printStackTrace();
 21     }
 22 }
 23 风格设置之后就得设置字体了.
 24 /**    设置全局字体    
 25  *     eg:initGlobalFontSetting("宋体");
 26  */ 
 27 @SuppressWarnings("unchecked")
 28 public static void initGlobalFontSetting(Font fnt) {
 29     FontUIResource fontRes = new FontUIResource(fnt);
 30     for (Enumeration keys = UIManager.getDefaults().keys(); keys.hasMoreElements();) {
 31         Object key = keys.nextElement();
 32         Object value = UIManager.get(key);
 33         if (value instanceof FontUIResource)
 34             UIManager.put(key, fontRes);
 35     }
 36 }
 37 以上的函数只是是做CS的项目基本上都会用到的, 是很基本的东西,第二个函数是我昨天写的,调整窗体大小的函数,
 38 如果需要像我一样自定义上面的标题栏,那就要用到这个函数了(调整窗体函数),看到没,我没有用自带的标题栏,
 39 而是自己定义的,如果需要自己定义标题栏,那么就需要把原来的标题栏隐藏掉,但是如果隐藏掉标题栏后就不可以调整窗体大小,所以我就写了一个函数.
 40 假设我现在需要将这个变大一点点是不是不可以,?因为我把标题栏隐藏掉了,但是如果我把另外一个代码加上去就可以了.
 41 *b******************************************************************************************
 42 以下是代码,大家可以收藏.如果仔细观察相信大家都看得懂..
 43 再看我刚才的这个点击标题栏托动的功能?其实也是要自己写的.大家自己去练练手吧.演示教程就到这里,记住哦,如果大家有兴趣的话等这个软件功能完成后我会在网站上面公布源代码.
 44 今天中秋,祝大家中秋快乐.~
 45 /**
 46      * adjust the window's size
 47      * @param frame the Object of window
 48      * @param a        the length of top 
 49      * @param b        the length of bottom
 50      * @param c        the length of left
 51      * @param d        the length of right
 52      * @param minWidth    the window's minwidth
 53      * @param minHeight    the window's minheight
 54      */
 55     public static void setCanResize(final Window frame,final int a,final int b,final int c,final int d,final int minWidth,final int minHeight){
 56         frame.addMouseMotionListener(new MouseMotionAdapter() {
 57             int x1,y1,x2,y2;
 58             public void mouseMoved(final MouseEvent e) {
 59                 Point mousePoint = e.getLocationOnScreen();
 60                 Point framePoint = frame.getLocationOnScreen();
 61                 if(mousePoint.x>=framePoint.x && mousePoint.x<=framePoint.x + c && mousePoint.y>=framePoint.y + a && mousePoint.y<=framePoint.y + frame.getHeight() -b){
 62                     frame.setCursor(Cursor.getPredefinedCursor(Cursor.W_RESIZE_CURSOR));
 63                 }else if(mousePoint.x>=framePoint.x + frame.getWidth() - d && mousePoint.x <= framePoint.x + frame.getWidth() && mousePoint.y>=framePoint.y + a && mousePoint.y<=framePoint.y + frame.getHeight() -b){
 64                     frame.setCursor(Cursor.getPredefinedCursor(Cursor.E_RESIZE_CURSOR));
 65                 }else if(mousePoint.x >=framePoint.x + c && mousePoint.x <=framePoint.x + frame.getWidth() -&& mousePoint.y >=framePoint.y && mousePoint.y <= framePoint.y + a){
 66                     frame.setCursor(Cursor.getPredefinedCursor(Cursor.N_RESIZE_CURSOR));
 67                 }else if(mousePoint.x >= framePoint.x + c && mousePoint.x <=framePoint.x + frame.getWidth()-&& mousePoint.y >= framePoint.y + frame.getHeight() -&& mousePoint.y<= framePoint.y + frame.getHeight()){
 68                     frame.setCursor(Cursor.getPredefinedCursor(Cursor.S_RESIZE_CURSOR));
 69                 }else if(mousePoint.x >= framePoint.x && mousePoint.x < framePoint.x + c && mousePoint.y >= framePoint.y && mousePoint.y < framePoint.y + a){
 70                     frame.setCursor(Cursor.getPredefinedCursor(Cursor.NW_RESIZE_CURSOR));
 71                 }else if(mousePoint.x > framePoint.x + frame.getWidth() -&& mousePoint.x <= framePoint.x + frame.getWidth() && mousePoint.y >= framePoint.y && mousePoint.y < framePoint.y + a){
 72                     frame.setCursor(Cursor.getPredefinedCursor(Cursor.NE_RESIZE_CURSOR));
 73                 }else if(mousePoint.x >= framePoint.x && mousePoint.x < framePoint.x + c && mousePoint.y > framePoint.y + frame.getHeight() - b && mousePoint.y <= framePoint.y + frame.getHeight()){
 74                     frame.setCursor(Cursor.getPredefinedCursor(Cursor.SW_RESIZE_CURSOR));
 75                 }else if(mousePoint.x > framePoint.x + frame.getWidth() -&& mousePoint.x <= framePoint.x + frame.getWidth() && mousePoint.y > framePoint.y + frame.getHeight() 
 76 - b && mousePoint.y <= framePoint.y + frame.getHeight()){
 77                     frame.setCursor(Cursor.getPredefinedCursor(Cursor.SE_RESIZE_CURSOR));
 78                 }else{
 79                     frame.setCursor(Cursor.getDefaultCursor());
 80                     x1 = -1;
 81                     return;
 82                 }
 83                 x1 = framePoint.x;
 84                 y1 = framePoint.y;
 85                 x2 = framePoint.x + frame.getWidth();
 86                 y2 = framePoint.y + frame.getHeight();
 87             }
 88             public void mouseDragged(final MouseEvent e) {
 89                 if(x1 < 0){
 90                     return;
 91                 }
 92                 int type = frame.getCursor().getType();
 93                 Point p = e.getLocationOnScreen();
 94                 switch (type){
 95                 case Cursor.W_RESIZE_CURSOR:
 96                     frame.setBounds(p.x, y1, (x2 - p.x)>minWidth?(x2 - p.x):minWidth, frame.getHeight()>minHeight?frame.getHeight():minHeight);
 97                     break;
 98                 case Cursor.E_RESIZE_CURSOR:
 99                     frame.setBounds(x1, y1, (p.x - x1)>minWidth?(p.x - x1):minWidth, frame.getHeight()>minHeight?frame.getHeight():minHeight);
100                     break;
101                 case Cursor.N_RESIZE_CURSOR:
102                     frame.setBounds(x1, p.y, frame.getWidth()>minWidth?(frame.getWidth()):minWidth, (y2 - p.y)>minHeight?(y2 - p.y):minHeight);
103                     break;
104                 case Cursor.S_RESIZE_CURSOR:
105                     frame.setBounds(x1, y1, frame.getWidth()>minWidth?(frame.getWidth()):minWidth, (p.y - y1)>minHeight?(p.y - y1):minHeight);
106                     break;
107                 case Cursor.NW_RESIZE_CURSOR:
108                     frame.setBounds(p.x, p.y, (x2 - p.x)>minWidth?(x2 - p.x):minWidth, (y2 - p.y)>minHeight?(y2 - p.y):minHeight);
109                     break;
110                 case Cursor.NE_RESIZE_CURSOR:
111                     frame.setBounds(x1, p.y, (p.x - x1)>minWidth?(p.x - x1):minWidth, (y2 - p.y)>minHeight?(y2 - p.y):minHeight);
112                     break;
113                 case Cursor.SW_RESIZE_CURSOR:
114                     frame.setBounds(p.x, y1, (x2 - p.x)>minWidth?(x2 - p.x):minWidth, (p.y - y1)>minHeight?(p.y - y1):minHeight);
115                     break;
116                 case Cursor.SE_RESIZE_CURSOR:
117                     frame.setBounds(x1, y1, (p.x - x1)>minWidth?(p.x - x1):minWidth, (p.y - y1)>minHeight?(p.y - y1):minHeight);
118                     break;
119                 }
120             }
121         });
122     }
123 
124                         
125  
126  
127 
128 

posted on 2009-06-18 09:42 rrong_m 阅读(714) 评论(0)  编辑  收藏

<2009年6月>
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011

导航

统计

常用链接

随笔档案

文章分类

文章档案

java编程

搜索

积分与排名

最新评论

阅读排行榜

评论排行榜