FocusLost() is not acting the way I thought it should

Hi
I hope someone will be be able to help me with this applet. I have three input fields and when someone moves from one to the next without making an entry (and lost focus for that field), I want to 'keep' him there until he has entered the information.
When I tab or click to another field leaving an 'empty' field, nothing happens(none of my code in the focusLost() method executes).
I am posting the entire code.
Thanks for any help anybody can offer :)
Chris
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.text.DecimalFormat;
public class Wages extends JApplet
                              implements ActionListener {
     private double rate,
                              hours;
     private String name;
     private JLabel nameLabel,
                              hoursLabel,
                              rateLabel;
     private JTextField nameField,
                                   hoursField,
                                   rateField,
                                   display;
     private JButton resultsButton;
     public void init() {
          Container c = getContentPane();
          c.setLayout( new FlowLayout() );
          nameLabel = new JLabel( "Enter Name" );
          nameField = new JTextField( 25 );
          nameField.addFocusListener(
               new FocusAdapter() {
                    public void focusLost(FocusEvent e) {
                         if (nameField.getText() == "") {
                              JOptionPane.showMessageDialog( null,
                                   "Enter a name in the name field",
                                   "Warning", JOptionPane.ERROR_MESSAGE );
                              nameField.requestFocus();
                         name = nameField.getText();
          c.add( nameLabel );
          c.add( nameField );
          hoursLabel = new JLabel( "Enter hours" );
          hoursField = new JTextField( 10 );
          hoursField.addFocusListener(
               new FocusAdapter() {
                    public void focusLost(FocusEvent e) {
                         if (hoursField.getText() == "") {
                              JOptionPane.showMessageDialog( null,
                                   "Enter the hours in the field",
                                   "Warning", JOptionPane.ERROR_MESSAGE );
                              hoursField.requestFocus();
                         hours = Double.parseDouble( hoursField.getText() );
          c.add( hoursLabel );
          c.add( hoursField );
          rateLabel = new JLabel( "Enter pay rate" );
          rateField = new JTextField( 10 );
          rateField.addFocusListener(
               new FocusAdapter() {
                    public void focusLost(FocusEvent e) {
                         if (rateField.getText() == "") {
                              JOptionPane.showMessageDialog( null,
                                   "Enter the rate in the field",
                                   "Warning", JOptionPane.ERROR_MESSAGE );
                              rateField.requestFocus();
                         rate = Double.parseDouble( rateField.getText() );
          c.add( rateLabel );
          c.add( rateField );
          display = new JTextField( 35 );
          display.setEditable( false );
          c.add( display );
          resultsButton = new JButton( "Calculate" );
          resultsButton.addActionListener( this );
          c.add( resultsButton );
     public void actionPerformed( ActionEvent e ) {
          print();
          nameField.requestFocus();
     private void print() {
          DecimalFormat precisionTwo = new DecimalFormat( "0.00" );
          display.setText(
               name + " GROSS Pay " +
               precisionTwo.format( hours * rate ) +
               " NET Pay " +
               precisionTwo.format( getNet() )
          nameField.setText( "" );
          hoursField.setText( "" );
          rateField.setText( "" );
     private double getNet() {
          if (rate <= 10)
               return hours * rate;
          else if (rate <= 20)
               return hours * rate * 0.8;
          else if (rate <= 30)
               return hours * rate * 0.7;
          else
               return hours * rate * 0.6;
}

Your error has nothing to do with focusLost. Here is the problem:
public void focusLost(FocusEvent e) {
if (nameField.getText() == "") { <---- Here
You can't compare strings that way. What you're saying is "does the namefield string the same pointer as the empty string?" even if the nameField is empty, it will have a different pointer. You want nameField.getText().equals("")

Similar Messages

  • Range partitioning does not work the way I thought it would

    I have a table that is range partitioned by number.
    The number represents a date field of the form: YYYYMMDDHH24
    However, there are extra values on the end of the field that represent an exact datestamp so a record looks like
    20071102100000001
    What I found in my tests is that if I have a partition based on range based on the following:
    values less than (2007110210)
    Any records inserted with a length greater than what is above automatically go to the future partition. It does not make sense that I would have to add another column and then do a substr on this field for just the first 10 characters to get them to go to the correct partition.
    ???? I am at a bit of a loss.

    Hi
    If you a column storing a timestamp you should use the timestamp or date datatype, not something else!!! Not only it makes not sense but you will have a lot of problems with that. To name only two: not consistent data and misleading the query optimizer.
    As you defined, since 20071102100000001 is greater than 2007110210 (i.e. not less then), I don't see why do you expect something else.
    HTH
    Chris

  • HT1430 mail is not behaving the way it should after updating to ios 6.1.2

    after updating to ios6.1.2 on Saturday March 9, 2013 the mail is not operating the way it should. What can i do to try and fix it?

    Nobody here would know since you didn't explain in detail why it's not operating the way it should.

  • My phone is not working the way it did before the manditory iOS 7 update.

    My phone is not working the way it did before the manditory iOS 7 update.  It freezes, it lags, I get kicked out of my apps, my messages do not send half of the time, I can't view the pictures in my camera roll if I enlarge them, and the phone glitches randomly.  How can this be fixed or what do I need to do to get it replaced??

    The Basic Troubleshooting Steps are:
    Restart... Reset... Restore from Backup...  Restore as New...
    Restart / Reset   >  http://support.apple.com/kb/ht1430
    Restoring  >  http://support.apple.com/kb/HT1414
    If you try all these steps and you still have issues... Then a Visit to an Apple Store or AASP (Authorized Apple Service Provider) is the Next Step...
    Be sure to make an appointment first...

  • My MacBook Pro turns on but not all the way, it gives me an icon of a grey folder with a question mark in the middle, and won't go further that that. Anyone knows why, or what's the problem?

    My MacBook Pro turns on but not all the way, it gives me an icon of a grey folder with a question mark in the middle, and won't go further that that. Anyone knows why, or what's the problem?

    If these do not resolve the issue or if you are not comfortable with proceeding through these steps then take your Mac to an Apple store or an Apple Authorized Service Provider.  An Apple store will perform these initial steps, diagnose the problem, and give an estimate for repairs (if needed).  If the Mac is less than one year old or is covered by AppleCare any repairs would be free.
              Genius reservation http://www.apple.com/retail/geniusbar/ .
              or find an Apple Authorized Service Provider https://locate.apple.com/country

  • HT5557 I have bookmarks and notes that are no longer attached to the original page and I can't find a way to delete them.  Could someone help me purge these things so they are not in the way?

    I have bookmarks and notes that are no longer attached to the original page and I can't find a way to delete them.  Could someone help me purge these things so they are not in the way?

    James Ward4  Thanks for your suggestion.  I have tried the video app and it appears to have some, but not all of the downloads which are viewable without wifi, so I will now review the download process and see if I can capture the missing episodes.  Thanks again.

  • Need some help killing threads (not in the way already mentioned..)

    I have read the ways in which we should safely kill a thread - and for the most part i understand that. But my question is HOW to implement it in the way that I need.
    Basically I have a multithreaded (ewww) app that really is a large job scheduler running 24/7. It can run anywhere from 1 to 15 jobs at a given time. This is fine. What i need is to have the ability to 'kill' a job when I need to. When the app daemon decides its time to run a certain job (based on business logic) it kicks one off, which is a class I made that implements Runnable.
    public class SchedulerProcessThread extends SOQBase implements Runnable{}
    when its time to start a job i do the usual:
    SchedulerProcessThread spt = new SchedulerProcessThread(blah);
    Thread t = new Thread(spt, "fooname");
    t.start();
    Now, this comes to my problem of where/how to kill the job (if needed). A SchedulerProcessThread is linear and finite so it will always have a termination point - it never loops. And when one is kicked off - i do not have a reference to it anymore - I mean, I couldnt if i am constantly running new jobs, potentially hundreds every hour. And jobs can be started in various places in the app, depending upon whether others are already running, etc.
    I wish to implement the do-while (alive) logic on the job thread. So in the 'run()' method of my SPT class, I would like the:
    while (alive) {
    doProcessing();
    But how can i invoke a method on my class [SPT] so that it changes the alive var from true to false when i do not have a reference to it?
    As a side note, I have a command prompt on the app whereby i can call up all the running 'jobs' which is a list of the running threads under a threadgroup called 'soqjob' (all new Threads that are started with a passing param of and SPT object are under the 'soqjob' threadgroup). So now i can see all those 'soqjob' threads which are currently running Thread objects that have been passed new instances of an SPT class.
    Is there anyway i can grab the 'soqjob' thread of my choice and somehow access my SPT class that was originally passed to it in the Thread constructor? if so, then I could pass in the command to stop the do-while loop.
    Hmm - does any of this make sense? If i can sum up, the problem is i do not know how to access my own SPT class once I have passed it into a thread object and invoked that thread object's 'start()' method. if i can do that, then i can switch the ALIVE var from true to false and thereby kill the SPT job i need.
    Any ideas?
    Many thanks
    Ian

    I would add a Collection (synchronized) to the Scheduler that holds a reference to all the Processes. Pass a reference of the Scheduler to the Processes so that when a Process is done, it can remove itself from the Collection.
    public class Scheduler {
         private Collection threads;
         public void addProcess() {
              Runnable runnable = new ProcessThread(this);
              Thread thread = new Thread(runnable);
              thread.start();
              threads.add(thread);
         public void removeProcess(ProcessThread thread) {
              threads.remove(thread);
         private Thread getSelectedThread(Component c) {
              //Find Thread in Collection and return it
         private class Action implements ActionListener {
              public void actionPerformed(ActionEvent e) {
                   Thread thread = getSelectedThread(e.getSource());
                   thread.interrupt();
    class ProcessThread extends ... implements Runnable {
         private Scheduler scheduler;
         public ProcessThread(Scheduler s) {
              this.scheduler = s;
         public void run() {
              while (!Thread.interrupted()) {
                   try {
                        doProcessing();
                        Thread.yield();     //Give the other Threads a chance to do some work
                   } catch (InterruptedException e) {
                        Thread.currentThread().interrupt();
              this.scheduler.removeProcess(this);     //Remove this Thread from the Scheduler's Collection
    }Did you consider using the classes java.util.Timer and java.util.TimerTask?

  • I need to cancel my membership I got today it did not work the way I wanted to and my computer is not working with it. Thank please cancel to today!!

    I need to cancel my membership I got today, it did not work the way I wanted to. So please cancel it today! Thanks

    This is a user forum; we have no access to your subscriptions, but we can help you to get it canceled.  So what did you subscribe to:
    Creative Cloud?
    an Acrobat.com online service?

  • Bought a new monitor.. wide screen 23"... Firefox is not filling the full window. IE works fine but I prefer Firefox. What do I need to do to fill entire window, not just the way it was with the old monitor?

    Bought a new monitor.. wide screen 23"... Firefox is not filling the full window. IE works fine but I prefer Firefox. What do I need to do to fill entire window, not just the way it was with the old monitor? edit

    Most pages are defined to be a certain size, regardless of how large or small your monitor is. You can use Firefox's zoom feature (View menu) to enlarge the text and images (or just the text, if you prefer) on a page.
    In addition to making individual site adjustments, there are some add-ons that will default every site to a higher zoom level. For example, check out:
    * [https://addons.mozilla.org/en-US/firefox/addon/6965/ Default FullZoom Level]
    * [https://addons.mozilla.org/en-US/firefox/addon/2592/ NoSquint]
    Does that help?

  • Ever since I downloaded the new iOS 7 my screen will not turn up and down and it rotates on its own side to side.it will not face the way I want it to go. How do I fix it?

    Ever since I downloaded the new iOS 7 my screen will not turn up and down and it rotates on its own side to side.it will not face the way I want it to go. How do I fix it?

    I've been working on this all day!!! I've tried everything I know of and can't get it to load either. Sounds like lots of people are having problems. Here is what I have so far...I have uninstalled EVERYTHING on my pc from apple and reinstalled itunes to no avail. I have tried all sorts of things I've read as fixes online. NOTHING has worked. Here is something interesting that i have noticed though. my main pc (which is the one i have always managed my itunes account with for years) is a 32 bit system running windows 7. Yesterday I installed itunes for the first time on my new netbook which is a 64 bit (windows 7) system and it works just fine. i have three other laptops (all window 7) in my household that are all 64 bit operating systems and ALL have updated to 10.5 and THEY ALL work fine. this is FOUR 64 bit systems ALL updated w/10.5 that work and ONE that is a 32 bit that will not. Can't get any help from apple. their suppot *****! I want to get someone on the **** phone or a live chat but cant. *** APPLE????? please let mw know if you find SOMETHING i can try next. I'm out of ideas and patience!

  • Hi, i would like my membership cancelled. I got it yesterday but its not working the way i wanted it to work. How do i go about that i getting my refund as its before 30 days.

    Hi, i would like my membership cancelled. I got it yesterday but its not working the way i wanted it to work. How do i go about that i getting my refund as its before 30 days.

    Hi kondwastefstef,
    I'm sorry that your subscription didn't meet your needs. Please contact Adobe Customer Support via phone or chat; they should be able to cancel your account and process your refund. Here's the contact information: Contact Customer Care
    Best,
    Sara

  • Skype Feedback: Do not change the way Skype is lai...

    DO NOT change the way skype is laid out. i like friends list on the lft and chat window on the right. DO NIOT CHANGE THAT OR SUFFR THE CONSEQUENCES >:L
    This post was transferred from its previous location to create its own new topic here; its subject and/or title has been edited to differentiate the post from other inquiries and to reflect the post's content. A link to this post appears where the post was originally added.

    I also have this problem... For all of the people above who are getting snotty - you're being rather single-minded about your particular use of the iPhone. I live in an African country where it's typical to wait 10 minutes for a medium sized PDF file to upload. I purchased an iPhone 4S in large part due to Facetime being the most stable option for video calls with my parents. Here, I **cannot** update my iOS, the available internet simply does not allow for it. My parents, who live in Canada, but in a remote area where they rely on cellular data, also purchased iPhones in order to use Facetime. But Apple does not allow updating the iOS over data!
    The Windows example above is a perfect demonstration of just why this is unacceptable -- internet explorer does not simply cease to function one day (without warning), forcing me to update to a different version of Windows or use an alternative. If I start out having it, I will continue to have it.
    It is unacceptable to market a product for its features, then require the buyer to take additional steps in order to restore said feature. If I am required to update in order to get cool *new* features, that is totally fair. But it is not unreasonable to expect that a relatively new product should continue working as advertised, and as it has been!
    If anyone learns of any other possible solutions, I will be delighted to hear them.

  • I am told to verify my identity by answering security questions that I do not know the answer to. What should ai do?

    I am told to verify my identity by answering security questions that I do not know the answer to. What should I do?

    You need to contact Apple to get the questions reset, which can be done by clicking here and picking a method for your country, or if that's not an option, by filling out and submitting this form.
    (95947)

  • HT4009 I purchased an upgrade inside the free app, however it shows I paid for the free app & now I can not download the full version.  What should I do?

    I purchased an upgrade inside the free app, however it shows I paid for the free app & now I can not download the full version.  What should I do?
    Thanks!
    Kristine

    Finish the download on your computer in iTunes and then sync the app to the iPad and then delete it. You will probably have to let it fully download before you can delete it.
    You can try restarting the iPad and see if the download will resume - Restart the iPad by holding down on the sleep button until the red slider appears and then slide to shut off. To power up hold the sleep button until the Apple logo appears and let go of the button.
    Yoy can try  this as well and see if the download will resume. Reset the iPad by holding down on the sleep and home buttons at the same time for about 10-15 seconds until the Apple Logo appears - ignore the red slider - let go of the buttons.
    Look in iTunes and see if there is a pending download in there that might be causing the delay. If there is a download there, try to finish that one first.

  • Hello buy a movie on apple tv, and now can not find the device tells me I should go to settings / downloads / check downloads, but that does not exist in the menu of the apple tv, please help

    Hello buy a movie on apple tv, and now can not find the device tells me I should go to settings / downloads / check downloads, but that does not exist in the menu of the apple tv, please help

    Welcome to the Apple community.
    A number of people have reported similar issues recently, many appear to have found a discrepancy of some kind in their account settings and making changes to these settings or simply resetting them has resolved the matter.
    Check your account details are correct, check that you are using the correct details for Location, Region and Time Zone. You may want to change these settings and then change them back to see if that helps.
    You might also try logging out of and then back into your iTunes account (Settings > iTunes Store > Apple ID’s > Sign Out) and restarting your router. (Some have reported that after doing this, they need to check for rentals even though it may report that there aren’t any, after which rentals once again appear in the ‘movies’ feature)
    Rentals should appear under their own heading in the ‘Movies’ feature, you might also check at Settings > iTunes Store > Check For Rentals.

Maybe you are looking for

  • Reference of internal order in PO creation

    Hi Friends, Is there any way to control system not to allow to create purchase orders with reference to Internal orders if they are not released and not approved. Present it is stopping at GR level if order is not released but we want to control this

  • Flash image viewer works in preview but not online

    Hi I followed an online demo on how to get an image slideshow on my webpage using flash. It was using insert media image viewer. It all worked fine, looked great in the preview but when I put everything online I can't see it. Just an empty space were

  • H.264 on SAFARI(iPhone/iPad)

    Hello guys. I am a university student and I am doing a project regard of getting live stream from IP camera via vlc player and send it to a particular browser (iphone/ipad) using HTML5 video player (Projekktor and VideoJS). Basically I receive RTSP l

  • How do I press, add, NOT RELEASE and drag?

    When I press the mouse-button in my panel, my program will add a component under the mousepointer. I would like to start dragging this component, without first releasing the button and then grabbing the component by pressing a second time. Can it be

  • Problem on after command javac

    Dear Sir/Madam. Can anyone help to solve the following problems ? I'm Java Beginner and I'll try to write this program using InputBox and Output Box. Thanks a lot !! /* celsius Programming with java by Wong A program to input temperature in Celsius a