大刀亂砍(詳細信息的窗口對話框)

          效果圖:


          下面代碼....自己看...看了都不回帖!! 還想加注釋????自己慢慢看

          package MoreInfoPanel;

          import java.awt.BorderLayout;
          import java.awt.Component;
          import java.awt.Container;
          import java.awt.Font;
          import java.awt.Window;
          import java.awt.event.ActionEvent;
          import java.awt.event.ActionListener;

          import javax.swing.JButton;
          import javax.swing.JPanel;

          public class MoreInfoPanel extends JPanel {
              
              
          private JButton newsButton;
              
          public Component topComponent;
              
          protected SpinWidget spinWidget;
              
          public Component bottomComponent;

              
          public static final int SPIN_WIDGET_HEIGHT = 14;

              
          public MoreInfoPanel (Component tc, Component mic) {
                  topComponent 
          = tc;
                  spinWidget 
          = new SpinWidget( );
                  bottomComponent 
          = mic;
                  newsButton();
                  doMyLayout();
              }

              
          private void newsButton(){
                  newsButton 
          = new JButton();
                  newsButton.setFont(
          new Font("宋體",0,12));
                  newsButton.setText(
          "詳細信息");
                  newsButton.addActionListener(
          new ActionListener(){
                      
          public void actionPerformed(ActionEvent arg0) {
                          
          if(newsButton.getText().equals("詳細信息")){
                               spinWidget.setOpen(
          true);
                               resetBottomVisibility();
                               newsButton.setText(
          "點擊返回");
                               
          return;
                          }

                          
          if(newsButton.getText().equals("點擊返回")){
                               spinWidget.setOpen(
          false);
                               resetBottomVisibility();
                               newsButton.setText(
          "詳細信息");
                               
          return;
                          }

                          
                      }

                  }
          );
              }


              
          protected void doMyLayout( ) {
                  setLayout(
          new BorderLayout());
                  add(topComponent,BorderLayout.NORTH);
                  add(newsButton,BorderLayout.EAST);
                  add(spinWidget,BorderLayout.SOUTH);
                  add(bottomComponent,BorderLayout.CENTER);
                  resetBottomVisibility();
              }


              
          public void resetBottomVisibility() {
                   
          if ((bottomComponent == null||
                      (spinWidget 
          == null))
                       
          return;
                   bottomComponent.setVisible (spinWidget.isOpen());
                   revalidate();
                   
          if (isShowing()) {
                       Container ancestor 
          = getTopLevelAncestor(); 
                       
          if ((ancestor != null&& (ancestor instanceof Window))        
                           ((Window) ancestor).pack();
                       repaint();
                   }

               }

                  
               
          public void showBottom (boolean b) {
                   spinWidget.setOpen(b);
               }


                
          public boolean isBottomShowing ( ) {
                    
          return spinWidget.isOpen( );
                }

          }



          package MoreInfoPanel;

          import java.awt.Dimension;
          import java.awt.Graphics;
          import java.awt.Polygon;
          import java.awt.event.MouseAdapter;
          import java.awt.event.MouseEvent;

          import javax.swing.JPanel;

          public class SpinWidget extends JPanel {
              
          boolean open;

              
          int Integer = MoreInfoPanel.SPIN_WIDGET_HEIGHT;
              
              Dimension mySize 
          = new Dimension (Integer,
                                                Integer);
              
          final int HALF_HEIGHT = Integer / 2;
              
          int[] openXPoints =
                  
          1, HALF_HEIGHT, Integer-1};

              
          int[] openYPoints =
                  
          { HALF_HEIGHT, Integer-1, HALF_HEIGHT};
              
          int[] closedXPoints =
                  
          11, HALF_HEIGHT};
              
          int[] closedYPoints =
                  
          1, Integer-1, HALF_HEIGHT };
              Polygon openTriangle 
          =
                  
          new Polygon (openXPoints, openYPoints, 3);
              Polygon closedTriangle 
          =
                  
          new Polygon (closedXPoints, closedYPoints, 3);

              
          public SpinWidget( ) {
                  setOpen (
          false);
                  addMouseListener (
          new MouseAdapter( ) {

                          
          public void mouseClicked (MouseEvent e) {
                              handleClick( );
                          }

                      }
          );
              }


              
          public void handleClick() {
                  setOpen (
          ! isOpen( ));
              }


              
          public boolean isOpen( ) {
                  
          return open;
              }


              
          public void setOpen (boolean o) {
                  open 
          = o;
              }


              
          public Dimension getMinimumSize( ) return mySize; }
              
          public Dimension getPreferredSize( ) return mySize; }

              
          public void paint (Graphics g) {    
                  
          if (isOpen( )) 
                      g.fillPolygon (openTriangle); 
                  
          else 
                      g.fillPolygon (closedTriangle); 
              }
           
          }


          package MoreInfoPanel;

          import java.awt.*
          import javax.swing.*;

          public class TestMoreInfoPanel {

              
          public static void main (String[] args) {
                  JOptionPane pane 
          =
                      
          new JOptionPane ("想知道我的藏身之處嗎?請點擊詳細信息",
                                       JOptionPane.WARNING_MESSAGE);
                  JDialog dialog 
          = pane.createDialog (null"Warning");
                  Container grabbedContent 
          = dialog.getContentPane( );
                  JTextArea area 
          =
                      
          new JTextArea ("QQ群:22069957,經國際ISO9001國際認證.有品牌的群"
                                     
          540);
                  pane.setFont(
          new Font("宋體",0,12));
                  area.setFont(
          new Font("宋體",0,12));
                  area.setLineWrap (
          true);
                  area.setWrapStyleWord (
          true);

                  JScrollPane scroller 
          =
                      
          new JScrollPane (area, 
                                       ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, 
                                       ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
                  MoreInfoPanel mip 
          = new MoreInfoPanel (grabbedContent, scroller);
                  dialog.setContentPane (mip);
                  dialog.pack();
                  dialog.setVisible(
          true);
                  System.exit(
          0);
              }
           
          }

          posted on 2008-06-07 14:21 相信 閱讀(762) 評論(2)  編輯  收藏 所屬分類: Swing文章

          評論

          # re: 大刀亂砍(詳細信息的窗口對話框) 2008-07-20 23:57 黑色

          。。。。。。

          雖然每一樣代碼都不是很多..

          但是也看得出來你很認真的..

          你到是越來越像寫小說的了...


          期待你更多的作品  回復  更多評論   

          # re: 大刀亂砍(詳細信息的窗口對話框) 2008-11-10 10:50 larrycheung

          學習中。  回復  更多評論   

          <2025年7月>
          293012345
          6789101112
          13141516171819
          20212223242526
          272829303112
          3456789

          導航

          統計

          公告

          不顯示applet

          常用鏈接

          留言簿(16)

          我參與的團隊

          隨筆檔案

          文章分類

          文章檔案

          新聞檔案

          相冊

          swingchina 專業搞Swing的網站

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 大关县| 武冈市| 临清市| 文登市| 弥渡县| 珠海市| 古浪县| 盖州市| 新密市| 莒南县| 肇源县| 津南区| 邯郸市| 深泽县| 大埔区| 凌云县| 民县| 达拉特旗| 北辰区| 阿鲁科尔沁旗| 策勒县| 保山市| 旌德县| 阳城县| 武功县| 中牟县| 乌审旗| 巢湖市| 高陵县| 衡水市| 东明县| 石河子市| 乐陵市| 罗平县| 同德县| 香港 | 巴南区| 浠水县| 德江县| 阿图什市| 虹口区|