Berikut contoh program untuk menampilkan progres bar pada java.
Spoiler for Contoh Program:
Spoiler for Contoh Program:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Progress extends JFrame
{
JProgressBar current;
JTextArea out;
Thread runner;
int num = 0;
public Progress()
{
super("Progress");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel pane = new JPanel();
pane.setLayout(new FlowLayout());
current = new JProgressBar(0,2000);
current.setValue(0);
current.setStringPainted(true);
pane.add(current);
setContentPane(pane);
}
public void iterate()
{
while(num <= 2000)
{
current.setValue(num);
try
{
Thread.sleep(50);
}
catch(InterruptedException e) {
}
num += 10;
}
}
public static void main(String[] arguments)
{
Progress frame = new Progress();
frame.pack();
frame.setVisible(true);
frame.iterate();
}
}
import java.awt.event.*;
import javax.swing.*;
public class Progress extends JFrame
{
JProgressBar current;
JTextArea out;
Thread runner;
int num = 0;
public Progress()
{
super("Progress");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel pane = new JPanel();
pane.setLayout(new FlowLayout());
current = new JProgressBar(0,2000);
current.setValue(0);
current.setStringPainted(true);
pane.add(current);
setContentPane(pane);
}
public void iterate()
{
while(num <= 2000)
{
current.setValue(num);
try
{
Thread.sleep(50);
}
catch(InterruptedException e) {
}
num += 10;
}
}
public static void main(String[] arguments)
{
Progress frame = new Progress();
frame.pack();
frame.setVisible(true);
frame.iterate();
}
}
Hasil tampilan :
Comments :
Posting Komentar