java進度條
① 怎樣用java編寫個進度條,然後彈出消息框
安裝的j2sk下面有個demo,有詳細源代碼
具體目錄為:%JAVA_HOME%/demo/jfc/Java2D/Java2Demo.jar
② java web 伺服器端執行的進度條
開始頁面:start.jsp
<%@ page contentType="text/html; charset=GBK" %>
<% session.removeAttribute("task"); %>
<jsp:useBean id="task" scope="session" class="progress.TaskBean"/>
<% task.setRunning(true); %>
<% new Thread(task).start(); %>
<jsp:forward page="status.jsp"/>
狀態頁面:status.jsp
<%@ page contentType="text/html; charset=GBK" %>
<jsp:useBean id="task" scope="session" class="progress.TaskBean"/>
<HTML>
<HEAD>
<TITLE>JSP進度條</TITLE>
<% if (task.isRunning()) { %>
<script type="" LANGUAGE="JavaScript">
setTimeout("location='status.jsp'", 1000);
</script>
<% } %>
</HEAD>
<bODY bgcolor="">
<H1 ALIGN="CENTER">JSP進度條</H1>
<H2 ALIGN="CENTER">
結果: <%= task.getResult() %><BR>
<% int percent = task.getPercent(); %>
<%= percent %>%
</H2>
<TABLE WIDTH="60%" ALIGN="CENTER"
CELLPADDING=0 CELLSPACING=2>
<TR>
<% for (int i = 10; i <= percent; i += 10) { %>
<TD WIDTH="10%" height="10" BGCOLOR="red"> </TD>
<% } %>
<% for (int i = 100; i > percent; i -= 10) { %>
<TD WIDTH="10%"> </TD>
<% } %>
</TR>
</TABLE>
<TABLE WIDTH="100%" BORDER=0 CELLPADDING=0 CELLSPACING=0>
<TR>
<TD ALIGN="CENTER">
<% if (task.isRunning()) { %>
正在執行
<% } else { %>
<% if (task.isCompleted()) { %>
完成
<% } else if (!task.isStarted()) { %>
尚未開始
<% } else { %>
已停止
<% } %>
<% } %>
</TD>
</TR>
<TR>
<TD ALIGN="CENTER">
<BR>
<% if (task.isRunning()) { %>
<FORM METHOD="GET" ACTION="stop.jsp">
<INPUT TYPE="SUBMIT" ="停止">
</FORM>
<% } else { %>
<FORM METHOD="GET" ACTION="start.jsp">
<INPUT TYPE="SUBMIT" ="開始">
</FORM>
<% } %>
</TD>
</TR>
</TABLE>
</BODY></HTML>
停止頁面:stop.jsp
<%@ page contentType="text/html; charset=GBK" %>
<jsp:useBean id="task" scope="session" class="progress.TaskBean"/>
<% task.setRunning(false); %>
<jsp:forward page="status.jsp"/>
業務邏輯bean:TaskBean.java
package progress;
import java.io.Serializable;
public class TaskBean
implements Runnable, Serializable {
private int counter;
private int sum;
private boolean started;
private boolean running;
private int sleep;
public TaskBean() {
counter = 0;
sum = 0;
started = false;
running = false;
sleep = 100;
}
protected void work() {
try {
Thread.sleep(sleep);
counter++;
sum += counter;
}
catch (InterruptedException e) {
setRunning(false);
}
}
public synchronized int getPercent() {
return counter;
}
public synchronized boolean isStarted() {
return started;
}
public synchronized boolean isCompleted() {
return counter == 100;
}
public synchronized boolean isRunning() {
return running;
}
public synchronized void setRunning(boolean running) {
this.running = running;
if (running) {
started = true;
}
}
public synchronized Object getResult() {
if (isCompleted()) {
return new Integer(sum);
}
else {
return null;
}
}
public void run() {
try {
setRunning(true);
while (isRunning() && !isCompleted()) {
work();
}
}
finally {
setRunning(false);
}
}
}
③ java 做進度條 進度數據獲取
publicstaticvoidmain(String[]args){
intnum=20;
for(inti=0;i<=num;i++){
System.out.println("當前進度:"+i*100/num+"%"+i+"/"+num);
}
}
④ Java中如何實現進度條效果
import java.awt.Color; import java.awt.Toolkit; import javax.swing.ImageIcon; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JProgressBar; import javax.swing.JWindow; @SuppressWarnings("serial") public class Demo extends JWindow implements Runnable { // 定義載入窗口大小 public static final int LOAD_WIDTH = 455; public static final int LOAD_HEIGHT = 295; // 獲取屏幕窗口大小 public static final int WIDTH = Toolkit.getDefaultToolkit().getScreenSize().width; public static final int HEIGHT = Toolkit.getDefaultToolkit().getScreenSize().height; // 定義進度條組件 public JProgressBar progressbar; // 定義標簽組件 public JLabel label; // 構造函數 public Demo() { // 創建標簽,並在標簽上放置一張圖片 label = new JLabel(new ImageIcon("images/background.jpg")); label.setBounds(0, 0, LOAD_WIDTH, LOAD_HEIGHT - 15); // 創建進度條 progressbar = new JProgressBar(); // 顯示當前進度值信息 progressbar.setStringPainted(true); // 設置進度條邊框不顯示 progressbar.setBorderPainted(false); // 設置進度條的前景色 progressbar.setForeground(new Color(0, 210, 40)); // 設置進度條的背景色 progressbar.setBackground(new Color(188, 190, 194)); progressbar.setBounds(0, LOAD_HEIGHT - 15, LOAD_WIDTH, 15); // 添加組件 this.add(label); this.add(progressbar); // 設置布局為空 this.setLayout(null); // 設置窗口初始位置 this.setLocation((WIDTH - LOAD_WIDTH) / 2, (HEIGHT - LOAD_HEIGHT) / 2); // 設置窗口大小 this.setSize(LOAD_WIDTH, LOAD_HEIGHT); // 設置窗口顯示 this.setVisible(true); } public static void main(String[] args) { Demo t = new Demo(); new Thread(t).start(); } @Override public void run() { for (int i = 0; i < 100; i++) { try { Thread.sleep(100); } catch (InterruptedException e) { e.printStackTrace(); } progressbar.setValue(i); } JOptionPane.showMessageDialog(this, "載入完成"); this.dispose(); } }
⑤ java導入進度條
我寫了個拷貝文件的例子你看看也許對你會有幫助,我在這里用的是文件大小做進度,也可以用文件夾總大小來作總進度,用每個文件的大小做增加。
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import javax.swing.JFrame;
import javax.swing.JProgressBar;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author gang-liu
*/
public class FielTestor extends JFrame {
private File source, detination;
private InputStream fileIn;
private OutputStream fileOut;
private JProgressBar bar;
private static final int BUFFER_SIZE = 100;
private byte[] buffer;
public FielTestor(final String sourceFileName, final String destiFileName)
throws FileNotFoundException, IOException {
super();
source = new File(sourceFileName);
detination = new File(destiFileName);
fileIn = new FileInputStream(source);
fileOut = new FileOutputStream(detination);
bar = new JProgressBar(0, fileIn.available());
getContentPane().add(bar);
buffer = new byte[BUFFER_SIZE];
setSize(300, 50);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
validate();
int byteRead = 0;
while (byteRead >= 0) {
byteRead = fileIn.read(buffer);
fileOut.write(buffer);
bar.setValue(bar.getValue() + byteRead);
}
fileOut.close();
fileIn.close();
}
}
⑥ 用 java 怎麼做進度條
用servlet吧,網上有很多!
⑦ JAVA 進度條
import java.awt.BorderLayout;
import javax.swing.JFrame;
import javax.swing.JProgressBar;
public class Test extends JFrame {
public Test(){
super();
setSize(100,100);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
JProgressBar progressBar = new JProgressBar();
getContentPane().add(progressBar,BorderLayout.NORTH);
progressBar.setStringPainted(true);
for (int i = 0;i < 50;i++){
progressBar.setValue(i);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
public static void main(String[] args) {
new Test();
}
}
for循環裡面加了個延時函數。
⑧ 怎麼做java語言進度條
在js中做一個遮罩層,當你點擊的時候顯示進度條,進度條讀完之後再隱藏,以下有兩種方式,試試,望採納
方法一:
//開啟遮罩
$.messager.progress({});
或
$.messager.progress({
title: 'Please waiting',
msg: 'Loading data...',
text: 'PROCESSING.......'
});
//關閉遮罩
$.messager.progress('close');
方法二:
//顯示遮罩
$("#標簽ID").標簽("loading", "數據載入中……")
$("#dg").datagrid("loading", "數據載入中……");
//隱藏遮罩
$("#dg").datagrid("loaded");
⑨ java實現進度條
先要明確你怎樣控制進度條,然後分步控制。就是如果讓你把進度條加到50%,你如何加。
⑩ java的進度條如何獲取一個事件運行的時間
進度條在初始化後還可以修改最大值的,至於獲取時間完成時間。。一般不是獲取時間,比如我要向資料庫插入10萬條數據,那麼可以設置最大值為10萬這樣,實際上具體時間誰也不知道的。