Results 1 to 5 of 5
  1. #1
    heatblazer is offline Senior Member
    Join Date
    Nov 2012
    Posts
    137
    Rep Power
    0

    Default Choppy code susspected - please advice

    Hello, in the accounting program I am working on, I`ve came with that decision:

    Java Code:
    Tasker.getThreads().get("addingThread").init(new Runnable() {
    	@Override										
            public void run() {	
               Thread.currentThread().setName("addingThread");	
    													
               while ( Tasker.getThreads().get("addingThread").isRunning() ) 
    	      {
    														/*keep looping untul both fields are 
    															filled */
    		if (!sname1.getText().equals("") &&
    				!fname1.getText().equals("") ) {
    		addButton1.setEnabled(true);
    		}
    		   else addButton1.setEnabled(false);
    		}
    	}
    }); // end check button
    Apparently the idea is checking 2 input text boxes - if filled - enable a button if you enter text and then delete it they disable the button again. But I am not sure this is a smart solution. Thread is unset elsewhere in the code - it`s not problem. Just is it a good approach. There is a screenshot, below, showing the rough concept.
    (Don`t go all out on me - I am learing Java for 3-4 months, not expert yet )
    Attached Thumbnails Attached Thumbnails Choppy code susspected - please advice-mframe.png  

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,569
    Rep Power
    12

    Default Re: Choppy code susspected - please advice

    Better, maybe, to add a document listener to the two text fields (and, if appropriate add a selection listener to the list) and every time the text content changes update the state of the button.

  3. #3
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,569
    Rep Power
    12

    Default Re: Choppy code susspected - please advice

    I'll move this to the Swing forum.

  4. #4
    heatblazer is offline Senior Member
    Join Date
    Nov 2012
    Posts
    137
    Rep Power
    0

    Default Re: Choppy code susspected - please advice

    Quote Originally Posted by pbrockway2 View Post
    Better, maybe, to add a document listener to the two text fields (and, if appropriate add a selection listener to the list) and every time the text content changes update the state of the button.
    Thanks, but this is a prototype, and I intend to perform other tasks inside the run() besides checking if the fields are filled, things like if it`s valid human name, valid year format ( later ), valid ID ( later ) etc., so your suggestion is good but does not fill my requirements 100%.

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,172
    Rep Power
    20

    Default Re: Choppy code susspected - please advice

    You can do all that in a DocumentListener.
    Indeed it might be preferable as each listener will deal with a single field, isolating the validation logic.
    Set a 'validXXX' flag for each field and only activate the button when all fields are valid.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. advice
    By icedust in forum Advanced Java
    Replies: 1
    Last Post: 10-11-2011, 12:50 AM
  2. need for some advice
    By kasiopi in forum AWT / Swing
    Replies: 3
    Last Post: 01-26-2011, 01:36 PM
  3. Choppy motion / graphics
    By Atriamax in forum Java Applets
    Replies: 5
    Last Post: 09-17-2009, 07:06 AM
  4. Replies: 14
    Last Post: 09-18-2008, 05:41 AM
  5. I need some advice and tips about my code...
    By sukatoa in forum Advanced Java
    Replies: 3
    Last Post: 06-23-2008, 08:29 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •