Swing_Thread

Hi, i've got this bingo app, but i get a probelm when printing the numbers through the JtextArea, it works properly when usin System.out.println, but it gets stuck with JTextArea.appen(...); I know its somthing to do with the thread, but dunno how to solve it, thx!
package bingo;
* @author  Mele
public class Vista extends javax.swing.JFrame {
    boolean[] Used;
    int C = 0;
    public Vista() {
        initComponents();
        Used = new boolean[100];
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {
        jPanel1 = new javax.swing.JPanel();
        BJugar = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        Area1 = new javax.swing.JTextArea();
        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        jPanel1.setBackground(new java.awt.Color(255, 0, 204));
        BJugar.setText("JUGAR");
        BJugar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BJugarActionPerformed(evt);
        Area1.setColumns(20);
        Area1.setRows(5);
        jScrollPane1.setViewportView(Area1);
        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(143, 143, 143)
                .addComponent(BJugar)
                .addContainerGap(142, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(94, Short.MAX_VALUE)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(90, 90, 90))
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(BJugar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(48, Short.MAX_VALUE))
        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        pack();
    }// </editor-fold>
    private void BJugarActionPerformed(java.awt.event.ActionEvent evt) {                                      
        Cuerpo();
    public void Cuerpo(){
        ini();
        for (int x = 0; x < 100; x++) {
            int r = N();
            if (Used[r]) {
                while (Used[r]) {
                    r = N();
            waits();
            //Thread.kill();
            Area1.append(C + ": " + r + "\n");
            System.out.println(C + ":" + r);
            C++;
            Used[r] = true;
    public void ini() {
        for (int x = 0; x < 100; x++) {
            Used[x] = false;
    public void waits() {
        try {
            Thread.sleep(2000);
        } catch (Exception e) {
            e.printStackTrace();
    public int N() {
        int r = new Double(Math.random() * 100).intValue();
        return (r);
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Vista().setVisible(true);
    // Variables declaration - do not modify
    private javax.swing.JTextArea Area1;
    private javax.swing.JButton BJugar;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    // End of variables declaration
}

Understood and running, thank you so much Encephalopathic , muchas gracias!
package bingo;
import javax.swing.Timer;
import java.awt.event.*;
* @author  Diego
public class Vista extends javax.swing.JFrame {
    int r;
    boolean[] Used;
    int[] News;
    int C = 0;
    int delay = 2000; //milliseconds
    ActionListener taskPerformer = new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
        tarea();
    public Vista() {
        initComponents();
        Used = new boolean[100];
        News=new int[100];
    public void Cuerpo() {
        ini();
        for (int x = 0; x < 100; x++) {
             r = N();
            if (Used[r]) {
                while (Used[r]) {
                    r = N();
           News[x]=r;
            Used[r] = true;
        new Timer(delay, taskPerformer).start();
public void tarea(){
            Area1.append(News[C]+ "\n");
            C++;
    public void ini() {
        for (int x = 0; x < 100; x++) {
            Used[x] = false;
    public int N() {
        int r = new Double(Math.random() * 100).intValue();
        return (r);
    }

Similar Messages

Maybe you are looking for