Advice wanted: do i need threads or not?Stuck!

Hi, everyone! I got stuck with little program I'm writing and need your advice desperately.
I am doing temperature conversion program. In short, it's an applet with two JTextFields and four panels. JTextFields belong to the applet. Two panels are derivatives from my class called BasicThermometer extends JPanel. I made this class as flexible as I could, and it can draw pretty thermometer with needed ticks and ticks' labels as needed.
So, I've put two BasicTherm-s into my applet representing Celsius and Fahrenheit therm-rs respectively.
Other two panels are derivatives from my GradientPanel extends JPanel. They have gradient painted background with red and blue colors.
OK, here my final goal. When user input temp. to be converted in either text field converted temp. appears in other text field and tungsten of each therm-r reacts accordingly (I did that).
I can not accomplish my other task. Tungsten of each therm. responds on mouse event, so the user can input temp. by dragging or clicking it on either therm-r.( It's reacting allright). I want the temperature appear in each textfield and other therm-r tungsten move accordingly. I am unable to determine wether I need threads in it and if I do, how to design them. Should it be one thread or two? I am very new to multithreading and everything there is still blur to me. Also I'd like my gradient panels to react by fading gradient or thicken it on red (upper) panel or blue(lower panel).
I already set it flexible, so it's not a problem if I only could coordinate all my events properly.
Any advice will be helpful for me. I mean, maybe I have to change something in my classes-subclasses. To create new constructors maybe? How to deliver events from one JPanel so that the applet knew and pass it to other JPanel (i.e. to other BasicThermometer) so to repaint it as I want.In my thinking there could be thread or two that constatly tested one or other therm-r (while GUI thread is idling) and pass results to applet's method which resets other therm-r. Yesterday I failed to make them work. They worked two rounds right after start() even though my permit was set to false in each of the thermometers, and then stopped and did not wake if I clicked on either therm (I tested them by passing messages to be displayed in DOS).
Well, I am very confused. Sorry for lengthy message.
Svetlana

try my code
import java.awt.*;
import java.applet.Applet;
import java.awt.event.*;
<applet code="CtoFConversion1.class" width=170 height = 170>
</applet>
public class CtoFConversion1 extends Applet implements ActionListener, ItemListener {
float c=0.0f;
float f=0.0f;
String msg="";
Checkbox checkbox1, checkbox2;
CheckboxGroup cbg;
TextField tf1,tf2;
Button convert, reset;
public void init() {
cbg = new CheckboxGroup();
checkbox1 = new Checkbox("Convert C to F",cbg, true);
checkbox2 = new Checkbox("Convert F to C",cbg, false);
convert = new Button("Convert");
reset = new Button("Reset");
Label centigrade = new Label("Centigrade :", Label.RIGHT);
Label fahrenheit = new Label("Fahrenheit :", Label.RIGHT);
tf1 = new TextField(10);
tf2 = new TextField(10);
add(checkbox1);
add(checkbox2);
add(centigrade);
add(tf1);
add(fahrenheit);
add(tf2);
add(convert);
add(reset);
checkbox1.addItemListener(this);
checkbox2.addItemListener(this);
tf1.addActionListener(this);
tf2.addActionListener(this);
convert.addActionListener(this);
reset.addActionListener(this);
tf2.setEditable(false);
public void itemStateChanged(ItemEvent ie) {
if((cbg.getSelectedCheckbox().getLabel()).equals("Convert C to F")) {
tf2.setEditable(false);
tf1.setEditable(true);
repaint();
if((cbg.getSelectedCheckbox().getLabel()).equals("Convert F to C")) {
tf1.setEditable(false);
tf2.setEditable(true);
repaint();
public void actionPerformed(ActionEvent ae) {
String command = ae.getActionCommand();
if(command.equals("Convert")) {
if((cbg.getSelectedCheckbox().getLabel()).equals("Convert C to F")) {
tf2.setEditable(false);
tf1.setEditable(true);
msg = tf1.getText();
try {
c = new Float(msg).floatValue();
msg="";
centi(c);
msg = msg+f;
tf2.setText(msg);
repaint();
}catch(NumberFormatException e){
tf2.setText("Syntax Error");
else if((cbg.getSelectedCheckbox().getLabel()).equals("Convert F to C")) {
tf1.setEditable(false);
tf2.setEditable(true);
msg = tf2.getText();
try {
c = new Float(msg).floatValue();
msg="";
fahren(c);
msg = msg+f;
tf1.setText(msg);
repaint();
}catch(NumberFormatException e){
tf1.setText("Syntax Error");
else if (command.equals("Reset")) {
tf2.setEditable(false);
tf1.setText("");
tf1.setEditable(true);
tf2.setText("");
checkbox1.setState(true);
repaint();
public float centi(float c){
f = (float)(1.8*c)+32.0f;
return f;
public float fahren(float c){
f = (float)(0.5556*(c-32.0));
return f;
}

Similar Messages

  • I have a problem in this that i want to paas a form in a case that when user pres n then it must go to a form but error arises and not working good and threading is not responding

    made in cosmos help please need it
    using System;
    using Cosmos.Compiler.Builder;
    using System.Threading;
    using System.Windows.Forms;
    namespace IUOS
        class Program
            #region Cosmos Builder logic
            // Most users wont touch this. This will call the Cosmos Build tool
            [STAThread]
            static void Main(string[] args)
                BuildUI.Run();
            #endregion
            // Main entry point of the kernel
            public static void Init()
                var xBoot = new Cosmos.Sys.Boot();
                xBoot.Execute();
                Console.ForegroundColor = ConsoleColor.DarkBlue;
                a:
                Console.WriteLine("------------------------------");
                Console.WriteLine("WELCOME TO THE NEWLY OS MADE BY THE STUDENTS OF IQRA UNIVERSITY!");
                Console.WriteLine("------------------------------");
                Console.WriteLine();
                Console.WriteLine();
                Console.WriteLine();
                Console.WriteLine("\t _____                                
                Console.WriteLine("\t|     |        |            |        
    |            |      |");
                Console.WriteLine("\t|     |        |            |        
    |            |      |");
                Console.WriteLine("\t|     |        |            |        
    |            |      |");
                Console.WriteLine("\t|     |        |            |        
    |            |      |___________");
                Console.WriteLine("\t|     |        |            |        
    |            |                  |");
                Console.WriteLine("\t|     |        |            |        
    |            |                  |");
                Console.WriteLine("\t|     |        |            |        
    |            |                  |");
                Console.WriteLine("\t|     |        |            |        
    |            |                  |");
                Console.WriteLine("\t|     |        |            |        
    |            |                  |");
                Console.WriteLine("\t|_____|        |____________|         |____________|      ____________");
                string input;
                Console.WriteLine();
                Console.Write("\nAbout OS     : a");
                Console.Write("\nTo Shutdown  : s");
                Console.Write("\nTo Reboot    : r");
                Console.Write("\nStart Windows Normaly : n");
                Console.WriteLine();
                input = Console.ReadLine();
                if (input == "s" || input == "S"){
                    Cosmos.Sys.Deboot.ShutDown();
                else
                if (input == "r" || input == "R"){
                    Cosmos.Sys.Deboot.Reboot();
                else
                if (input == "a" || input == "A"){
                    Console.ForegroundColor = ConsoleColor.DarkBlue;
                    Console.Clear();
                    Console.WriteLine("\n\n\n-------------------------------------");
                    Console.WriteLine("version: DISPLAYS OS VERSION");
                    Console.WriteLine("about: DISPLAYS INFO ABOUT ANGRY OS");
                    Console.WriteLine("hello or hi: DISPLAYS A HELLO WORLD");
                    Console.WriteLine("MESSAGE THAT WAS USED TO TEST THIS OS!!");
                    Console.WriteLine("-----------------------------------");
                    Console.Write("You Want to know : ");
                    input = Console.ReadLine();
                    if (input == "version"){
                        Console.WriteLine("--------------------");
                        Console.WriteLine("OS VERSION 0.1");
                        Console.WriteLine("--------------------");
                    else
                    if (input == "about"){
                        Console.WriteLine("--------------------------------------------");
                        Console.WriteLine("OS IS DEVELOPED BY Qazi Jalil-ur-Rahman & Syed Akber Abbas Jafri");
                        Console.WriteLine("--------------------------------------------");
                    Console.Write("Want to go back to the main window");
                    Console.Write("\nYes : ");
                    string ans = Console.ReadLine();
                    if (ans == "y" || ans == "Y")
                        goto a;
                        Thread.Sleep(10000);
                    else
                    if (input == "n" || input == "N")
                        Thread.Sleep(5000);
                        Console.Clear();
                        for (int i = 0; i <= 0; i++){
                            Console.Write("\n\n\n\n\t\t\t\t\t  ____        ____   ___  
                            Console.Write("\n\t\t|\t\t |  |      |    |     
    |   |  | |  |  |");
                            Console.Write("\n\t\t|\t|    |  |----  |    |     
    |   |  | |  |  |---");
                            Console.Write("\n\t\t|____|____|  |____  |___ |____  |___|  |    |  |___");
                            Thread.Sleep(500);
                        Thread.Sleep(5000);
                        Console.Clear();
                        BootUserInterface();
                        Console.ReadLine();
    //                    Form1 fo = new Form1();
                    else{
                        for (int i = 0; i <= 5; i++){
                            Console.Beep();
                            Thread.Sleep(1000);
                            goto a;
                while (true);
            private static void BootUserInterface() {
                Thread t = new Thread(UserInterfaceThread);
                t.IsBackground = true;
                t.SetApartmentState(ApartmentState.STA);
                t.Start();
            private static void UserInterfaceThread(object arg) {
                Form1 frm = new Form1();  // use your own
                Application.Run(frm);
     

    Hi
    Jalil Cracker,
    >>when user pres n then it must go to a form but error arises and not working good and threading is not respondin
    Could you post the error information? And which line caused this error?
    If you want to show Form1, you can use form.show() method
    Form1 frm = new Form1();
    frm.Show();
    In addition, Cosmos is an acronym for C# Open Source Managed Operating System. This is not Microsoft product.If the issue is related to Cosmos, it would be out of our support. Thanks for your understanding. And you need raise an issue at Cosmos site.
    Best regards,
    kristin
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • I am trying to use powerpoint but when I open a document I want to work on it does not open on my desktop. It appears as open on mission control but it disappears offscreen. How can I get it to open where i need it and can work on it?

    I am trying to use powerpoint but when I open a document I want to work on it does not open on my desktop. It appears as open on mission control but it disappears offscreen. How can I get it to open where i need it and can work on it?

    It's almost certainly too late.
    The time to create a backup is before a catastrophe.  After a catastrophe, it's too late.

  • My ipod touch is in DFU mode 5g I need help, do not want to lose my data, please help in Spanish

    I need help, do not want to lose my data, PLEASE HELP IN SPANISH

    Una vez que el dispositivo está pidiendo ser restaurado con iTunes ... ya es demasiado tarde para salvar nada ... y usted debe continuar con la recuperación de ...
    Vea aquí> http://support.apple.com/kb/HT1808
    Es posible que tenga que probar más de una vez ... Asegúrese de seguir todos los pasos ...
    Tómese su tiempo ... Preste especial atención a los pasos 3 y 4.
    Para minimizar la pérdida ...
    Después de haber recuperado su dispositivo ...
    Re-sincronizar su contenido o restauración de la última copia de seguridad ...
    Restaurar desde copia de seguridad> http://support.apple.com/kb/ht1766
    Once the Device is asking to be Restored with iTunes... it is too late to save anything... and you must continue with the Recovery...
    See Here  >  http://support.apple.com/kb/HT1808
    You may need to try this More than Once...  Be sure to Follow ALL the Steps...
    Take your time... Pay particular attention to Steps 3 and 4.
    To minimise loss...
    After you have Recovered your Device...
    Re-Sync your Content or Restore from the most recent Backup...
    Restore from Backup  >  http://support.apple.com/kb/ht1766

  • How do I reorganize my photos on iPad 2?  I need to move (not copy) photos from one album to another.  When I use the copy function to another album, and then try to delete an image from the original album, the system wants to delete the photos from all a

    How do I reorganize my photos on iPad 2?  I need to move (not copy) photos from one album to another.  When I use the copy function to another album, and then try to delete an image from the original album, the system wants to delete the photos from all albums.  Please help.

    You can't do it directly on the iPad - the new album functionality basically only allows you to copy photos into those new albums, you can't move them. The way that I think of it as working is that you are just creating pointers to the photos in those new albums, so if you then delete the original photo on the iPad you therefore automatically delete all the pointers to it.
    If you want to re-organise your albums then you will need to do it on your computer and then sync those albums over to the iPad

  • Iphone 3gs software update version 6.1.6 not able to do it need help and also want to know if i do not update it will my phone stop working

    Hi I am getting a message of updating my iphone 3gs software version ios 6.1.6 but i am not getting an option to download it how can i update this version on my phone and if i will not update it will my phone stop working i am confused as i tried a lot online to search and download for it but not find it and now want rectification of it and also want to know if i do not update it what will happen next. please a little help required in this if its possible please reply on this as i am in need of this phone and do not want it that it should stop working just bcoz of it

    manubakshi26 wrote:
    Hi I am getting a message of updating my iphone 3gs software version ios 6.1.6 but i am not getting an option to download it how can i update this version
    Do the Update using iTunes on your Computer.
    See the Using iTunes Section Here...
    How to update your iPhone, iPad, or iPod touch
    Make sure you have the Latest Version of iTunes (v11.1.5) Installed on your computer
    iTunes free download from www.itunes.com/download

  • Just want to say that's Block pop-up windows it's realy need to fix not work ever i think in Microsoft explorer it's work good but in firefox else new virsion Firefox4 it's not work right so please yts have to fix it it's so many important addon

    just want to say that's Block pop-up windows it's realy need to fix not work ever i think in Microsoft explorer it's work good but in firefox else new virsion Firefox4 it's not work right so please yts have to fix it it's so many important addon

    [Quote]
    Waiting for Tidbits and Elector to grace my post with there constant negativity and start a war of words as usual... since they love stirring the pot and angering the Windows Phone Community every time they reply to posts.  I just can't believe they spend that much time here on the forums replying if they are not a paid Verizon employee or a paid basher from a competing platform.
    [/Quote]
    Well I found nothing wrong in your post. So why even make a statement like the quote I included?
    Once more I am a retired government employee. So I have the time to post. Or has my rights been taken away to voice an opinion?
    Your posts was great you were not whining about your rights to file complaints to the FCC or FTC etc. One of the best I have read.
    And I am not trying to sway you from your phone choice. If you looked at my avitar it shows apple iphones. But I use and have used androids and not Windows phones.
    However your numbers of windows phone users all leaving over the issue is miniscule in the number of users of Android and iOS devices.
    I have written many times I wish all the devices get updated like iOS devices do. But at present that is not happening
    No bashing, no adversarial post just a little common sense is all I use.
    And again your post was great.
    Good Luck

  • List of current software that is NOT supported by Lion. In other words, how many upgrades to my existing software applications are needed in order to want or are needed to upgrade to Lion

    List of current software that is NOT supported by Lion. In other words, how many upgrades to my existing software applications are needed in order to want or are needed to upgrade to Lion

    Check
    http://roaringapps.com/

  • I have 2 iphones, one for personal and one for business.  I need my phones not to sync otherwise they will both ring all the time.  How can I log out of my icloud and unsync my phones?

    I have 2 iphones, one for personal and one for business.  I need my phones not to sync otherwise they will both ring all the time.  How can I log out of my icloud and unsync my phones?

    Syncing your phones to the same iCloud account won't cause them to both ring all the time, it only puts the same contacts, calendars, and other synced data on the phone.  The phones will only ring with someone calls the number associated with the phone.
    If you want to stop using iCloud on one or both of the phones, go to Settings>iCloud, tap Delete Account, then choose Keep On My iPhone when prompted.  This will disconnect them from iCloud and keep a copy of the synced data on the phone.

  • Hi everyone, I have LR 5 that I purchased with a serial number and about a week ago I got the message about a new update, I want to get LR 6 but not the creative cloud, last time from LR4 to LR5 there was just an update without buying the creative cloud,

    Hi everyone, I have LR 5 that I purchased with a serial number and about a week ago I got the message about a new update, I want to get LR 6 but not the creative cloud, last time from LR4 to LR5 there was just an update without buying the creative cloud, is that possible from LR5 to LR6? Thanks so much.

    Welcome to Apple Discussions!
    You can't install 9.2.1 or earlier on any Mac that is only Mac OS X bootable. In fact you need to use the restore disks which came with those Macs to install 9.2.2 on those Macs. 8.6 is only possible to install on Macs which came with 8.6 or earlier. The 9.1 disk may be useful for your 1999 PowerMac G4, but won't be of any use for a 2006 Powerbook G4.
    Adobe Pagemill does not follow w3.org web publishing standards. If you want a webpage editor, get http://www.barebones.com/ BBEdit
    MS Office, there is a free Mac OS X alternative in http://www.neooffice.org/
    Or you can upgrade to the full Office 2004 for the Mac, or get http://www.thinkfree.com/ or Open OS X Office.
    Wordperfect files can be converted to Word files with http://www.dataviz.com/ 's Maclinkplus.
    Microsoft no longer has Internet Explorer for download (that quit being offered January 2006), though that is covered more in my FAQ:
    http://www.macmaps.com/browser.html
    As for other Mac OS X inquiries, I strongly recommend seeing my other FAQ:
    http://www.macmaps.com/macosxnative.html
    which should answer most of your other questions. If you have further questions, please feel free to ask me.
    Disclaimer: Reference to links I make to my Macmaps.com website are a for your information only type reference. I do not get any profit from this page, and it is open to the public.

  • I am unable to attach documents to a yahoo email from my macbook pro can anyone advice me what i need to do to address this please?

    Hi there;
    For some reason I am unable to attach documents to a yahoo email from my macbook pro. I do not experience this problem on a nomal PC and i can even open attachments on the mac. However on trying to attach a document to an email it keeps coming up wth an error stating ''invalid file selected'' each time i tr. Can anyone advice me what i need to do to address this please?
    many thanks

    Since your Mac probably came with 10.4, there is no longer a way to get 10.5 Leopard install media. IF it has the requirements, you may be able to upgrade to 10.6 Snow Leopard by buying the boxed install media at the Apple Store for $30.
    System requirements are found here: http://support.apple.com/kb/SP575
    General support can be found here: http://www.apple.com/support/snowleopard/

  • I've been using a trial of FCP x 10.1.4, went to buy and it's 10.2 - I don't want 10.2 because I'm not running the updated OS. Can't I buy 10.1.4?

    I've been using a trial of FCP x 10.1.4, went to buy it  and it's trying to sell me 10.2 - I don't want 10.2 because I'm not running the updated OS and don't want to. I have cameras that run off of OS 10.9.5. so need to keep that OS.  Is there a way I can just buy the version I used in the 30 day trial (10.1.4)?  It runs fine on my current OS.

    I'm on latest version of OS X, FCPX, LPX and FCPXML export ingests into LPX just fine.

  • HT2731 How can I change my store to US, now that I am in the US? A link in a previous thread says not accessible as the profile still shows different country..

    How can I change my store to US, now that I am in the US? A link in a previous thread says not accessible as the profile still shows different country..

    As long as you have a form of payment (credit or debit card) with a USA source, and with a billing address in the USA, then you just need to change your payment information on your account to that, change your country in the store settings, and you will then be able to shop in the USA store.
    Your AppleID will work in any country's store, as long as your payment source and billing addres are also specific to that country (and you are in that country as well, as there may be IP filters in place to stop use outside of the country).

  • Built in ftp server, I want to use it, but do not think I can

    I enabled the ftp server, I want to use it, I am not sure it is up to the task.
    With it on, users can ftp in just fine, I set the ftp settings to log ftp users into their home directory. I plan on having 1000's of ftp users, and they do not all need to get home directories.
    I created a sharing only account, and changed their home path to /Library/WebServer/Documents/them
    I also changed their shell to /sbin/nologin
    This did not work, they were not allowed to login, nothing at all in the logs either.
    So I move to a standard user, and then they can login, as long as I do not change the shell they use. I do not want them to have ssh access.
    I ended up just hand configuring the ftp server, which means I am not going to be able to use Server Admin, or it will mess up my settings. I really do not want to create system users for ftp accounts anyway. Ideally, I could create ftp users with TLS, but I do not see that as an option, and OS X does not seem to be simple to set up ssh chroot, so that is not an option either.
    Suggestions on a shared hosting machine?

    Apple's implementation of lukemftp isn't very robust for hosting needs. They have spent little effort on crafting the GUI to support multiple accounts (via WGM) pointing to the same domain space, or paths within a sandbox (say you want to craft a second account to point to a subdirectory of a site --not with Apple's exceptionally primitive GUI in this regard). Apple also hasn't spent any effort to update their website for OS components: http://www.apple.com/opensource/, so this isn't really on their radar. Many hosting companies have begged Apple to address these issues ... going back many years. The results of their attentiveness is the product you now have.
    You should take a few minutes to post your wishes, and your disappointments, via the feedback tool within the Server Admin menu.
    Then follow Alex's suggestion to consider pureftpd.

  • My daughter set up my iPad I want to use my I'd not hers I have an id I do not know her password

    My daughter set up my iPad I want to use my I'd not hers i do not have her password and she does not remember it.I have an id I do not know my p
    assword.  Frequently the App Store will select her id and I cannot update or get new apps

    You will need her password in order to chgange that.

Maybe you are looking for

  • URL Param is not working

    Hi, I am passing two variable values through URL for one template to another template. It was passing two variable values to second templates but suddenly after applying new java patch it is not passing the second variable value in the URL.  Is there

  • I want to exchange all my equipment for the newest model available.

    I've been a steady customer since Feb. 2008. I want to exchange all of my equipment for the latest model available. How do I go about that? 

  • Nokia c7-00 showing offline when inserting relance...

    hi.. am from kerala and curently using tata docomo sim in kerala circle and it works well...am studying in tamilnadu and when i insert reliance sim in tamilnadu circle,it wents offline and i cant even access the network selection menu..whenever i sel

  • When is next version of OCS due out?

    Just curious if anyone knew when the next version of OCS was due out; I read the statement of direction but it doesn't really say when any of the future versions are slated for release. I wish Oracle would provide at least a ballpark roadmap for OCS.

  • Putting Single Quote in any field

    Hi All, What is the purpose of putting ' ' (Single Quote) in any of the field? Example: Object:F_BKPF_BUK Field: ACTVT:01 BUKRS:' '  - > What does this imply?