大刀乱砍(详细信息的窗口对话框)

效果图:


下面代码....自己看...看了都不回帖!! 还想加注释????自己慢慢看

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 相信 阅读(742) 评论(2)  编辑  收藏 所属分类: Swing文章

评论

# re: 大刀乱砍(详细信息的窗口对话框) 2008-07-20 23:57 黑色

。。。。。。

虽然每一样代码都不是很多..

但是也看得出来你很认真的..

你到是越来越像写小说的了...


期待你更多的作品  回复  更多评论   

# re: 大刀乱砍(详细信息的窗口对话框) 2008-11-10 10:50 larrycheung

学习中。  回复  更多评论   


只有注册用户登录后才能发表评论。


网站导航:
 
<2024年3月>
252627282912
3456789
10111213141516
17181920212223
24252627282930
31123456

导航

统计

公告

不显示applet

常用链接

留言簿(16)

我参与的团队

随笔档案

文章分类

文章档案

新闻档案

相册

swingchina 专业搞Swing的网站

搜索

最新评论

阅读排行榜

评论排行榜