WEll I'm kinda new to Java programming...but we got a major project coming up and I got stuck on one of the examples. This is for a validation code, to validate correct inputs....the errors are highlighted in red...Thanks to anyone that bothered to help :P I'm sure the answer is really basic but i tried flipping stuff around and it doesn't work :evil: supposedly i'm missing an ")" but no friggin idea where. -__-ll

// Airlines Reservation program
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Airlines extends JFrame {
private JTextField phoneTextField, firstTextField, lastTextField, dateTextField, addressTextField;

/** Creates a new instance of Airlines */
public Airlines() {
super ( "Airlines");
JLabel phoneLabel = new JLabel( "Phone" );
JLabel firstLabel = new JLabel( "First Name" );
JLabel lastLabel = new JLabel( "Last Name" );
JLabel dateLabel = new JLabel( "Date" );
JLabel addressLabel = new JLabel( "Address" );
JButton okButton = new JButton( "OK" );
okButton.addActionListener( new ActionListener(){
public void actionPerformed( ActionEvent event ){
validateDate();
}
}
);
phoneTextField = new JTextField( 15 );
firstTextField = new JTextField( 5 );
lastTextField = new JTextField( 2 );
addressTextField = new JTextField( 12 );
dateTextField = new JTextField( 20 );
JPanel firstName = new JPanel();
firstName.add( firstLabel );
firstName.add( firstTextField );
JPanel lastName = new JPanel();
lastName.add( lastLabel );
lastName.add( lastTextField );
JPanel address = new JPanel();
address.add( addressLabel );
address.add( addressTextField );
JPanel date = new JPanel();
date.add( dateLabel );
date.add( dateTextField );
JPanel phone = new JPanel();
phone.add( phoneLabel );
phone.add( phoneTextField );
JPanel ok = new JPanel();
ok.add( okButton );
Container container = getContentPane();
container.setLayout( new GridLayout( 6, 1 ) );
container.add( firstName );
container.add( lastName );
container.add( address );
container.add( date );
container.add( phone );
container.add( ok );
setSize( 400, 400 );
setVisible( true );
}
public static void main( String args[]){
Airlines application = new Airlines();
application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
}

private void validateDate()
{
if ( lastTextField.getText().equals( "" ) ||
firstTextField.getText().equals( "" ) ||
addressTextField.getText().equals( "" ) ||
dateTextField.getText().equals( "" ) ||
phoneTextField.getText().equals( "" ) || // end condition
)
JOptionPane.showMessageDialog(this, "Fill in all fields please");
else if(!lastTextField.getText().matches( "[A-Z][a-zA-Z]*"))
JOptionPane.showMessageDialog( this, "Invalid last name" );
else if(!firstTextField.getText().matches( "[A-Z][a-zA-Z]*"))
JOptionPane.showMessageDialog( this, "Invalid first name" );
else JOptionPane.showMessageDialog( this, "Thanks Bub" );
}
}

Recommended Answers

All 3 Replies

private void validateDate()
{
if ( lastTextField.getText().equals( "" ) ||
firstTextField.getText().equals( "" ) ||
addressTextField.getText().equals( "" ) ||
dateTextField.getText().equals( "" ) ||
phoneTextField.getText().equals( "" ) || // end condition
)

remove the || before the comments marks, or replace it with the following:

private void validateDate()
{
if ( lastTextField.getText().equals( "" ) ||
firstTextField.getText().equals( "" ) ||
addressTextField.getText().equals( "" ) ||
dateTextField.getText().equals( "" ) ||
phoneTextField.getText().equals( "" ) // end condition
)

Not to up on Java but below the Private void validate date, if "("... where does this end ")"
Hope if helps

paradox nailed it

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.