Hey all.
Ok i've written the code below with no syntax errors. However, im struggling.
1) For Button 1 - Check Balance, I want to firstly bar out the pin number so it doesn't show. How do I do this?
2) For button 1 - I have added show input dialogs... however, following the 2 input dialogs, I want to add an option dialog and confirm dialog. But it throws the following error:
javax.swing.JOptionPane cannot be applied to (java.lang.string)
How can I add the different types of dialogs in one method? is that even possible?
Many thanks for the help in advance!!
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.Dialog.*;
import javax.swing.*;
import javax.swing.JOptionPane;
public class CashMachine extends JPanel implements ActionListener {
public JFrame f1;
public JButton B1;
protected JTextArea textArea;
public void createAndShowGUI(){
CashMachine c = new CashMachine(); // Because createAndShwoGUI is not a constructor but // rather an ordinary method we need to declare an
// Object of the class and make reference to it inside // this method
c.setPreferredSize (new Dimension (200, 200)); // Setting dimensions of the Object.
c.setLayout(null); // because we will use Absolute Positioning
f1 = new JFrame ("Welcome To Barclays Bank");
f1.setLayout(null);
f1.setContentPane(c); // Linking the frame f to the Object we c we just created.
//ImageIcon icon2 = createImageIcon("VW.jpg") ; // Creating an icon to hold an image.
JButton B1 = new JButton("Check Balance");
B1.setBounds(300, 380, 250, 70);
B1.addActionListener(this );
B1.setActionCommand("S1");
JButton B2 = new JButton("Withdraw Cash");
B2.setBounds(600 , 380, 250, 70);
B2.addActionListener(this );
B2.setActionCommand("S2");
JButton B3 = new JButton("Request Resources");
B3.setBounds(900 , 380, 250, 70);
B3.addActionListener(this );
B3.setActionCommand("S3");
JButton B4 = new JButton("Help");
B4.setBounds(600 , 480, 250, 70);
B4.addActionListener(this );
B4.setActionCommand("S4");
textArea = new JTextArea(10, 50); // This creates a Text Area of 5 rows and 30 columns.
textArea.setEditable(true); // You can change its content.
textArea.setBounds( 120, 30, 50, 100); // Position it any where you want.
//Putting some labels on the columns of the text area to act as headers for the receipt
textArea.append("Number of items " + "\t" + "Price " +"\n");
textArea.append("------------------------ " +"\t" + "------ " +"\n");
// Now we are dealing with Labels to hold logos or images.
ImageIcon icon = new ImageIcon(CashMachine.class.getResource("BARCLAYS.jpg"));
JLabel label = new JLabel(icon); // Creates a labels and puts the image on it.
label.setBounds( 400, 10, 690, 350); // Position it any where you want.
// Now add all the things you created ( i.e. Button, Scrollable Text Area, and Label) to the frame.
f1.add(label);
f1.add(B1);
f1.add(B2);
f1.add(B3);
f1.add(B4);
f1.pack();
f1.setVisible(true);
}
public void actionPerformed(ActionEvent e) {
if ("S1".equals(e.getActionCommand())) {
String CheckBalance = JOptionPane.showInputDialog("Please Enter Your Pin Number" );
if(CheckBalance != null)
JOptionPane.showInputDialog("Please Enter Your Account Number" );
if(CheckBalance != null)
textArea.setLineWrap(true); // This warps the text around the Text Area.
}
}
protected static ImageIcon createImageIcon(String path) {
java.net.URL imgURL = CashMachine.class.getResource(path);
if (imgURL != null) {
return new ImageIcon(imgURL);
} else {
System.err.println("Couldn't find file: " + path);
return null;
}
}
public static void main(String[] args) {
CashMachine c = new CashMachine();
// Here we are creating an Object of the class and call a method within it called createAndShow //GUI
c.createAndShowGUI();
}
} // end Class