当前位置:首页 » 编程语言 » java进度条

java进度条

发布时间: 2022-01-27 03:20:46

① 怎样用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万这样,实际上具体时间谁也不知道的。

热点内容
nas的监控存储 发布:2024-11-16 05:52:53 浏览:316
phpxml转换 发布:2024-11-16 05:47:10 浏览:955
内网服务器搭建什么公司做 发布:2024-11-16 05:36:24 浏览:594
如何利用map做本地缓存 发布:2024-11-16 05:34:37 浏览:539
w7恢复出厂设置密码是多少 发布:2024-11-16 05:23:49 浏览:791
方周编译器 发布:2024-11-16 05:23:12 浏览:660
数据库监控工具 发布:2024-11-16 05:23:07 浏览:958
存储器题型 发布:2024-11-16 05:23:06 浏览:86
怎么设置电脑配置信息 发布:2024-11-16 05:04:26 浏览:981
推荐系统php 发布:2024-11-16 05:03:42 浏览:12