JAVA—咖啡館

          ——歡迎訪問rogerfan的博客,常來《JAVA——咖啡館》坐坐,喝杯濃香的咖啡,彼此探討一下JAVA技術,交流工作經驗,分享JAVA帶來的快樂!本網站部分轉載文章,如果有版權問題請與我聯系。

          BlogJava 首頁 新隨筆 聯系 聚合 管理
            447 Posts :: 145 Stories :: 368 Comments :: 0 Trackbacks

          公告

           

          Locations of visitors to this page
          點擊這里給我發消息 點擊這里給我發消息

          常用鏈接

          留言簿(17)

          隨筆分類(542)

          隨筆檔案(438)

          文章分類(182)

          文章檔案(142)

          新聞分類

          ※→ 【JAVA文檔】

          ※→ 【親人博客】

          ※→ 【休閑娛樂】

          ※→ 【友情鏈接】

          ※→ 【學習網站】

          ※→ 【服務網站】

          ※→ 【著名網站】

          ※→ 【阿里博客】

          最新隨筆

          搜索

          積分與排名

          最新評論

          閱讀排行榜

          評論排行榜

            1import java.awt.BorderLayout;
            2import java.awt.Color;
            3import java.awt.Cursor;
            4import java.awt.Dimension;
            5import java.awt.FlowLayout;
            6import java.awt.Font;
            7import java.awt.Point;
            8import java.awt.event.MouseAdapter;
            9import java.awt.event.MouseEvent;
           10import java.awt.event.MouseMotionAdapter;
           11import java.text.SimpleDateFormat;
           12import java.util.Date;
           13import java.util.HashMap;
           14import java.util.Map;
           15import javax.swing.BorderFactory;
           16import javax.swing.ImageIcon;
           17import javax.swing.JLabel;
           18import javax.swing.JOptionPane;
           19import javax.swing.JPanel;
           20import javax.swing.JScrollPane;
           21import javax.swing.JTextArea;
           22import javax.swing.SwingConstants;
           23import java.awt.Insets;
           24import java.awt.Toolkit;
           25import javax.swing.JDialog;
           26
           27public class VersionUtil
           28 private Map<String, String> feaMap = null;
           29 private Point oldP;//上一次坐標,拖動窗口時用
           30 private TipWindow tw = null;//提示框 
           31 private ImageIcon img = null;//圖像組件
           32 private JLabel imgLabel = null//背景圖片標簽
           33 private JPanel headPan = null;
           34 private JPanel feaPan =null;
           35 private JPanel btnPan = null;
           36 private JLabel title = null;
           37 private JLabel head = null;
           38 private JLabel close = null;//關閉按鈕
           39 private JTextArea feature = null
           40 private JScrollPane jfeaPan = null;
           41 private JLabel releaseLabel = null;
           42 private JLabel sure = null;
           43 private SimpleDateFormat sdf=null;
           44  
           45 {
           46  sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
           47  feaMap = new HashMap<String, String>(); 
           48  feaMap.put("name""中國信息大學固定資產管理系統");
           49  feaMap.put("release", sdf.format(new Date()));
           50  feaMap.put("feature""1.開發環境:windows\n2.開發語言:java\n3.開發工具:Eclipse3.2\n4.數據庫類型:SQL Server2005\n5.開發人員:花新昌\n6.聯系方式:15210477080");
           51 }

           52 
           53 public VersionUtil() {
           54  init();   
           55  handle();
           56  tw.setAlwaysOnTop(true);    
           57  tw.setUndecorated(true);
           58  tw.setResizable(false);
           59  tw.setVisible(true);
           60  tw.run();
           61 }

           62 public void init(){   
           63  //新建300x220的消息提示框
           64  tw = new TipWindow(300220);  
           65  img = new ImageIcon("background.gif");
           66  imgLabel = new JLabel(img);  
           67  //設置各個面板的布局以及面板中控件的邊界
           68  headPan = new JPanel(new FlowLayout(FlowLayout.CENTER, 00));
           69  feaPan = new JPanel(new FlowLayout(FlowLayout.CENTER, 00));
           70  btnPan = new JPanel(new FlowLayout(FlowLayout.CENTER, 00));
           71  title = new JLabel("歡迎使用本系統");
           72  head = new JLabel(feaMap.get("name"));
           73  close = new JLabel(" x");//關閉按鈕
           74  feature = new JTextArea(feaMap.get("feature")); 
           75  jfeaPan = new JScrollPane(feature);
           76  releaseLabel = new JLabel("登錄  " + feaMap.get("release"));  
           77  sure = new JLabel("確定");
           78  sure.setHorizontalAlignment(SwingConstants.CENTER);
           79  
           80  // 將各個面板設置為透明,否則看不到背景圖片
           81  ((JPanel) tw.getContentPane()).setOpaque(false);
           82  headPan.setOpaque(false);
           83  feaPan.setOpaque(false);
           84  btnPan.setOpaque(false);
           85  
           86  //設置JDialog的整個背景圖片
           87  tw.getLayeredPane().add(imgLabel, new Integer(Integer.MIN_VALUE));
           88  imgLabel.setBounds(00, img.getIconWidth(), img.getIconHeight());
           89  headPan.setPreferredSize(new Dimension(30060));
           90  
           91  //設置提示框的邊框,寬度和顏色
           92  tw.getRootPane().setBorder(BorderFactory.createMatteBorder(1111, Color.gray));
           93  
           94  title.setPreferredSize(new Dimension(26026));
           95  title.setVerticalTextPosition(JLabel.CENTER);
           96  title.setHorizontalTextPosition(JLabel.CENTER);
           97  title.setFont(new Font("宋體", Font.PLAIN, 12));
           98  title.setForeground(Color.black);
           99
          100  
          101  close.setFont(new Font("Arial", Font.BOLD, 15));
          102  close.setPreferredSize(new Dimension(2020));
          103  close.setVerticalTextPosition(JLabel.CENTER);
          104  close.setHorizontalTextPosition(JLabel.CENTER);
          105  close.setCursor(new Cursor(12));
          106  close.setToolTipText("關閉");
          107
          108  
          109  head.setPreferredSize(new Dimension(25035));
          110  head.setVerticalTextPosition(JLabel.CENTER);
          111  head.setHorizontalTextPosition(JLabel.CENTER);
          112  head.setFont(new Font("宋體", Font.PLAIN, 12));
          113  head.setForeground(Color.blue);
          114
          115  
          116  feature.setEditable(false);
          117  feature.setForeground(Color.red);
          118  feature.setFont(new Font("宋體", Font.PLAIN, 13));
          119  feature.setBackground(new Color(184230172));
          120  //設置文本域自動換行
          121  feature.setLineWrap(true);
          122
          123  jfeaPan.setPreferredSize(new Dimension(25080));
          124  jfeaPan.setBorder(null);
          125  jfeaPan.setBackground(Color.black);
          126  
          127  releaseLabel.setForeground(Color.DARK_GRAY);
          128  releaseLabel.setFont(new Font("宋體", Font.PLAIN, 12));
          129  
          130  //為了隱藏文本域,加個空的JLabel將他擠到下面去
          131  JLabel jsp = new JLabel();
          132  jsp.setPreferredSize(new Dimension(30025));
          133  
          134  sure.setPreferredSize(new Dimension(11030));
          135  //設置標簽鼠標手形
          136  sure.setCursor(new Cursor(12));
          137
          138  headPan.add(title);
          139  headPan.add(close);
          140  headPan.add(head);
          141  
          142  feaPan.add(jsp);
          143  feaPan.add(jfeaPan);
          144  feaPan.add(releaseLabel);
          145  
          146  btnPan.add(sure);
          147  
          148  tw.add(headPan, BorderLayout.NORTH);
          149  tw.add(feaPan, BorderLayout.CENTER);
          150  tw.add(btnPan, BorderLayout.SOUTH);  
          151 }

          152 
          153 public void handle() 
          154  //為更新按鈕增加相應的事件
          155  sure.addMouseListener(new MouseAdapter() {
          156   public void mouseClicked(MouseEvent e) {
          157    JOptionPane.showMessageDialog(tw, "謝謝,再見");
          158    tw.close();
          159   }

          160   public void mouseEntered(MouseEvent e) {
          161    sure.setBorder(BorderFactory.createLineBorder(Color.gray));
          162   }

          163   public void mouseExited(MouseEvent e) {
          164    sure.setBorder(null);
          165   }

          166  }
          );
          167  //增加鼠標拖動事件
          168  title.addMouseMotionListener(new MouseMotionAdapter(){
          169   public void mouseDragged(MouseEvent e) {
          170    // TODO Auto-generated method stub
          171    Point newP = new Point(e.getXOnScreen(), e.getYOnScreen());   
          172    int x = tw.getX() + (newP.x - oldP.x);
          173    int y = tw.getY() + (newP.y - oldP.y);
          174    tw.setLocation(x, y);
          175    oldP=newP;
          176    
          177   }
             
          178  }
          );
          179  //鼠標按下時初始坐標,供拖動時計算用
          180  title.addMouseListener(new MouseAdapter() {   
          181   public void mousePressed(MouseEvent e) {
          182    oldP = new Point(e.getXOnScreen(), e.getYOnScreen());
          183   }

          184  }
          );
          185  
          186  //右上角關閉按鈕事件
          187  close.addMouseListener(new MouseAdapter() {
          188   public void mouseClicked(MouseEvent e) {
          189    tw.close();
          190   }

          191
          192   public void mouseEntered(MouseEvent e) {
          193    close.setBorder(BorderFactory.createLineBorder(Color.gray));
          194   }

          195
          196   public void mouseExited(MouseEvent e) {
          197    close.setBorder(null);
          198   }

          199  }
          );
          200
          201 }

          202 public static void main(String args[]) {
          203  new VersionUtil();
          204 }

          205}

          206class TipWindow extends JDialog{   
          207 private static final long serialVersionUID = 8541659783234673950L;
          208 private static Dimension dim;   
          209    private int x,  y;   
          210    private int width,  height;   
          211    private static Insets screenInsets;     
          212  
          213   
          214    public TipWindow(int width,int height)
          215     this.width=width;
          216     this.height=height;
          217        dim = Toolkit.getDefaultToolkit().getScreenSize();   
          218        screenInsets   =   Toolkit.getDefaultToolkit().getScreenInsets(this.getGraphicsConfiguration()); 
          219        x = (int) (dim.getWidth() - width-3);   
          220        y = (int) (dim.getHeight()-screenInsets.bottom-3);  
          221     initComponents();
          222    }
            
          223    public void run() {   
          224        for (int i = 0; i <= height; i += 10{   
          225           try {   
          226                this.setLocation(x, y - i); 
          227                Thread.sleep(5);   
          228            }
           catch (InterruptedException ex) {      
          229            }
             
          230        }

          231        //此處代碼用來實現讓消息提示框5秒后自動消失
          232        try {
          233   Thread.sleep(5000);
          234  }
           catch (InterruptedException e) {
          235   // TODO Auto-generated catch block
          236   e.printStackTrace();
          237  }

          238        close();
          239    }
               
          240    private void initComponents() {   
          241        this.setSize(width, height);   
          242        this.setLocation(x, y);   
          243        this.setBackground(Color.black);        
          244    }
              
          245    public void close(){
          246     x=this.getX();
          247     y=this.getY();
          248     int ybottom=(int)dim.getHeight()-screenInsets.bottom;
          249     for (int i = 0; i <= ybottom-y; i += 10{   
          250            try {              
          251                setLocation(x, y+i); 
          252                Thread.sleep(5);                                   
          253            }
           catch (InterruptedException ex) {    
          254            }
             
          255        }
           
          256     dispose();
          257    }
           
          258}
           
          259
          260
          二。運行效果

          程序中使用的背景圖如下:


          posted on 2013-07-15 10:50 rogerfan 閱讀(3314) 評論(0)  編輯  收藏 所屬分類: 【Java知識】
          主站蜘蛛池模板: 托克逊县| 长沙县| 多伦县| 石柱| 唐河县| 河南省| 车致| 水城县| 岗巴县| 淄博市| 道孚县| 玛多县| 大城县| 南阳市| 鹰潭市| 江陵县| 莒南县| 常宁市| 沅陵县| 雷波县| 麦盖提县| 原平市| 博兴县| 利津县| 海兴县| 米林县| 当阳市| 滨海县| 电白县| 乌拉特中旗| 五家渠市| 米易县| 通州市| 迭部县| 冷水江市| 巍山| 南康市| 沅江市| 顺平县| 乌兰察布市| 高雄市|