This week's book giveaway is in the Programmer Certification forum.
We're giving away four copies of OCP Oracle Certified Professional Java SE 21 Developer Study Guide: Exam 1Z0-830 and have Jeanne Boyarsky & Scott Selikoff on-line!
See this thread for details.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Having problem with these program

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have to create a program that enter some information including a zip code, but the user is not allowed to type ( 00000 ) . If the user does input those five digits a invalid input should be displayed.
This is what i have for that part:

private JTextField getzipCodeEntry() {
zipCodeEntry = new JTextField();
zipCodeEntry.setPreferredSize(new Dimension(200, 20));
zipCodeEntry.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
zipCodeAsEntered = zipCodeEntry.getText().trim();
// This deletes leading and trailing blanks in entry field, too
zipCodeEntry.setText(zipCodeAsEntered);
System.out.println(zipCodeAsEntered);
if (!zipCodeAsEntered.matches("\\d{5}"))
System.out.println("ZIP must be five digits");

if (zipCodeAsEntered.length() == 0)
System.out.println("Zip Code is required");


}

}); // end private JLabel getzipCodeLabel()
return zipCodeEntry;
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to JavaRanch.

Ok, so you know what the problem to solve is and you have some code. Now, what is your question?
 
lowercase baba
Posts: 13091
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
so what exactly is your question?
 
Jorge Correa
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sorry if i did not myself clear. I want some help in how to display a invalid input message if the user enters 00000 in the zip code field.
 
Marshal
Posts: 79979
397
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
. . . if("00000".equals(zipCodeAsEntered)) . . . ?
 
Sheriff
Posts: 28333
97
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Or are you asking how to display a message?
 
Think of how dumb the average person is. Mathematically, half of them are EVEN DUMBER. Smart tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic