导航:首页 > 编程语言 > java导入进度条

java导入进度条

发布时间:2024-06-04 14:45:03

Ⅰ 用 java 怎么做进度条

import java.awt.Canvas;
import java.awt.Color;
import java.awt.Graphics;

public class MyProgressBar extends Canvas {
private float scaleSize;
private float currentValue;

public MyProgressBar() {
this(100, 50);
}

public MyProgressBar(float scaleSize, float currentValue) {
this.scaleSize = scaleSize;
this.currentValue = currentValue;

this.setBackground(Color.lightGray);
this.setForeground(Color.magenta);
setSize(150, 25);
}

public float getCurrentValue() {
return currentValue;
}

public void setCurrentValue(float currentValue) {
this.currentValue = Math.max(0, currentValue);
if (this.scaleSize < this.currentValue) {
this.currentValue = this.scaleSize;
}
}

public float getScaleSize() {
return scaleSize;
}

public void setScaleSize(float scaleSize) {
this.scaleSize = Math.max(1.0f, scaleSize);
if (this.scaleSize < this.currentValue) {
this.scaleSize = this.currentValue;
}
}

public synchronized void paint(Graphics g) {
int w = getSize().width;
int h = getSize().height;

g.setColor(getBackground());
g.fillRect(1, 1, w - 2, h - 2);
g.fill3DRect(0, 0, w - 1, h - 1, true);

g.setColor(getForeground());
g.fillRect(3, 3, (int) (currentValue * (w - 6) / scaleSize), h - 6);
}
}

下面是程序执行入口点:
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;

public class TestMyProgressBar extends JFrame implements Runnable,
ActionListener {

private MyProgressBar bar;
private JButton btnStart;
static TestMyProgressBar tmpb;

public TestMyProgressBar() {
setSize(400, 300);
setLocation(400, 400);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setTitle("演示自定义进度条");
setLayout(new FlowLayout());
btnStart = new JButton("开始");
this.add(btnStart);
btnStart.addActionListener(this);
bar = new MyProgressBar();
setVisible(true);
}

public static void main(String[] args) {
tmpb = new TestMyProgressBar();
}

@Override
public void run() {
for (int i = 1; i <= 20; i++) {
int x = i * 5;
bar.setCurrentValue(x);
if (x > 0 && x < 100) {
btnStart.setEnabled(false);
}
if (x == 100) {
btnStart.setEnabled(true);
}
try {
Thread.sleep(200);
add(bar);

} catch (InterruptedException e) {
e.printStackTrace();
}
}
}

@Override
public void actionPerformed(ActionEvent e) {
if (e.getActionCommand().equals("开始")) {
Thread t = new Thread(tmpb);
t.start();
}
}
}

Ⅱ 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导入进度条

很简单,因为数据读到集合所用的时间远远不如数据库的存储,因此只要计算插入数据库的进度即可。做法是:在读入数据库的时候 根据集合的大小生成一个最大进度为集合长度的进度条,每成功写入数据库一条,进度条 +1。

Ⅳ 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导入进度条相关的资料

热点内容
安卓手机拍摄慢动作怎么设置 浏览:480
中国程序员加油 浏览:172
python去哪个城市比较多 浏览:759
闪迪u盘加密初始密码 浏览:773
房屋办理解压需要契税和发票吗 浏览:888
丽江易学java高级程序员 浏览:661
程序员木兰教程 浏览:665
pythontkinter按钮 浏览:439
如何快捷录音安卓 浏览:7
sd播放音乐需要哪些文件夹 浏览:839
华为平板m3怎么升级到安卓11 浏览:532
联通app排队号怎么看 浏览:647
怎么不越狱安装app 浏览:183
python怎么用链表 浏览:851
8k程序员面试题 浏览:541
贵州交警app怎么下载 浏览:414
解压缩安装包怎么安装 浏览:44
压缩机系统与装置 浏览:677
上海大众app怎么查保养记录 浏览:464
抖音网红一手资源解压密码 浏览:543