to querendo fazer um programinha tipo um sistema de sorteio…
mas assim, queria que quando apertar o botao ele fique mostrando bem rapido os numeros que ele vai sorteando em um Label e quando apertar em outro botao ele pare de sortear e mostre o numero sorteado…
eu consegui fazer mas quando ele entra no loop nao atualiza o Label… queria que ele atualizasse o Label toda vez que um numero fosse sorteado.
esse eh o metodo responsavel por sortear os numeros
P
pepinho
qual eh o nome do seu label??
pq nao vi nenhum setText ai.
vc tem q colocar: label.setText(valorString);
L
luiz.argenton
essa eh a classe completa
publicclassLabelPanelextendsjavax.swing.JPanel{booleansortear=false;privateintnumero;/** Creates new form LabelPanel */publicLabelPanel(){initComponents();}/** 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. */// <editor-fold defaultstate="collapsed" desc=" Código Gerado ">//GEN-BEGIN:initComponentsprivatevoidinitComponents(){java.awt.GridBagConstraintsgridBagConstraints;jLabel1=newjavax.swing.JLabel();jLabel2=newjavax.swing.JLabel();setLayout(newjava.awt.GridBagLayout());setBackground(newjava.awt.Color(255,255,255));jLabel1.setFont(newjava.awt.Font("Tahoma",0,60));jLabel1.setForeground(newjava.awt.Color(255,51,51));jLabel1.setText("SORTEIO");gridBagConstraints=newjava.awt.GridBagConstraints();gridBagConstraints.insets=newjava.awt.Insets(6,0,6,0);add(jLabel1,gridBagConstraints);jLabel2.setFont(newjava.awt.Font("Tahoma",0,55));jLabel2.setText("000");gridBagConstraints=newjava.awt.GridBagConstraints();gridBagConstraints.gridx=0;gridBagConstraints.gridy=1;gridBagConstraints.insets=newjava.awt.Insets(6,0,6,0);add(jLabel2,gridBagConstraints);}// </editor-fold>//GEN-END:initComponentspublicvoidsetLabelNumeroSorteado(Stringnumero){this.jLabel2.setText(numero);}publicvoidSortear(intnumero){inti=0;while(i<=2000000){intnumSorteado=(int)(1+(Math.random()*numero));this.setLabelNumeroSorteado(""+numSorteado);i++;}}publicvoidsetSortear(booleansorteio){this.sortear=sorteio;}// Declaração de variáveis - não modifique//GEN-BEGIN:variablesprivatejavax.swing.JLabeljLabel1;privatejavax.swing.JLabeljLabel2;// Fim da declaração de variáveis//GEN-END:variables}
tipo eu gostaria de saber se tem alguma maneira de fazer igual faz aquele Timer do Delphi…
vc inicia ele e de instante em instante ele chama um método… ai isto faz mudar o label
P
pepinho
existe sim o nome eh thread !!!
da uma olhadinha ai nu guj q vc encontra bastante coisa sobre o assunto pq eu nao manjo muito ainda da threads