Validate  4 JTextfield (from being empty)

hello , i'm new using java ,i've done a method that work fine , but due to my lack of knowledge of the language , the method is to big( in lines of code) , i know i could use a "for" and inside an "if" to make the validation , but i dont understand the behavior of the objects . here is the code
public void actionPerformed (ActionEvent ae ) {
Object obj = ae.getSource();
if (obj == BTGuarPre){ //BTGuarPre IS COMMAND  BUTTON
verificar (obj);
void verificar (Object obj){
if (TXT1.getText().equals("")) {
JOptionPane.showMessageDialog (this,
"Por favor Introduce Una Respuesta.",
     "Campo Vacio", JOptionPane.PLAIN_MESSAGE);
               TXT1.requestFocus();
          } else if (TXT2.getText().equals("")) {
JOptionPane.showMessageDialog (this,
               "Por favor Introduce Una Respuesta.",
               " Campo Vacio", JOptionPane.PLAIN_MESSAGE);
               TX2.requestFocus();
     } else if (TXT3.getText().equals("")) {
               JOptionPane.showMessageDialog (this,
               "Por favor Introduce Una Respuesta.",
               " Campo Vacio", JOptionPane.PLAIN_MESSAGE);
               TXT3.requestFocus();
          } else if (TXT4.getText().equals("")) {
     JOptionPane.showMessageDialog (this,
     "Por favor Introduce Una Respuesta.",
               " Campo Vacio", JOptionPane.PLAIN_MESSAGE);
               T4.requestFocus();
} else {
bla,bla
thank s !!!

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class NumericVerifier
public static void main(String args[])
JFrame frame = new JFrame("Numeric Verifier");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel1 = new JPanel(new BorderLayout());
JLabel label1 = new JLabel("Numeric-only");
JTextField textField1 = new JTextField();
panel1.add(label1, BorderLayout.WEST);
panel1.add(textField1, BorderLayout.CENTER);
JPanel panel3 = new JPanel(new BorderLayout());
JLabel label3 = new JLabel("Numeric-only");
JTextField textField3 = new JTextField();
panel3.add(label3, BorderLayout.WEST);
panel3.add(textField3, BorderLayout.CENTER);
InputVerifier verifier = new InputVerifier()
public boolean verify(JComponent comp)
boolean returnValue;
JTextField textField = (JTextField)comp;
try
Integer.parseInt(textField.getText());
returnValue = true;
} catch (NumberFormatException e)
returnValue = false;
return returnValue;
textField1.setInputVerifier(verifier);
textField3.setInputVerifier(verifier);
frame.add(panel1, BorderLayout.NORTH);
//frame.add(panel2, BorderLayout.CENTER);
frame.add(panel3, BorderLayout.SOUTH);
frame.setSize(300, 95);
frame.setVisible(true);
TRY THIS
Thanx

Similar Messages

  • Validate JTextComponent for being empty

    well, I think the method could be like this:
         public Object validaDatosReturnArray(MyTextField cod, MyTextField nom,
                   MyTextField ape, MyTextField dir, MyTextField fono,
                   MyPasswordField pass) {
              Object[] datos = { "Error en el Ingreso Datos",
                        Utilitario.getContenido(cod), Utilitario.getContenido(nom),
                        Utilitario.getContenido(ape), Utilitario.getContenido(dir),
                        Utilitario.getEntero(fono), Utilitario.getContenido(pass) };
              System.out.println("Cod : " + datos[1].toString());
              System.out.println("Nom : " + datos[2].toString());
              System.out.println("Ape : " + datos[3].toString());
              System.out.println("Dir : " + datos[4].toString());
              System.out.println("Fono: " + datos[5].toString());
              System.out.println("Pass: " + datos[6].toString());
              Empleado u = ListaEmpleados.getElemenAt(datos[1].toString());
              if (u == null) {
                   if (datos[1].toString() == null)
                        Utilitario.mensaje("Falta Codigo", datos[0].toString(), 1);
                   else if (datos[2].toString() == null)
                        Utilitario.mensaje("Falta Nombre", datos[0].toString(), 2);
                   else if (datos[3].toString() == null)
                        Utilitario.mensaje("Falta Apellido", datos[0].toString(), 3);
                   else if (datos[4].toString() == null)
                        Utilitario.mensaje("Falta Direccion", datos[0].toString(), 3);
                   else if (Integer.parseInt(datos[5].toString()) == -1)
                        Utilitario.mensaje("Falta Telefono", datos[0].toString(), 2);
                   else if (datos[6].toString() == null)
                        Utilitario.mensaje("Falta Clave", datos[0].toString(), 2);
                   return datos;
              } else
                   return null;
    and the setEmpleado method() :
    public void setEmpleado() {
              Object[] datos = (Object[]) validaDatosReturnArray(txtCodigo,
                        txtNombres, txtApellidos, txtDireccion, txtTelefono, jpsClave);
              Empleado u = ListaEmpleados.getElemenAt(datos[1].toString());
              if (datos == null) {
                   System.out.println("Aqui esta tu arreglito ktm" + datos);
              } else {
                   u = new Empleado();
                   u.setCodigo(Utilitario.formatoMay(datos[1].toString()));
                   u.setNombre(Utilitario.formatoMay(datos[2].toString()));
                   u.setApellido(Utilitario.formatoMay(datos[3].toString()));
                   u.setDireccion(Utilitario.formatoMay(datos[4].toString()));
                   u.setTelefono(Integer.parseInt(datos[5].toString()));
                   u.setClave(Utilitario.formatoMay(datos[6].toString()));
                   ListaEmpleados.add(u);
                   GUI.aviso(this, "El registro se grabo correctamente");
                   Utilitario
                             .mensaje("<html>Datos de Nuevo Empleado:"
                                       + "<br> C�digo          :"     + datos[2].toString()
                                       + "<br> Nombre          :"     + datos[3].toString()
                                       + "<br> Apellido      :"     + datos[3].toString()
                                       + "<br> Direccion      :"      + datos[4].toString()
                                       + "<br> Telefono      :"     + Integer.parseInt(datos[5].toString())
                                       + "<br> Contrase�a     :"      + datos[6].toString(),
                                       "Importante", 1);
                   listarEmpleados();
                   txtCodigo.setText(setCodigo(ListaEmpleados.ls));
         }some one can do it better or give ideas to build a method able to validate his parameters (JTextComponents) for being empty ?
    Another cue:
    Is better to return an Array of JTextFields in this method?, because i will do a getText() from each JTextComponent validated to be empty for extracting the date from each one to insert in a DinamicList (LIFO)
    *the method to insert is ready, i just want to know what do you think about this possibility from validate JTextComponents                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class NumericVerifier
    public static void main(String args[])
    JFrame frame = new JFrame("Numeric Verifier");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JPanel panel1 = new JPanel(new BorderLayout());
    JLabel label1 = new JLabel("Numeric-only");
    JTextField textField1 = new JTextField();
    panel1.add(label1, BorderLayout.WEST);
    panel1.add(textField1, BorderLayout.CENTER);
    JPanel panel3 = new JPanel(new BorderLayout());
    JLabel label3 = new JLabel("Numeric-only");
    JTextField textField3 = new JTextField();
    panel3.add(label3, BorderLayout.WEST);
    panel3.add(textField3, BorderLayout.CENTER);
    InputVerifier verifier = new InputVerifier()
    public boolean verify(JComponent comp)
    boolean returnValue;
    JTextField textField = (JTextField)comp;
    try
    Integer.parseInt(textField.getText());
    returnValue = true;
    } catch (NumberFormatException e)
    returnValue = false;
    return returnValue;
    textField1.setInputVerifier(verifier);
    textField3.setInputVerifier(verifier);
    frame.add(panel1, BorderLayout.NORTH);
    //frame.add(panel2, BorderLayout.CENTER);
    frame.add(panel3, BorderLayout.SOUTH);
    frame.setSize(300, 95);
    frame.setVisible(true);
    TRY THIS
    Thanx

  • How can I stop sound track from being divided when adding clips to other tracks in PrE12?

    The situation:
    I have a project with several minutes of video clips on the timeline (expert view) in "Video 1/Audio 1."  There is also music on the sound track (below the empty "Narration" track).
    Any time I make an edit to the Video 1 track, PRE cuts the Sound Track.  (Note that this is not the Audio 1 track, it's the sound track which is two tracks away.)  If I insert a clip, the Sound Track is cut and left with a gap.  Same if I do a FreezeFrame insert.  This is bad enough (make ten insertions, have the Sound Track chopped into ten separate pieces), but it gets worse: when I try to slide the Sound Track pieces back together, the Video 1 clips will be moved around.
    This appears to be a major bug but I'm hoping there is a simple way to deal with it.
    Here's what the Manual (p.71) has to say about it (not much).
    "When you insert a clip into the Expert view timeline, adjacent clips on all tracks shift to accommodate the new clip. By shifting all clips together, the audio and video of the existing clips remain in sync."
    * The question here is, adjacent to what?  The Sound Track is a continuous music clip of many minutes; it is alone on the Track, and there is nothing on the track above it (Narration track).  So it's not adjacent to anything, and yet it is being chopped up.
    The Manual continues:
    "Sometimes, you don’t want all clips to shift with each insertion. For example, when you add background music that superimposes the entire movie, you don’t want clips to shift."
    *They got that right, but they don't say anything about how to prevent it.
    This next makes no sense at all:
    "To shift specific clips togather, press the Alt key as you insert.  At a time, you can shift specific clips simultaneously on a maximum of two tracks.  These include the track receiving the insertion and the track containing the linked audio or video (if any). The affected tracks shift together, remaining aligned. The clips on other tracks are unaffected."
    *There is no mention of how to specify what clips would be shifted, or not.
    I'm not dealing with linked clips.  And they tell me how to shift clips (sort of) but nothing about how to stop clips from being cut up and shifted.  This all makes it very hard to create a coordinated product.
    Any suggestions or solutions will be much appreciated.

    Thanks, ATR,
    I wll try this--but I still am unclear on how to do what the Manual says is possible: select clips on another track that WILL be moved, if I so desire, so as to remain synched to the main Video track.
    UPDATE:
    In the case of inserting Freeze Frame, I just tried both Ctrl method and Alt method, and neither worked.
    1. Put Video on Vid1 track
    2. Put Music on Sound Track
    3. Ran a few seconds of Vid
    4. Stopped Vid, selected Freeze Frame
    5. Held down Ctrl key while clicking "Insert in Movie"  also tried with holding down Alt key.
    Result: a 3 second still was inserted int the Vid1 track.  A corresponding gap was created in the Sound Track.
    6. Slid the final part of the Sound Track to the left along the timeline to re-connect it to the next segment created by the above process.
    Result: the video following the final Freeze Frame was pushed to the right end of  Video1 track.
    7. Slid the Sound Track all the way to the left.
    Result: the entire Video 1 Track contents were pushed to the right and divided in pieces.
    I documented each step with screen shots which I can send if you want them and if I can figure out how to do it.
    UPDATE #2
    In the case of inserting a video clip to the Timeline, I just tried both Ctrl method and Alt method, and neither worked.
    1. Locate video in Project Assets
    2a. R click video in Project Assets (pull-down menu appears), hold down Ctrl, click Insert to Timeline.
    Result: Vid clip is inserted on Video 1 track, Sound Track is separated with a corresponding gap.
    2b.  R click video in Project Assets (pull-down menu appears), push Alt
    Result: pull-down menu disappears as soon as Alt is pushed down.
    I can stil drag the Vid clip but it's one more manual step...I love shortcuts!!

  • Photoshop CC 2014 - "Could not complete your request because something prevented the text engine from being initialised".

    This problem has just started, only with CC 2014. It doesn't happen with CC or CS6.
    When I open a particular layered file, then Duplicate it, then close the original Master file I get the "text engine" warning box when I try to enter text in the copy file.
    If I enter text in the original Master file - no problem.
    If the Master file is still open and I try to enter text in the copy file  - no problem.
    I've validated all my fonts in Font Book, deleting all the duplicates and one corrupt font. No change to problem.
    I've gone to User/Library/Application Support/Adobe/Adobe Photoshop CC2014/ and trashed the CT Font Cache folder. No change to problem.
    I've run PS Update.
    Running OS 10.9.3.
    Any suggestions?

    I'm having the same issue on my work computer. I found this info in Adobe's help section.
    Issue
    When you use the Type Tool, you receive the following error:
    "Could not complete your request because something prevented the text ending from being initialized."
    To the top 
    Solution
    Close Photoshop, clear the font cache, and restart.
    Exit Photoshop.
    In Windows Explorer, navigate to the Users/[user name]/AppData/Roaming/Adobe/Adobe Photoshop CC/CT Font Cache folder.
    Move these two files to the Recycle Bin:
    AdobeFnt_CMaps.lst
    AdobeFnt_OSFonts.lst
    Empty the Recycle Bin.
    Restart Photoshop.
    To the top 
    Additional information
    This issue can occur after you uninstall and reinstall Photoshop several times.
    Text Engine error using type tool in Photoshop CC | Windows 8

  • How can I EXCLUDE particular folders/files from being included in the Lightroom 5 catalog?

    How can I EXCLUDE particular folders/files from being included in the Lightroom 5 catalog?
    I want to be able to specify paths and/or filename patterns that should NEVER be indexed in the catalog: not that they don't show up under certain circumstances, just that they are NOT THERE (in the catalog) to begin with!!
    I also do NOT want to have to respecify these criteria when "synching" the catalog; criteria should be PERMANENT (or at least 'til they're changed in LR preferences).
    I cannot be the only person in the world with this problem--but it sure seems like it, because I've spent an inordinate amount of time doing online searches & I can't find anything that addresses this issue.
    Can anyone PLEASE HELP me?
    BTW, Adobe employees (if there are any of you out there), I'm simply trying out LR now.  If I can't get this (seemingly fundamental) thing worked out (with relatively little effort), Adobe is going to LOSE A SALE of LR, because it's useless to me without this feature.
    Thanks,
    -t

    Thanks for the info... but how to you TELL LR to EXCLUDE images in a particular directory/directory structure?  The intuitive place to indicate this would be a right-click on the folder itself (or particular images), but no such option exists..  "???"  Thanks again, -pt
    The same way that you avoid buying things in your local convenience store. You don't stick a lot of labels on certain shelves, slap a credit card down on the counter each week, and announce you are buying everything that doesn't have a label on its shelf. You just choose the things you want to buy.
    Your mention of "synching the catalog" suggests that you are expecting the LR library, to mirror the total images in the computer by default. This is not IMO a useful way to think about it. LR contains no images at all, by default: the Catalog starts out empty.
    Then you Add just those selected images that you want to import, among those already in the computer. That's a one-off process which is IMO best achieved controllably in batches - which you can keyword and otherwise organise in LR terms as you go. For new incoming images, ongoing, it is a question of Copying, Moving or Adding these in defined batches as they occur - from the relevant location only - there is no need to re-consider the import of a wider body of images. And one would not want to repeat that whole task anyway: one's prior investment in achieving the right selectivity, has a positive value.
    RP

  • What line(s) of javascript is used to disable/enable html from being written for .mucows

    The question kinda says it all but some widget developers use javascript to disable html from being written. I'm wondering how it's done

    You can have different <pageItemHTML> sections based on the value of an option. You could have one that's empty and one that's not.
    Download all the samples from the documentation page:
    MuCow Documentation
    There's a sample named 'Fox.mucow' which uses different HTML based on the value of an option.

  • How to prevent a page from being printed (with condition)?

    Dear forumers,
    How can I control a page in smartform from being printed / displayed?
    The scenario:
    There are multiple pages in the smartform. In the second page, the variable, V_TEXT will be displayed in a text element located in the secondary window (not the main window). If the variable V_TEXT is empty, the second page should NOT be printed / displayed at all.
    How may I achieve this? Please help. Thanks.

    Hi,
    You can control the Window Display in the Page by giving some condition, but there is no option to control the page display based on the condition.
    Jatender

  • Lock personnel numbers from being edited

    Hello
    I am in the middle of a system migration which is being done in phases; some personnel numbers have been moved and some remain in the legacy system.  Is there a way to lock the already migrated ones from being edited through PA30, PA40 in SAP?  The HR staff keep forgetting to use the new SAP environment so it is important to stop them from making changes in the old SAP.
    Thanks.
    PC

    Hi Patrick,
    One more suggestion..if your client is not reluctant for a small core modification then take a look at subroutine sd_word_processing_put in SAPMV45A called in module sd_word_processing_put (screen 4152)
    There is a local variable called da_display in it which you can influence based on the TDID that is in focus (just set it to 'X' if you want to lock a particular TDID).
    Normally (SAPLV70T)LV70T-TDID contains the TDID that user has clicked on. If it is empty then it means the user is navigating for the first time into header texts (in this case you can read XTHEAD index 1 and see whether it is the same TDID that you want to lock).
    So you can check whether da_display is SPACE and T180-TRTYP is V(change mode) and T180-TCODE is VA02 and then whether (SAPLV70T)LV70T-TDID is the id that you want to lock down and then set da_display to 'X'.
    Even adding fields in additional data tabs is a repair technically may be you can try the above approach (if possible)..
    Hope this helps..
    Sri

  • Cellular data (APN) being emptied even without iOS upgrade

    I regularly face an issue where I notice that my 3G doesn't work anymore.
    I then go to Settings > General > Cellular Network, and I notice that the "APN" field is empty.
    I fill it in, and a few days ago, field gets emptied again without any intervention.
    I know this can happen after an iOS upgrade, but I confirm I face the problem also without any software upgrade!
    Could you explain what can cause this and how to prevent the field from being reset all the time?
    Thanks

    This guide should solve your problem.

  • How can an iTunes Match user prevent songs from being uploaded to the iCloud?

    Has anyone who is currently using iTunes Match found a way to prevent selected songs in their music library from being uploaded to the iCloud. I have a number of audio files that are hour long mixes, but aren't quite large enough to run afoul of the 200MB size limit. I'd like to keep using iTunes Match, but would like to prevent it from trying to upload any of these larger files. Any help would be greatly appreciated. Thank you!

    Another oddity I just discovered is that if I turn on wifi hotspot on my phone and connect my iMac to my phone's 3G service then iTunes on my iMac will stream music just fine from iTunes match (yes, the music was only in the cloud, not on my drive).
    I've tried everything I can think of to get iTunes Match to play tracks over cellular.. including totally deauthorizing all my computers and devices, totally removing all tracks my itunes match in the cloud and re-scanning/uploading everything. Purchased new tracks, and they won't play unless they are downloaded. But they will play just fine when previeing them for purchase in iTunes app.

  • Restoring a SQL Server 2005 DB to a SQL Server 2014 install, is there any way to prevent it from being upgraded

    Does anyone know if there is a flag I can use to prevent a SQL Server 2005 database from being upgraded to SQL 2014 when it is restored to a 2014 instance?
    Don't ask why, I just need to know if this is possible or if 2005/8 DB's are required to be upgraded if they are going to run on SQL 2012/2014 instances. The documentation seems to say this is so, I just want to verify that.

    First: You cannot directly restore a 2005 database to
    2014. MS supports migration over 3 SQL Server version steps; means you can restore 2005 to 2008/2008R2/2012, but not to 2014. You have to do a migration step between.
    Olaf I was looking for this today, because I'm working with a new customer that have SQL 2005 and I have SQL 2014. And needed to restore a backup form the production server in my test server.
    When I read what you write I think, oh no!! I have to install SQL 2012 in my server. But that it's not an option for me, and I say let me try to restore the DB first in 2014 and if not work install 2012.
    You can restore a 2005 database to 2014 directly, and it works.
    For reference the version number in the servers 2005 (9.0.4035 SP3) and 2014 (12.0.2000 RTM)
    This is not related in any way to the original question that you answered (the file format will be upgraded to the new motor, that is sure).
    I put this lines because in the future there will be some people searching about if possible to restore a 2005 DB to 2014, and like me will read your lines and think it's not possible and that can make a decision to buy 2012 and not 2014 to that new server they
    will migrate.
    Don't forget to mark the best replies as answers!

  • How can I prevent a PDF file from being copied, printed or downloaded? Students should only be able to view the text and and not distribute it in any way.

    How can I prevent a PDF file from being copied, printed or downloaded? Students should only be able to view the text and and not distribute it in any way.

    You can prevent it from being printed by applying a security policy to it
    in Acrobat. The rest can't be prevented, unless you spend  a LOT of money
    on DRM protection.

  • Search has encountered a problem that prevents results from being returned. If the issue persists, please contact your administrator.

    Hello Guys,
    I am creating resultsource from central admin. If I create it from central admin it works fine. But if I am creating result source from power shell scripts it shows me following error message.
    An exception of type 'Microsoft.Office.Server.Search.Query.InternalQueryErrorException' occurred in Microsoft.Office.Server.Search.dll but was not handled in user code
    Additional information: Search has encountered a problem that prevents results from being returned.  If the issue persists, please contact your administrator.
    Any suggestion ?
    Thanks in Advance.

    Hi,
    Please provide more specific information about the issue. What type of content source you tried creating via powershell?
    Make sure you are using the approproate permission and search service application.
    Here is the reference for creating content resource via script:
    http://technet.microsoft.com/en-us/library/ff607867(v=office.15).aspx
    Regards,
    Rebecca Tu
    TechNet Community Support

  • How to prevent an encrypted backup from being restored to a different device?

    If I force an employee to do an encrypted backup (which I can do with a configuration profile), and that employee is fired. We take back the company iphone, but they go and buy a personal one. They connect the new, personal iphone to itunes and do a restore of the encrypted backup (they know the password) and now they have all the work related stuff on their personal phones. Is there a way to prevent an encrypted back from being restored to a different device id.

    We require encryption of our employee backups as well...and the problem you mention is a real one.....
     If you use Exchange, you could disable Exchange Active Sync to prevent them from subsequently connecting to Exchange Server and getting new data with the new personal device....but you would still have the old data as part of the backup...the other issue is that we've found that the profile is part of the backup and if an employee leaves, even on good terms, if he wants to restore say, his music from the backup without the profile, it becomes quite awkward...the profile would have to be removed, ( which removes everything added with the profile, possible email and wi-fi), then the user could backup music etc  with iTunes, then return the corporate phone to be salvaged or re-deployed...and later put his personal data back on another device without the profile...if there is a way around the issue you bring up I'd like to know of it as well. .  Perhaps there is an MDM with functionality that would help here....that is one great strength of the Blackberry platform..all corporate data can be controlled from the BES server. 

  • How do I prevent files from being backed up to iCloud and iTunes?

    I have created the ios app using adobe AIR16 and flash cc. After submission of my aap into aapstore, I received a message from Apple with the following message –
    From Apple
    2.23 - Apps must follow the iOS Data Storage Guidelines or they will be rejected.
    By using xcode we can prevent files from being backed up to icloud and itunes, but i want to know that  what is the way to achieve this by using AIR. While creating an explicit app id from apple developer account , i am not enabling icloud support.

    Within AIR you can set the File.preventBackup property to true on a directory or file to prohibit that content from being backed up to the cloud:
    File - Adobe ActionScript® 3 (AS3 ) API Reference
    This is all you need to call when you first create the folder or file to have it work with iOS backup guidelines.

Maybe you are looking for