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

Edited 6 Years Ago by peter_budo: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks)

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?

you could make your own input screens, instead of the JOptionPane standards, and use a JPasswordField instead of a JTextField

How can I add the different types of dialogs in one method? is that even possible?

by programming them both. yes, that is very possible

String CheckBalance = JOptionPane.showInputDialog("Please Enter Your Pin Number" );
if(CheckBalance != null)
JOptionPane.showInputDialog("Please Enter Your Account Number" );
if(CheckBalance != null)

what exactly do you want to do here? why re-checking the value of CheckBalance? either you can use brackets around the entire part of code that should be run only if CheckBalance != null, or you should change CheckBalance's value. otherwise, re-checking is not the most effective way to work.

String CheckBalance = JOptionPane.showInputDialog("Please Enter Your Pin Number" );
if(CheckBalance != null)
JOptionPane.showInputDialog("Please Enter Your Account Number" );
if(CheckBalance != null)

^ Ive created the cash machine interface. With the above code, the customer enters their card. They enter their pin number, followed by the account number. What i'm struggling with is s that I want to show their balance and offer them a print out of their balance/statement from a yes/no option dialog box. But I do not know how to do this straight after the above code.

So basically im asking, how can I add the different types of dialogs in one method?

Edited 6 Years Ago by sabah_786: n/a

So basically im asking, how can I add the different types of dialogs in one method?

like this:

public void readAndShowInput(){
String input = JOptionPane.showInputDialog(null,"get input");
JOptionPane.showMessageDialog(null, input);
}

this is one method, containing several different types of dialogs. so, just write the method like that, and you have 'm

Thank you sooooo much!! That worked perfectly!!! Thanksssss a million!!! WOOOO HOOO!

I will be back in the near future with more errors (hope not!) :-)

This article has been dead for over six months. Start a new discussion instead.