Cara Membuat Progressbar di java

nih gan berikut codingan cara membuat loading atau splash screen di java
package latihan_database;

import java.awt.*;
import javax.swing.*;
import javax.swing.border.Border;

public class floading extends javax.swing.JFrame {

 int a = 0;
 JProgressBar progressBar = new JProgressBar(0,100);
 JLabel label = new JLabel();
 Border border = BorderFactory.createTitledBorder("Mohon Tunggu ..... ");

    public floading() {
        initComponents();
 progressBar.setStringPainted(false);
 progressBar.setBorder(border);
 label.setText("Aplikasi Penerimaan Mahasiswa Baru");
 label.setFont(new Font("Tahoma", 1, 16));
 JPanel content = (JPanel) getContentPane();
 content.setBackground(Color.red);
 content.setBorder(BorderFactory.createLineBorder(Color.yellow,5));
    setLayout(null);
    add(label);
    label.setBounds(15, 10, 315, 50);
    Component add = add(progressBar);
    progressBar.setBounds(10, 100, 315, 40);
    setSize(345, 200);
    setVisible(true);
     setLocationRelativeTo(null);
        setDefaultCloseOperation(3);
        while (a<=100)
        {
            progressBar.setValue(a);
            try
            {
                Thread.sleep(80);
               
            }
            catch(InterruptedException e)
            {
            }
            a++;
           
        }
        this.dispose();
        new login().setVisible(true);
           
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

        jProgressBar1 = new javax.swing.JProgressBar();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(90, 90, 90)
                .addComponent(jProgressBar1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(164, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(247, Short.MAX_VALUE)
                .addComponent(jProgressBar1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(39, 39, 39))
        );

        pack();
    }// </editor-fold>

    public static void main(String args[]) {
        try{
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
            new floading();
           
        }
        catch (Exception e)
        {
           
        }
       
    }
    // Variables declaration - do not modify
    private javax.swing.JProgressBar jProgressBar1;
    // End of variables declaration
}

1 komentar:

  1. maff, mau tanya sedikit untuk peletakan coding tersebut di bagian yang mana ya?
    soalnya saya sudah buatkan jframe untuk login beserta even nya.
    mohon banttuannya.

    BalasHapus