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

java进度

发布时间: 2022-08-30 18:32:53

‘壹’ java实现进度条

先要明确你怎样控制进度条,然后分步控制。就是如果让你把进度条加到50%,你如何加。

‘贰’ 用 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多文件上传显示进度条

使用 apache fileupload ,spring MVC jquery1.6x , bootstrap 实现一个带进度条的多文件上传,由于fileupload 的局限,暂不能实现每个上传文件都显示进度条,只能实现一个总的进度条,效果如图:

packagecom.controller;

importjava.util.List;

importjavax.servlet.http.HttpServletRequest;
importjavax.servlet.http.HttpServletResponse;
importjavax.servlet.http.HttpSession;

importorg.apache.commons.fileupload.FileItemFactory;
importorg.apache.commons.fileupload.ProgressListener;
importorg.apache.commons.fileupload.disk.DiskFileItemFactory;
importorg.apache.commons.fileupload.servlet.ServletFileUpload;
importorg.apache.log4j.Logger;
importorg.springframework.stereotype.Controller;
importorg.springframework.web.bind.annotation.RequestMapping;
importorg.springframework.web.bind.annotation.RequestMethod;
importorg.springframework.web.bind.annotation.ResponseBody;
importorg.springframework.web.servlet.ModelAndView;

@Controller
{
Loggerlog=Logger.getLogger(FileUploadController.class);

/**
*upload上传文件
*@paramrequest
*@paramresponse
*@return
*@throwsException
*/
@RequestMapping(value="/upload.html",method=RequestMethod.POST)
publicModelAndViewupload(HttpServletRequestrequest,
HttpServletResponseresponse)throwsException{
finalHttpSessionhs=request.getSession();
ModelAndViewmv=newModelAndView();
booleanisMultipart=ServletFileUpload.isMultipartContent(request);
if(!isMultipart){
returnmv;
}
//Createafactoryfordisk-basedfileitems
FileItemFactoryfactory=newDiskFileItemFactory();

//Createanewfileuploadhandler
ServletFileUploapload=newServletFileUpload(factory);
upload.setProgressListener(newProgressListener(){
publicvoipdate(longpBytesRead,longpContentLength,intpItems){
ProcessInfopri=newProcessInfo();
pri.itemNum=pItems;
pri.readSize=pBytesRead;
pri.totalSize=pContentLength;
pri.show=pBytesRead+"/"+pContentLength+"byte";
pri.rate=Math.round(newFloat(pBytesRead)/newFloat(pContentLength)*100);
hs.setAttribute("proInfo",pri);
}
});
Listitems=upload.parseRequest(request);
//Parsetherequest
//Processtheuploadeditems
//Iteratoriter=items.iterator();
//while(iter.hasNext()){
//FileItemitem=(FileItem)iter.next();
//if(item.isFormField()){
//Stringname=item.getFieldName();
//Stringvalue=item.getString();
//System.out.println("thisiscommonfeild!"+name+"="+value);
//}else{
//System.out.println("thisisfilefeild!");
//StringfieldName=item.getFieldName();
//StringfileName=item.getName();
//StringcontentType=item.getContentType();
//booleanisInMemory=item.isInMemory();
//longsizeInBytes=item.getSize();
//FileuploadedFile=newFile("c://"+fileName);
//item.write(uploadedFile);
//}
//}
returnmv;
}


/**
*process获取进度
*@paramrequest
*@paramresponse
*@return
*@throwsException
*/
@RequestMapping(value="/process.json",method=RequestMethod.GET)
@ResponseBody
publicObjectprocess(HttpServletRequestrequest,
HttpServletResponseresponse)throwsException{
return(ProcessInfo)request.getSession().getAttribute("proInfo");
}

classProcessInfo{
publiclongtotalSize=1;
publiclongreadSize=0;
publicStringshow="";
publicintitemNum=0;
publicintrate=0;
}

}

‘伍’ 关于Java中进度条的问题

importjava.awt.BorderLayout;
importjava.awt.Cursor;
importjava.awt.Toolkit;
importjava.awt.event.ActionEvent;
importjava.awt.event.ActionListener;
importjava.beans.PropertyChangeEvent;
importjava.beans.PropertyChangeListener;
importjava.io.File;
importjava.io.FileInputStream;
importjava.io.FileOutputStream;
importjava.io.InputStream;
importjava.io.OutputStream;

importjavax.swing.JButton;
importjavax.swing.JFrame;
importjavax.swing.JProgressBar;
importjavax.swing.SwingWorker;


{
=1L;

;

privateJButton;

privateTasktask;

publicBar(Stringtitle)
{
setTitle(title);
setLayout(newBorderLayout());
progressBar=newJProgressBar(0,100);
progressBar.setValue(0);
progressBar.setStringPainted(true);

add(progressBar,BorderLayout.CENTER);
=newJButton("拷贝");
.addActionListener(newActionListener()
{
@Override
publicvoidactionPerformed(ActionEvente)
{
start();
.setEnabled(false);
}
});
add(,BorderLayout.EAST);
}

classTaskextendsSwingWorker<Void,Void>
{
@Override
publicVoiddoInBackground()
{
setProgress(0);
Filefile=newFile("aa.mp3");
longsize=file.length();
byte[]bts=newbyte[1024*10];
intlength=0;
longcLength=0;
try
{
InputStreamstream=newFileInputStream(file);
OutputStreamos=newFileOutputStream(newFile("a.mp3"));
while((length=stream.read(bts))>0)
{
os.write(bts,0,length);
cLength+=length;
setProgress((int)(cLength*100/size));
Thread.sleep(100);
}
os.close();
stream.close();
}
catch(Exceptione1)
{
e1.printStackTrace();
}
returnnull;
}

@Override
publicvoiddone()
{
setTitle("拷贝完毕");
Toolkit.getDefaultToolkit().beep();
.setEnabled(true);
setCursor(null);
}
}

publicvoidpropertyChange(PropertyChangeEventevt)
{
if("progress"==evt.getPropertyName())
{
intprogress=(Integer)evt.getNewValue();
progressBar.setValue(progress);
}
}

privatevoidstart()
{
task=newTask();
task.addPropertyChangeListener(this);
task.execute();
setTitle("正在拷贝...");
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
}

()
{
Barframe=newBar("Bar");
frame.setAlwaysOnTop(true);
frame.setSize(280,60);
frame.setResizable(false);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}

publicstaticvoidmain(String[]args)
{
javax.swing.SwingUtilities.invokeLater(newRunnable()
{
publicvoidrun()
{
createAndShowGUI();
}
});
}
}


‘陆’ java中怎样实现渐变色进度条

代码如下:
package test;

import java.awt.Color;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Insets;
import java.awt.geom.Point2D;
import java.util.ArrayList;
import java.util.Timer;
import java.util.TimerTask;

import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
import javax.swing.plaf.basic.BasicProgressBarUI;

public class test extends JFrame {

int current = 0;

public static void main(String[] args) {
new test().setVisible(true);
}

public test() {

JPanel contentPane = new JPanel();

setContentPane(contentPane);
contentPane.setBounds(0, 0, 400, 400);

final JProgressBar pbMusic = new JProgressBar();
pbMusic.setBounds(16, 38, 332, 4);
pbMusic.setValue(current);
pbMusic.setMaximum(100);
pbMusic.setUI(new GradientProgressBarUI());
pbMusic.setBorderPainted(false);
new Timer().schele(new TimerTask() {

@Override
public void run() {
pbMusic.setValue(current++);
}
}, 0, 1000);
contentPane.add(pbMusic);

setLocation(400, 200);
setSize(400, 400);
setVisible(true);
}
public class GradientProgressBarUI extends BasicProgressBarUI {
@Override
protected void paintDeterminate(Graphics g, JComponent c) {
Graphics2D graphics2d = (Graphics2D) g;

Insets b = progressBar.getInsets();
// JProgressBar的边界区域

int width = progressBar.getWidth();
int height = progressBar.getHeight();
int barRectWidth = width - (b.right + b.left);
int barRectHeight = height - (b.top + b.bottom);
int arcSize = height / 2 - 1;

int amountFull = getAmountFull(b, barRectWidth, barRectHeight);
//已完成的进度

graphics2d.setColor(Color.WHITE);
graphics2d.fillRoundRect(0, 0, width - 1, height, arcSize,
arcSize);
//绘制JProgressBar的背景

//用GradientPaint类来实现渐变色显示进度
//设置了开始点和终止点,并设置好这两个点的颜色,系统会自动在这两个点中用渐变色来填充
Point2D start = new Point2D.Float(0, 0);
Point2D end = new Point2D.Float(amountFull - 1, barRectHeight - 1);
//这里设置的终止点是当前已经完成的进度的那个点

GradientPaint gradientPaint = new GradientPaint(
start, new Color(114,243,233), end, new Color(233,243,123));

graphics2d.setPaint(gradientPaint);

graphics2d.fillRoundRect(b.left, b.top, amountFull - 1,
barRectHeight, arcSize, arcSize);//这里实现的是圆角的效果将arcSize调成0即可实现矩形效果
}
}
}

‘柒’ java学习进度跟不上怎么办

  1. 要多去熟悉相关的原理性知识

  2. 多动手去练习,不要怕懒,一遍不会多练习几遍

  3. 还是多练,熟能生巧。

    ps:如果涉及项目,必须要把业务逻辑理清再去写代码,最好是伪代码出来再去写代码。

‘捌’ java 做进度条 进度数据获取

publicstaticvoidmain(String[]args){
intnum=20;
for(inti=0;i<=num;i++){
System.out.println("当前进度:"+i*100/num+"%"+i+"/"+num);
}
}

‘玖’ 怎么做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");

热点内容
c语言二维数组程序 发布:2025-01-27 09:58:57 浏览:517
驱魔人ftp 发布:2025-01-27 09:57:12 浏览:657
服务器防护节点什么意思 发布:2025-01-27 09:51:47 浏览:184
git命令删除文件夹 发布:2025-01-27 09:45:49 浏览:367
手机版的电脑斗罗大陆服务器 发布:2025-01-27 09:43:11 浏览:798
androidopencv下载 发布:2025-01-27 09:35:19 浏览:320
python类函数重载 发布:2025-01-27 09:32:00 浏览:575
为什么提高财政资金配置效率 发布:2025-01-27 09:31:52 浏览:299
手机软件卸载缓存 发布:2025-01-27 09:27:54 浏览:38
aspnet图片缓存 发布:2025-01-27 09:24:10 浏览:222