1 como crair um pregres bar em java Sáb Fev 07, 2015 8:17 pm
bolohue
Usuario
primer vc cria seu jframe
se vc n sober cria, ngm lga
agr vc adede iso no codegu:
e agr coloca iso dntro do seu ge freme:
pronto
se vc n sober cria, ngm lga
agr vc adede iso no codegu:
- Código:
private JProgressBar getProgressBar() {
if (progressBar == null) {
progressBar = new JProgressBar();
progressBar.setStringPainted(true);
}
return progressBar;
}
private JPanel getPanel() {
if (panel == null) {
panel = new JPanel();
panel.add(getBtnIniciar());
}
return panel;
}
private JButton getBtnIniciar() {
if (btnIniciar == null) {
btnIniciar = new JButton("Iniciar!");
btnIniciar.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
btnIniciar.setEnabled(false);
porcentagem = 0;
timer = new Timer(30, new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
porcentagem++;
progressBar.setValue(porcentagem);
if (porcentagem >= 100) {
timer.stop();
btnIniciar.setEnabled(true);
}
}
});
timer.start();
}
});
}
return btnIniciar;
}
private Timer timer;
private int porcentagem;
}
e agr coloca iso dntro do seu ge freme:
- Código:
contentPane.add(getProgressBar(), BorderLayout.NORTH);
contentPane.add(getPanel(), BorderLayout.SOUTH);
pronto