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
-
How to map lookup main table field in another main table using MDM 7.1?
We created a new SAP MDM 7.1 repository with multiple main tables. The first main table is called ProductMaster table which contains Products information. The ProductCode is the primary key and the only display field for the table during data loadi
-
Skip lot across multiple batches for same material
Hi, I am looking for a way to control skip lots across multiple batches for the same material. We need to do a quality check in production after a certain quantity produced (on a machine, for a material). My idea was to do skip lots (for GR) until w
-
Updating Adobe Illustrator CS5 15.0.2-update Foutcode: U43M1D207
Get this Log report by updating Adobe Illustrator CS5 15.0.2-update Er is een fout opgetreden tijdens het downloaden van deze update. Sluit de download af en probeer het later opnieuw. Foutcode: U43M1D207
-
How to delete memory history for SMS on iphone 4
How do I delete my memory history on my iphone4. I have used the swipe delete method and the edit delete method--but the message still shows up in my serach spotlight function. Any help other than a total reset is what im looking for. Thanks
-
HT1338 Java Plug in not working?
I have re-installed java several times and can not get the plug in to work. So frustrating.