Code:package BanqueDeux; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.*; import java.applet.*; import java.awt.*; import javax.swing.JTextField; public class HelloJava extends Applet { private JFrame frame = new JFrame("WelcomeToBarclaysBank"); private JLabel label = new JLabel("Thank you, Welcome, Please Insert Your Card, If Finished Close Window", JLabel.LEFT); //Frame Size Changes and Writing on one individual frame including JLabels etc. private JButton clix = new JButton("EnterYourPIN"); private JLabel j = new JLabel("-----------------------------------------------------------------------------------------------------------"); private JButton une = new JButton("1"); private JButton deux = new JButton("2"); private JButton trois = new JButton("3"); private JButton quatre = new JButton("4"); private JButton cinq = new JButton("5"); private JButton six = new JButton("6"); private JButton sept = new JButton("7"); private JButton huit = new JButton("8"); private JButton neurfe = new JButton("9"); private JButton zero = new JButton("0"); private JTextField pinField = new JTextField(6); private JButton ui = new JButton("Enter"); public HelloJava() { frame.getContentPane().add(label); add(clix); add(j); add(une); add(deux); add(trois); add(quatre); add(cinq); add(six); add(sept); add(huit); add(neurfe); add(zero); add(pinField); add(ui); //JButton declared for allow PIN Entry and an add of a JButton to the applet. clix.addActionListener ( new ActionListener() { public void actionPerformed(ActionEvent e) { String title = "Barclays Banking"; String pin = JOptionPane.showInputDialog("Please Enter Your PIN!"); if(pin.equals("1111")) { String accnumbre = JOptionPane.showInputDialog("Enter your Account Number"); if(accnumbre.equals("0072525")) { JOptionPane.showMessageDialog(null, "Entered Correct PIN and Account Number, Welcome"); } } else if(pin.equals("")) { JOptionPane.showMessageDialog(null, "No PIN or AccNumbre Entered"); } else { JOptionPane.showMessageDialog(null, "Wrong PIN or AccNumbre Entered"); } } } ); une.addActionListener ( new ActionListener() { public void actionPerformed(ActionEvent e) { pinField.setText(pinField.getText() + "1"); } } ); deux.addActionListener ( new ActionListener() { public void actionPerformed(ActionEvent e) { pinField.setText(deux.getText() + "2"); } } ); trois.addActionListener ( new ActionListener() { public void actionPerformed(ActionEvent e) { pinField.setText(trois.getText() + "3"); } } ); quatre.addActionListener ( new ActionListener() { public void actionPerformed(ActionEvent e) { pinField.setText(quatre.getText() + "4"); } } ); cinq.addActionListener ( new ActionListener() { public void actionPerformed(ActionEvent e) { pinField.setText(cinq.getText() + "5"); } } ); six.addActionListener ( new ActionListener() { public void actionPerformed(ActionEvent e) { pinField.setText(six.getText() + "6"); } } ); sept.addActionListener ( new ActionListener() { public void actionPerformed(ActionEvent e) { pinField.setText(sept.getText() + "7"); } } ); huit.addActionListener ( new ActionListener() { public void actionPerformed(ActionEvent e) { pinField.setText(huit.getText() + "8"); } } ); neurfe.addActionListener ( new ActionListener() { public void actionPerformed(ActionEvent e) { pinField.setText(neurfe.getText() + "9"); } } ); zero.addActionListener ( new ActionListener() { public void actionPerformed(ActionEvent e) { pinField.setText(zero.getText() + "0"); } } ); ui.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (pinField.equals("1111")) { JOptionPane.showMessageDialog(null, "Your PIN is correct"); setVisible(true); } else if(pinField.equals("")) { JOptionPane.showMessageDialog(null, "Nothing Entered"); } } }); frame.setSize(300, 300); frame.setVisible(true); } }(Above) This is my code.....Code:import java.applet.*; import javax.swing.*; import java.awt.event.*; import java.awt.event.*; import java.awt.event.*; import java.awt.*; import java.awt.Container; import java.awt.FlowLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseEvent; //Java AWT Declaration Eveents e.g. ActionEvent/Listener/Mouse import BanqueDeux.*; import javax.swing.JApplet; import javax.swing.JButton; import javax.swing.JDialog; import javax.swing.JFrame; import javax.swing.JLabel; //importing another package and Different Buttons and Applets for Suitable Use. //Bibliogaphy/Bibliographie- JavaExamplesInANutshell- O-REILY //Bibliography/Bibliographie- Google- Search: AppletObjects public class BanqueATM extends Applet{ public static Frame myFrame = new Frame(); public static BanqueClass BC = new BanqueClass(); //static frame and banque class declaration in addition to coding scope. Label greetingdeux = new Label("+++++BARCLAYS BANK+++++++-©- International ="); Label greetingune = new Label("------------------------Ask a Banker For Your Pin-----------------------------"); Label greeting = new Label("Welcome To Barclays Bank"); Button clickButton = new Button("(PIN)-Click Here To Enter PIN"); Label greetingtrois = new Label("***+++Withdraw Amount With Receipt+++++****"); Button clique = new Button("Click"); Label greetingjeur = new Label("**+++++++++Change Your PIN+++++++++++**"); Button Buttoner = new Button("Confirm"); Label grting = new Label("**++Print Mini Statementr++**"); Button cliquedix = new Button("Print Statement"); Label ecole = new Label("++++++++++**Withdraw With No Receipt***++++++++++"); Button clinuyi = new Button("Click"); Label fraisses = new Label("++++++View your current balance++++++"); Button fraissesshow = new Button("View"); Label f = new Label("--------------Return Card and Finish----------------"); Button fo = new Button("Finish-ReturnCard"); Label greetingx = new Label("-----------------------------------------------------"); Label greetingg = new Label("------------------------------------------------"); Label ifrancais = new Label("EMail a Banker at customerservices@barclays.co.uk"); Label u = new Label("E-mail for programme help at '"); Button almost = new Button("Help"); //GUI Main Applet Graphics, Including Buttons, Labels etc, Text near is what is shown in Applet public void init() { //Declaration of Main Display of Class setBackground(Color.lightGray); add(greetingdeux); add(greetingune); add(greeting); add(clickButton); add(greetingtrois); add(clique); add(greetingjeur); add(Buttoner); add(grting); add(cliquedix); add(ecole); add(clinuyi); add(fraisses); add(fraissesshow); add(f); add(fo); add(greetingx); add(greetingg); add(ifrancais); add(u); add(almost); //Adding Different Objects to the actual specific Class rather than //others Frame appletFrame = new Frame("PleaseRe-SizeWindowToEnterPIN"); appletFrame.setLayout(new GridLayout(1,0)); appletFrame.resize(500, 300); appletFrame.show(); Applet HelloJava = new HelloJava(); appletFrame.add(HelloJava); HelloJava.init(); HelloJava.start(); //Frames shown are resized and includes a joint applet to the main ATM class. cliquedix.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent evt) { String title = "Barclays Banking"; String message = "Thank you, Please Wait, Your Mini Statement is being Printed."; JOptionPane.showMessageDialog(null, message, title, JOptionPane.INFORMATION_MESSAGE); } }); //An individual action Listener event which initiates on mouse click clickButton.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { String title = "Barclays Banking"; String pin = JOptionPane.showInputDialog("Please enter your PIN!"); if (pin.equals("1111")) { JOptionPane.showMessageDialog(null, "Entered PIN: "+pin+". Welcome", "Barclays", JOptionPane.INFORMATION_MESSAGE); } else if(pin.equals("")) { JOptionPane.showMessageDialog(null, "No PIN Entered"); } else { JOptionPane.showMessageDialog(null, "Wrong PIN Entered"); } } }); //An individual action Listener event which initiates on mouse clic clique.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { String enterpindeux = JOptionPane.showInputDialog("Enter PIN Before Withdrawing"); if (enterpindeux.equals("1111")) { String cash = JOptionPane.showInputDialog("How Much Cash Would You Like To Withdraw?"); JOptionPane.showMessageDialog(null, "Withdrawing the following amount with Receipt: "+cash+". Amount Withdrawing", "Barclays", JOptionPane.INFORMATION_MESSAGE); } else { JOptionPane.showMessageDialog(null, "Wrong PIN Sir/Madam"); } } }); //An individual action Listener event which initiates on mouse click Buttoner.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { String changepin = JOptionPane.showInputDialog("What is your Old PIN? [ConsideringYourPreviousPINHasBeenEntered]"); if (changepin.equals("1111")) { String newpin = JOptionPane.showInputDialog(null, "What is Your New PIN?"); JOptionPane.showMessageDialog(null, "PIN Changed"); } else if(changepin.equals("")) { JOptionPane.showMessageDialog(null, "NoPIN Entered"); } else { JOptionPane.showMessageDialog(null, "Wrong PIN Sir/Madam"); } } }); //An individual action Listener event which initiates on mouse click clinuyi.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { String enterpin = JOptionPane.showInputDialog("Enter Your PIN Before Withdrawing"); if (enterpin.equals("1111")) { String cashdeux = JOptionPane.showInputDialog("How Much Cash Would You Like To Withdraw (w/o receipt)?"); JOptionPane.showMessageDialog(null, "Withdrawing the following amount without Receipt: "+cashdeux+". Amount Withdrawing", "Barclays", JOptionPane.INFORMATION_MESSAGE); } else { JOptionPane.showMessageDialog(null, "Wrong PIN Sir/Madam"); } } }); //An individual action Listener event which initiates on mouse click almost.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { JOptionPane.showMessageDialog(null, "Help Can be found at www.barclays.co.uk, customerservices@barclays.co.uk, Thank you"); } }); //An individual action Listener event which initiates on mouse click //If and Else Statements included in all action Listeners. fraissesshow.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { double newAmount, initialAmount; newAmount = initialAmount = 20; try { double withdrawelAmount = Double.parseDouble(JOptionPane.showInputDialog("How much have you withdrawn?")); newAmount = initialAmount - withdrawelAmount; } catch (NumberFormatException e) { System.err.println("That is not a number, Sir!"); System.err.println("Transaction Void"); } JOptionPane.showMessageDialog(null, "You have: "+newAmount); } }); fo.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { String Carde = JOptionPane.showInputDialog(null, "Card Returned, Type PIN To Finish"); if (Carde.equals("1111")) { setVisible(false); } } }); } }
This is the problem in the HelloJava class.......
When I run the problem code it compiles in the Hello Java class but does not allow for the numbers to be shown as correct or Incorrect or Nothing entered by an message input dialog, could someone help with why nothing is shown upon clicking the button and how I can make sure if I enter 1111 (the pin) or an incorrect PIN (2222) it tells me if its incorrect or correct.Code:ui.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (pinField.equals("1111")) { JOptionPane.showMessageDialog(null, "Your PIN is correct"); setVisible(true); } else if(pinField.equals("")) { JOptionPane.showMessageDialog(null, "Nothing Entered"); } } });
The PIN can be entered from clicking the JButtons I want it to verify if the numbers in the JTextField are correct or not by an InputDialog.
Thank you.


LinkBack URL
About LinkBacks




Reply With Quote






Bookmarks
Algorithms and Data Structures
Java tutorials
Algorithms Forum