jeudi 21 décembre 2017

Partial searching with an IF statement, syntax problems

please bear with me as I'm rather new to programming.

I've created a simple application and I'm able to search a user via his name. I now want to be able to search via his number. I feel like I'm almost there but I've got the syntax wrong here, could anybody tell me how to resolve this? Wasted way too much time trying to resolve this! Eclipse is just giving me an error and say '( expected', and won't let me run the program.

So yeah basically I'm just looking for some advice on where I'm going wrong as I'm sure it's only a syntax error.

thanks in advance

here is my code:

 JButton searchForAUserBtn = new JButton( "search for a user" );
    searchForAUserBtn.addActionListener( new ActionListener()
    {   public void actionPerformed( ActionEvent e )
        {   
                        if{Student con = user.SearchViaName( 
 nmField.getText());
                        if (con != null)
                            nmField.setText(contact.getNum());
                       try{     emField.setText(contact.getEm()); }
                       catch(Exception f){
                          outputArea.setText(" user not found.");}}

                        else{Student con = user.searchViaNumber( 
 numField.getText());
                        if (con != null)
                            nmField.setText(contact.getNm());
                       try{     emField.setText(contact.getEm()); }
                       catch(Exception e){
                          outputArea.setText(" user not found.");}

                        }

        }
    });
    add( searchForAUserBtn );

Aucun commentaire:

Enregistrer un commentaire