.................................................. ..........DELETED
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
.................................................. ..........DELETED
What is it supposed to do when there is bad input?
The posted code does not compile without compiler errors.
The code is poorly formatted. Many lines are not indented inside of {}s that should be. That makes the code hard to read and understand,
If you don't understand my answer, don't ignore it, ask a question.
Its now fixed thanks for your input...
You need to read the API doc and tutorial about how to use CardLayout.
The code does not tell the layout the names of the components.
http://docs.oracle.com/javase/tutori...yout/card.html
That's wrong. There are missing class definitions for the posted code.I know there is no errors
import java.awt.*; import javax.swing.*; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; public class Gu8il { public static void main(String[] args) { JFrame f1 = new JFrame("Keith"); Container cp = f1.getContentPane(); cp.setLayout(new FlowLayout()); final CardLayout cards = new CardLayout(); final JPanel cardPanel = new JPanel(); cardPanel.setLayout(cards); //First card final JPanel firstCard = new JPanel(); final JTextField tf1=new JTextField("pass",10); //<<<<<<<<<<< preload for testing final JTextField tf2=new JTextField("pass", 10); JLabel lab10=new JLabel("Username"); JLabel lab11=new JLabel("Password"); final String user = "pass"; final String passwd = "pass"; JButton switchButton = new JButton("Switch Cards"); String myText1 = tf1.getText(); String myText2 = tf2.getText(); switchButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { String myText1 = tf1.getText(); String myText2 = tf2.getText(); System.out.println("mY1="+myText1 + ", mT2="+myText2); //<<<<<<<<<<<<<<< if (myText1.equals(user) && (myText2.equals(passwd))) cards.next(cardPanel); else { System.out.println("show fifthCard"); //<<<<<<<<<<<<<<<<< cards.show(cardPanel, "fifthCard"); } } }); firstCard.add(lab10); firstCard.add(tf1); firstCard.add(lab11); firstCard.add(tf2); firstCard.add(switchButton); //end of first card //Second card final JPanel secondCard = new JPanel(); final JTextField jTextField1 = new JTextField(20); final JTextField jTextField2 = new JTextField(20); JLabel myFahrenheit = new JLabel("Enter Fahrenheit"); JButton myButton = new JButton("Convert"); ActionListener a1 = new ActionListener() { public void actionPerformed(ActionEvent e) { Double Fahrenheit = Double.parseDouble(jTextField1.getText()); Double myCelius = (5.0/9.0)*(Fahrenheit - 32); jTextField2.setText(Double.toString(myCelius)+ " degrees celsius"); }}; //????????????????<<<<<<<<<<<< myButton.addActionListener(a1); secondCard.add(myFahrenheit); secondCard.add(jTextField1); secondCard.add(jTextField2); secondCard.add(myButton); JButton secondButton = new JButton("Next"); secondButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { cards.next(cardPanel); } }); secondCard.add(secondButton); //end of second card //Third card final JPanel thirdCard = new JPanel(); final JTextField jTextField3 = new JTextField(10); final JComboBox cars = new JComboBox(); cars.addItem("Honda"); cars.addItem("Ford"); cars.addItem("Audi"); cars.addItem("BMW"); JButton addbutton = new JButton("Add to List"); ActionListener a3 = new ActionListener() { public void actionPerformed(ActionEvent e) { String myText = jTextField3.getText(); cars.addItem(myText); }}; addbutton.addActionListener(a3); JButton minusbutton = new JButton("Remove from List"); ActionListener a4 = new ActionListener() { public void actionPerformed(ActionEvent e) { cars.removeItem(cars.getSelectedItem()); }}; minusbutton.addActionListener(a4); thirdCard.add(jTextField3); thirdCard.add(cars); thirdCard.add(addbutton); thirdCard.add(minusbutton); JButton thirdButton = new JButton("Next"); thirdButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { cards.next(cardPanel); } }); thirdCard.add(thirdButton); //end of third card //Fourth card final JPanel fourthCard = new JPanel(); JButton LL=new JButton("Launch Text Compare"); JButton LTC=new JButton("Launch Tempeture Converter"); JButton LARC=new JButton("Launch Add/Remove from ComboBox"); ActionListener a5 = new ActionListener() { public void actionPerformed(ActionEvent e) { // checkText A1 =new checkText(); //?????????????????? } }; ActionListener a6 = new ActionListener() { public void actionPerformed(ActionEvent e) { // tempConvert A2 =new tempConvert(); //????????????????? } }; ActionListener a7 = new ActionListener() { public void actionPerformed(ActionEvent e) { // AddRemoveItemFromCombo A3 =new AddRemoveItemFromCombo(); //?????????????????? } }; LL.addActionListener(a5); LTC.addActionListener(a6); LARC.addActionListener(a7); fourthCard.add(LL); fourthCard.add(LTC); fourthCard.add(LARC); //end of fourth card //Fifth card final JPanel fifthCard = new JPanel(); JLabel fifthLabel=new JLabel("You entered the incorrect username or password"); fifthCard.add(fifthLabel); JButton fifthButton = new JButton("Next"); fifthButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { cards.show(cardPanel, "firstCard"); } }); fifthCard.add(fifthButton); //end of fifth card cardPanel.add(firstCard, "firstCard"); //<<<<<<<<<<< Need name of card<<<<<<<<<<< cardPanel.add(secondCard, ""); cardPanel.add(thirdCard, ""); cardPanel.add(fourthCard, ""); cardPanel.add(fifthCard, "fifthCard"); cp.add(cardPanel); f1.pack(); f1.setSize(800,400); f1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f1.setVisible(true); } }
If you don't understand my answer, don't ignore it, ask a question.
Please don't delete your questions as they are not for you only but are also for coders who in the future search for answers for similar problems. Simply deleting your question when it has been solved is a bit selfish and unfair to them.