How to use GUI in c language?Which is best GUI for c?

How do i use threads in a GUI in java?

  • I am trying to make a command line program and i can't seem to understand how to use threads in a GUI. Please explain in plain english and give examples. Thank y

  • Answer:

    I made you a simple example using a JLabel, with an increasing number using a thread well actually i let the class extend thead, so the class is a Thread itself, maybe its helpful: import java.awt.BorderLayout; import javax.swing.JFrame; import javax.swing.JLabel; public class LabelThread extends Thread implements Runnable{ int i=1; private JLabel label=new JLabel(i+""); private boolean running=true; public static void main(String [ ] args) { new LabelThread(); } public LabelThread() { JFrame f=new JFrame(); f.setSize(200,200); f.setVisible(true); f.add(label,BorderLayout.CENTER); start(); } @Override public void run() { while(running) { i++; System.out.println(i+""); label.setText(i+""); try { Thread.sleep(100); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } if(i==100) { running=false; } } } }

Robert S at Yahoo! Answers Visit the source

Was this solution helpful to you?

Other answers

What does a GUI have to do with threads? Threads are quite a complex concept (especially in dealing with concurrency), maybe if you need to ask this question then you are not yet experienced enough to learn about threads.

I Don't Eat Vodka

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.