📄 dialogoprogresoarchivo.java
字号:
/* * To change this template, choose Tools | Templates * and open the template in the editor. *//* * dialogoProgresoArchivo.java * * Created on 31/03/2009, 01:50:12 PM */package vista;import java.util.Observable;import java.util.Observer;import javax.swing.JOptionPane;/** * * @author Camilo Andres */public class dialogoProgresoArchivo extends javax.swing.JFrame implements Observer { private String nombreArchivo; private long sizeFile; /** Creates new form dialogoProgresoArchivo */ public dialogoProgresoArchivo() { initComponents(); this.setVisible(true); } public dialogoProgresoArchivo(String nombreArchivo, long sizeFile) { this.nombreArchivo = nombreArchivo; this.sizeFile = sizeFile; initComponents(); this.setVisible(true); setTitle("Descargando: "+nombreArchivo); } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { jProgressBar1 = new javax.swing.JProgressBar(); jLabel1 = new javax.swing.JLabel(); setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE); setTitle("Descargando:"); setResizable(false); jProgressBar1.setName("jProgressBar1"); // NOI18N jLabel1.setFont(new java.awt.Font("Arial", 3, 12)); // NOI18N jLabel1.setText("Descargando.....10%"); jLabel1.setName("jLabel1"); // NOI18N javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap(50, Short.MAX_VALUE) .addComponent(jProgressBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 303, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(47, 47, 47)) .addGroup(layout.createSequentialGroup() .addGap(125, 125, 125) .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 146, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(129, Short.MAX_VALUE)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(51, 51, 51) .addComponent(jProgressBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(39, 39, 39) .addComponent(jLabel1) .addContainerGap(45, Short.MAX_VALUE)) ); pack(); }// </editor-fold>//GEN-END:initComponents /** * @param args the command line arguments */ public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new dialogoProgresoArchivo().setVisible(true); } }); } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JLabel jLabel1; private javax.swing.JProgressBar jProgressBar1; // End of variables declaration//GEN-END:variables public void update(Observable o, Object arg) { long byteRx=(Long)(arg); int porcentaje=(int)(100.0*(double)byteRx/(double)sizeFile); jProgressBar1.setValue(porcentaje); jLabel1.setText("Descargando......"+porcentaje+"%"); setTitle("Descargando: "+nombreArchivo+"--"+porcentaje+"%"); if (porcentaje>=100) { JOptionPane.showMessageDialog(null, "Descarga exitosa"); dispose(); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -