当前位置:首页 » 多媒体相关

请问:如何实现通过点击不同的button改变下面不同面板的切换?


请问在应用程序中,如何实现通过切换工具栏中的按钮实现下面不同界面的改变?  
  请教大虾,给点思路?谢谢

推荐阅读

  • R9600核心 双敏火旋风9618战斗版仅499 [详细内容]
  • IT [详细内容]
  • IT [详细内容]
  • 低端重型武器 紫光ATI9600本本仅6.5K [详细内容]
  • 小i发声字典的变通实现 [详细内容]
  • IT [详细内容]
  • 力求突破 128M硕菁R9600移动版499上市 [详细内容]
  • 网友回答:
    网友:onefox

    这是以前做的一个小东西,里面的   mainface.java   大概跟您说地差不多  
      你可以参考一下思路何实现方法。      
       
       
      ===============================================================  
      /**  
        *       [mainface.java]         主体面板布局类  
        *    
        *   创建日期:(2003-8-2)  
        *   @author:one_fox  
        */  
         
      import   java.awt.*;  
      import   java.awt.event.*;  
      import   javax.swing.*;  
      import   javax.swing.border.*;  
       
       
       
      public   class   mainface   extends   jframe   {  
               
              //操作面板---------------------//  
              private   jpanel   searchface   =   null;  
              private   jpanel   addface   =   null;  
              private   jpanel   countface   =   null;  
               
              //界面组件---------------------//  
              private   jradiobutton   search   =   new   jradiobutton("查询",   true);  
              private   jradiobutton   add   =   new   jradiobutton("添加");  
              private   jradiobutton   count   =   new   jradiobutton("统计");  
              private   buttongroup   btgroup   =   new   buttongroup();  
       
              private   container   contentpane   =   this.getcontentpane();  
       
       
      /**  
      *   构造方法:  
      *   @param   searchface   jpanel     搜索面板  
      *   @param   addface   jpanel     添加面板  
      *   @param   countface   jpanel     统计面板  
      */      
              public   mainface(jpanel   searchface,   jpanel   addface,   jpanel   countface)   {  
                      this.searchface   =   searchface;  
                      this.addface   =   addface;  
                      this.countface   =   countface;  
                       
                      //界面制作------------------------//  
                      makeface();  
                      addlistener();  
              }  
       
       
      /**  
      *   方法:面板构建  
      */      
              private   void   makeface()   {  
                      btgroup.add(search);  
                      btgroup.add(add);  
                      btgroup.add(count);  
       
                      jpanel   uppanel   =   new   jpanel();  
                      uppanel.setlayout(new   flowlayout(flowlayout.center,   15,   3));  
                      uppanel.add(search);  
                      uppanel.add(add);  
                      uppanel.add(count);  
       
                      //总体布局----------------------//  
                      contentpane.add(uppanel,   borderlayout.north);  
                      contentpane.add(searchface,   borderlayout.center);  
              }  
               
               
      /**  
      *   方法:面板显示  
      */      
              public   void   showface()   {  
                      this.settitle("房改房资料管理系统");  
                      setsize(550,350);  
                      dimension   dime   =   toolkit.getdefaulttoolkit().getscreensize();  
                      setlocation(dime.width/2   -   275,   dime.height/2   -   175);  
                      setresizable(false);  
                      show();  
              }  
               
       
      /**  
      *   方法:事件监听  
      */      
              private   void   addlistener()   {  
                       
                      //添加窗口关闭事件------------------//  
                      this.addwindowlistener(new   windowadapter(){  
                              public   void   windowclosing(windowevent   e){  
                                      if(dbload.loader.getloader().disconnect())   {  
                                              dispose();  
                                              system.exit(0);  
                                      }  
                                      else   {  
                                              dispose();  
                                              system.exit(1);  
                                      }  
                              }  
                      });  
                       
                      //"查询"   按钮----------------------//  
                      search.addactionlistener(new   actionlistener(){  
                              public   void   actionperformed(actionevent   e){  
                                      contentpane.remove(addface);  
                                      contentpane.remove(countface);  
                                      contentpane.add(searchface,   borderlayout.center);  
                                      contentpane.repaint();  
                                      show();  
                              }  
                      });  
                       
                      //"添加"   按钮---------------------//  
                      add.addactionlistener(new   actionlistener(){  
                              public   void   actionperformed(actionevent   e){  
                                      contentpane.remove(searchface);  
                                      contentpane.remove(countface);  
                                      contentpane.add(addface,   borderlayout.center);  
                                      contentpane.repaint();  
                                      show();  
                              }  
                      });  
                       
                      //"统计"   按钮---------------------//  
                      count.addactionlistener(new   actionlistener(){  
                              public   void   actionperformed(actionevent   e){  
                                      contentpane.remove(searchface);  
                                      contentpane.remove(addface);  
                                      contentpane.add(countface,   borderlayout.center);  
                                      contentpane.repaint();  
                                      show();  
                              }  
                      });  
              }  
      }

    网友:abib

    jb做界面也不爽,还不如自己写  
      每个面板应该独立出来做的

    .

    讨论区

    Login