国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

等待窗體的一種實現

2019-11-18 15:30:00
字體:
來源:轉載
供稿:網友

   在很多應用中,假如某一處理需要花費的時間比較長,應用應該提供一個比較人性化的提示。假如這個處理是由一個循環來實現的,則可以采用一個任務進度提示,其它情況可能就采用彈出一個類似于"系統正在處理,請稍后..."提示框的方式來達到目的。以下的代碼簡單實現了這一功能:

package test;
import javax.swing.*;
import java.awt.*;
import com.borland.jbcl.layout.*;
import javax.swing.border.*;

class PRogressPanel extends JPanel {
  JLabel jTip = new JLabel();
  JProgressBar jProgress = new JProgressBar();
  XYLayout xYLayout1 = new XYLayout();
  TitledBorder titledBorder1;
  public ProgressPanel() {
    try {
      jbInit();
    }
    catch(Exception e) {
      e.printStackTrace();
    }
  }
  public static void main(String[] args) {
    ProgressPanel progressPanel1 = new ProgressPanel();
  }
  private void jbInit() throws Exception {
    titledBorder1 = new TitledBorder("");
    jTip.setText("處理中...");
    jTip.setFont(new java.awt.Font("Dialog", 0, 12));
    this.setLayout(xYLayout1);
    jProgress.setOrientation(JProgressBar.HORIZONTAL);
    jProgress.setForeground(new Color(0, 0, 105));
    jProgress.setBorder(BorderFactory.createLoweredBevelBorder());
    jProgress.setStringPainted(true);
    xYLayout1.setWidth(258);
    xYLayout1.setHeight(75);
    this.setDebugGraphicsOptions(0);
    this.add(jTip, new XYConstraints(10, 1, -1, -1));
    this.add(jProgress,       new XYConstraints(5, 16, 249, 24));
  }
}

package test;
import java.awt.Window;
import java.awt.Dimension;
import java.awt.Toolkit;
import javax.swing.JFrame;
import javax.swing.JLabel;
import java.awt.Rectangle;
import javax.swing.SwingConstants;
import java.awt.GridBagLayout;

public class WaitingFrame {
    protected static Window winInc;
    private static WaitingFrame inc;

    private static JLabel jWaitTip;
    private static ProgressPanel proPanel;

    private static final String WAITING_TIP = "系統正在處理中,請稍后.....";
    private static final String PROGRESS_TIP = "處理中...";

    private static final int DEFAULT_WIDTH = 260;
    private static final int DEFAULT_HEIGHT = 45;

    private static int DEFAULT_LOCATEX;
    private static int DEFAULT_LOCATEY;

    private static boolean resetFlg = false;

    private static int maXProgress = 100;
    //當前顯示的窗口類型
    private int curType;

    /**
     * 等待窗口
     */
    public static final int WAITING = 0;

    /**
     * 進度條窗口
     */
    public static final int PROGRESS = 1;

    private WaitingFrame() {
    }

    /**
     * 獲取提示窗口實例
     * @param aType:窗口類型
     * @return
     */
    public synchronized static WaitingFrame getInstance(int aType){
        if(aType==PROGRESS){
            if(null==proPanel){
                proPanel = new ProgressPanel();
            }
        }else{
            if(null==jWaitTip){
                jWaitTip = new JLabel();
                jWaitTip.setFont(new java.awt.Font("Dialog", 0, 16));
                jWaitTip.setHorizontalAlignment(SwingConstants.CENTER);
                jWaitTip.setText(WAITING_TIP);
                jWaitTip.setBounds(new Rectangle(0, 0, 280, 98));
            }
        }
        if(null==inc){
            inc = new WaitingFrame();
            JFrame frm = new JFrame();
            frm.getContentPane().setLayout(new GridBagLayout());
            winInc = new Window(frm);
            if(aType==PROGRESS){
                inc.curType = aType;
                proPanel.jProgress.setMaximum(maxProgress);
                proPanel.jProgress.setValue(0);
                winInc.add(proPanel);
            }else{
                inc.curType = WAITING;
                winInc.add(jWaitTip);
            }
            winInc.setSize(DEFAULT_WIDTH,DEFAULT_HEIGHT);
            Dimension sysSize = Toolkit.getDefaultToolkit().getScreenSize();
            DEFAULT_LOCATEX = (sysSize.width-DEFAULT_WIDTH)/2;
            DEFAULT_LOCATEY = (sysSize.height-DEFAULT_HEIGHT)/2;;
        }else{
            if (aType == PROGRESS) {
                winInc.removeAll();
                proPanel.jTip.setText(PROGRESS_TIP);
                proPanel.jProgress.setValue(0);
                winInc.add(proPanel);
            }
            else {
                winInc.removeAll();
                jWaitTip.setText(WAITING_TIP);
                winInc.add(jWaitTip);
            }
        }
        inc.curType = aType;
        inc.resetFlg = false;
        return inc;
    }

QQread.com 推出各大專業服務器評測 linux服務器的安全性能 SUN服務器 HP服務器 DELL服務器 IBM服務器 聯想服務器 浪潮服務器 曙光服務器 同方服務器 華碩服務器 寶德服務器



發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 苗栗县| 普陀区| 吉木乃县| 松原市| 衡山县| 利川市| 抚顺县| 永登县| 通州市| 水城县| 安仁县| 兖州市| 越西县| 镇宁| 乌恰县| 来宾市| 黄大仙区| 长顺县| 丹巴县| 永修县| 和平区| 安庆市| 左贡县| 随州市| 宣武区| 通许县| 天峨县| 汨罗市| 陇川县| 河源市| 东源县| 杭州市| 桦南县| 辉县市| 蚌埠市| 四会市| 商南县| 阿合奇县| 平邑县| 巴林左旗| 晋宁县|