salve sapreste dirmi come legare la JProgressBar ad un processo?
mi spiego:
ho trovato il codice che posto qui... che mi fa visualizzare una progress bar con un tasto avvio...
il timer e settato da 0 a 100...
ora come faccio a collegare il timer all'esecuzione di un processo?
io ho un modulo che ad esempio ricerca delle cose all'interno di un testo...
come faccio a collegare questa barra al modulo, di modo che la barra inizi quando inizia la ricerca e finisce quando finisce la ricerca all'nterno del testo?
codice:ProgressBar() { JFrame frame = new JFrame(); frame.setTitle("Progress Bar"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setBounds(450, 300,280,100); JPanel content = new JPanel(new GridLayout(3, 1)); frame.add(content); content.add(new JLabel("Avanzamento corrente:"), SwingConstants.CENTER); bar = new JProgressBar(0, 200); bar.setValue(bar.getMinimum()); bar.setStringPainted(true); content.add(bar); button = new JButton("Avvio"); button.setSize(130,30); button.addActionListener(this); content.add(button); //frame.pack(); frame.setVisible(true); } /** * Esegue gli eventi action per un JButton e per un Timer */ public void actionPerformed(ActionEvent e) { if(e.getSource() instanceof JButton) { button.setEnabled(false); timer = new Timer(100, this); timer.start(); } else { int current = bar.getValue(); if(current < bar.getMaximum()) { bar.setValue(current + 1); } else { timer.stop(); } } }

Rispondi quotando

