Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Applets
Search Coderanch
Advance search
Google search
Register / Login
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:
Tim Cooke
Campbell Ritchie
Ron McLeod
Junilu Lacar
Liutauras Vilda
Sheriffs:
Paul Clapham
Jeanne Boyarsky
Henry Wong
Saloon Keepers:
Tim Moores
Tim Holloway
Stephan van Hulst
Piet Souris
Carey Brown
Bartenders:
Jesse Duncan
Frits Walraven
Mikalai Zaikin
Forum:
Applets
Form validation error
Yohan Weerasinghe
Ranch Hand
Posts: 507
I like...
posted 11 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi all,
Please have a look at the following code
import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.applet.*; public class STestFile1 extends JApplet implements ActionListener{ JPanel card1,card2, cards; JLabel hApply, hPersonal,hHeading; JTextField tPhoneNumber, tPhoneNumberOffice, tMonth; JButton button1; CardLayout ourLayout; GridBagLayout gbl1,gbl2; GridBagConstraints gbc1,gbc2; int iPhone1,iPhone2,iMonth; boolean i = true; public void init() { ourLayout = new CardLayout(); hApply = new JLabel("Applying For"); hPersonal = new JLabel("Personal Details"); hHeading = new JLabel("Application Form"); tPhoneNumber = new JTextField(10); tMonth = new JTextField(10); tPhoneNumberOffice = new JTextField(10); button1 = new JButton("NEXT"); button1.addActionListener(this); gbl1 = new GridBagLayout(); gbc1 = new GridBagConstraints(); gbl2 = new GridBagLayout(); gbc2 = new GridBagConstraints(); JPanel mCard1 = new JPanel(); mCard1.setLayout(gbl1); JPanel mCard2 = new JPanel(); mCard2.setLayout(gbl2); gbc1.anchor = GridBagConstraints.WEST; gbc2.anchor = GridBagConstraints.WEST; /*Adding mCard1 stuffs*/ gbc1.gridx = 1; gbc1.gridy = 1; gbc1.gridwidth= 1; gbc1.gridheight = 1; gbl1.setConstraints(hApply,gbc1); mCard1.add(hApply); gbc1.gridx = 1; gbc1.gridy = 2; gbc1.gridwidth= 1; gbc1.gridheight = 1; gbl1.setConstraints(hPersonal,gbc1); mCard1.add(hPersonal); gbc1.gridx = 1; gbc1.gridy = 3; gbc1.gridwidth= 1; gbc1.gridheight = 1; gbl1.setConstraints(hHeading,gbc1); mCard1.add(hHeading); /*Adding mCard2 Stuffs*/ gbc2.gridx = 1; gbc2.gridy = 1; gbc2.gridwidth= 1; gbc2.gridheight = 1; gbl2.setConstraints(tPhoneNumber,gbc2); mCard2.add(tPhoneNumber); gbc2.gridx = 1; gbc2.gridy = 2; gbc2.gridwidth= 1; gbc2.gridheight = 1; gbl2.setConstraints(tMonth,gbc2); mCard2.add(tMonth); gbc2.gridx = 1; gbc2.gridy = 3; gbc2.gridwidth= 1; gbc2.gridheight = 1; gbl2.setConstraints(tPhoneNumberOffice,gbc2); mCard2.add(tPhoneNumberOffice); gbc2.gridx = 1; gbc2.gridy = 4; gbc2.gridwidth= 1; gbc2.gridheight = 1; gbl2.setConstraints(button1,gbc2); mCard2.add(button1); /*Adding panels to cards*/ card1 = new JPanel(); card1.add(mCard2); card2 = new JPanel(); card2.add(mCard1); /*Setting up the main card*/ cards = new JPanel(); cards.setLayout(ourLayout); cards.add(card1,"two"); cards.add(card2,"one"); /*Setting up the main window*/ JPanel panel1 = (JPanel)getContentPane(); panel1.setLayout(new BorderLayout()); panel1.add(cards); } public void validateNumbersFields() { try { iPhone1 = Integer.parseInt(tPhoneNumber.getText()); iPhone2 = Integer.parseInt(tPhoneNumberOffice.getText()); iMonth = Integer.parseInt(tMonth.getText()); } catch(NumberFormatException ne) { JOptionPane.showMessageDialog(null,"You have entered CHARACTERS to a DIGITS ONLY field"); i=false; } } public void actionPerformed(ActionEvent ae) { validateNumbersFields(); if(ae.getSource().equals(button1)) { if(tPhoneNumber.getText() == null ? "" == null : tPhoneNumber.getText().equals("")) { JOptionPane.showMessageDialog(null,"Please fill the first name"); } else { if(i==false) { JOptionPane.showMessageDialog(null,"Error"); } else { ourLayout.show(cards, "one"); } } } } }
In here when the user clicks on the button, if all the CONDITIONS are OK, then the display should move to the second card. But that is not happening
. Please help me.
Are you better than me? Then please show me my mistakes..
Did you see how Paul
cut 87% off of his electric heat bill with 82 watts of micro heaters
?
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Form validation error
Error in FileReader
Display error in CardLayout
How to call variables in one applet using another applet?
java.lang.NullPointerException at runtime
More...