Salve ragazzi io ho queste due classi...il problema è che il thread non stampa nulla sulla jtextfield ecco le classi:
codice:public class Estrazioni extends Thread{ private int ritardo,numeroestratto; Estrazioni(int ritardo,int numeroestratto){ super(); this.ritardo=ritardo; this.numeroestratto=numeroestratto; } public void run(){ int tentativi=0,numeroestratto2=0; InterfacciaGrafica ig = new InterfacciaGrafica(); while(numeroestratto2!=numeroestratto){ try{ sleep(ritardo); numeroestratto2 = (int) Math.random()*20; tentativi++; ig.insntent.setText(""+tentativi); ig.insnestr.setText(""+numeroestratto2); ig.insnvinc.setText(""+numeroestratto); }catch(Exception e){ } } } }codice:import java.awt.*; import javax.swing.*; public class InterfacciaGrafica extends JFrame{ private JPanel pannello; public JTextField insnvinc,insnestr,insntent; InterfacciaGrafica(){ } InterfacciaGrafica(String titolo){ super(titolo); setSize(400,400); setLayout(null); pannello = new JPanel(); pannello.setLayout(null); pannello.setBackground(Color.white); pannello.setSize(400,400); getContentPane().add(pannello); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setResizable(true); JLabel numerovincente = new JLabel("Numero vincente"); numerovincente.setBounds(20, 30, 170, 60); numerovincente.setFont(new Font("",Font.ITALIC,20)); pannello.add(numerovincente); JLabel numeroestratto = new JLabel("Numero estratto"); numeroestratto.setBounds(20, 100, 170, 60); numeroestratto.setFont(new Font("",Font.ITALIC,20)); pannello.add(numeroestratto); JLabel numerotentativi = new JLabel("N tentativi"); numerotentativi.setBounds(20, 160, 170, 60); numerotentativi.setFont(new Font("",Font.ITALIC,20)); pannello.add(numerotentativi); insnvinc = new JTextField(); insnestr = new JTextField(); insntent = new JTextField(); insnvinc.setEditable(false); insnestr.setEditable(false); insntent.setEditable(false); insnvinc.setBounds(240, 30, 90, 60); insnvinc.setFont(new Font("",Font.ITALIC,20)); pannello.add(insnvinc); insnestr.setBounds(240, 100, 90, 60); insnestr.setFont(new Font("",Font.ITALIC,20)); pannello.add(insnestr); insntent.setBounds(240, 160, 90, 60); insntent.setFont(new Font("",Font.ITALIC,20)); pannello.add(insntent); Estrazioni e = new Estrazioni(200,(int)Math.random()*20); e.start(); setResizable(false); setVisible(true); } public void paint(Graphics g){ super.paint(g); g.drawLine(200, 450, 200, 0); } public static void main(String[] args) { InterfacciaGrafica ig = new InterfacciaGrafica("Estrazione Lotto"); } }

Rispondi quotando