Note that there are some explanatory texts on larger screens.

plurals
  1. POthreads and swing components in java
    primarykey
    data
    text
    <p>As you see, I've been researching and tried to set a thread in <strong>main.java</strong> class. This is the main method:</p> <pre><code>public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new main().setVisible(true); check ch = new check(); ch.start(); } }); } </code></pre> <p>Main method calls a thread called <strong>ch</strong> , from <strong>check.java</strong> class.</p> <p>This is the thread class:</p> <pre><code>public class check extends Thread { public JTextArea estado = new JTextArea(); public JTextField updatedVersion = new JTextField(); public JLabel updatedLabel = new JLabel(); public String catchUpdatedVersion; int UPDATENUMBER; int CURRENTNUMBER; public void run() { String infURL = "https://thread.googlecode.com/svn/trunk/thread.inf"; String name = "thread.inf"; File file = new File(name); try { URLConnection conn = new URL(infURL).openConnection(); conn.connect(); estado.append("Conectando al servidor..."); estado.append(System.getProperty("line.separator")); estado.append(" -- Buscando actualizaciones... --"); estado.append(System.getProperty("line.separator")); InputStream in = conn.getInputStream(); OutputStream out = new FileOutputStream(file); int b = 0; while (b != -1) { b = in.read(); if (b != -1) { out.write(b); } } out.close(); in.close(); } catch (MalformedURLException ex) { } catch (IOException ioe) { } String fileToReadUpdatedVersion = "thread.inf"; try { BufferedReader br = new BufferedReader( new FileReader(fileToReadUpdatedVersion)); String brr = br.readLine(); catchUpdatedVersion = brr.substring(34,42); String catchUpdatedShortVersion = brr.substring(15,16); UPDATENUMBER = Integer.parseInt(catchUpdatedShortVersion); String fileToReadCurrentVer = "thread.inf"; BufferedReader brrw = new BufferedReader( new FileReader(fileToReadCurrentVer)); String brrwREAD = brrw.readLine(); String catchCurrentShortVersion = brrwREAD.substring(15,16); CURRENTNUMBER = Integer.parseInt(catchCurrentShortVersion); if (CURRENTNUMBER &gt;= UPDATENUMBER) { estado.setText("No se han encontrado actualizaciones."); } else { updatedVersion.setForeground(new Color(0,102,0)); updatedLabel.setForeground(new Color(0,153,51)); updatedVersion.setText(catchUpdatedVersion); estado.append("-------------------" + "NUEVA ACTUALIZACIÓN DISPONIBLE: " + catchUpdatedVersion + " -------------------");; estado.append(System.getProperty("line.separator")); estado.append("Descargando actualizaciones... " + "Espere por favor, no cierre este " + "programa hasta que esté completado..."); try { String updateURL = "https://thread.googlecode.com/" + "svn/trunk/thread.inf"; String updatedname = (catchUpdatedVersion + ".zip"); File updatedfile = new File(updatedname); URLConnection conn = new URL(updateURL).openConnection(); conn.connect(); estado.append(System.getProperty("line.separator")); estado.append(" Archivo actual: " + updatedname); estado.append(System.getProperty("line.separator")); estado.append(" Tamaño: " + conn.getContentLength() / 1000 / 1000 + " MB"); InputStream in = conn.getInputStream(); OutputStream out = new FileOutputStream(updatedfile); int c = 0; while (c != -1) { c = in.read(); if (c != -1) { out.write(c); } } out.close(); in.close(); } catch (MalformedURLException ex) { ex.printStackTrace(); } } } catch (IOException ioe) { System.out.println(ioe); ioe.printStackTrace(); } } } </code></pre> <p>When I run the program, the thread does not work fine. It is supposed to download a file and then display its progress in a JTextArea in <strong>main.java</strong> class. It does download the file, but nothing appears in JTextArea. </p> <p>Where is my mistake?</p> <p>EDIT: Showing all the code.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload