I am trying to create a banking system which can state if the user has selected the SavingJRadioButton or the CheckingJRadioButton. Before using getters and setters, I used public static variables which worked, but my teacher wants getters and setters. So far my code looks like this:
public class CreateAccount extends JFrame
{
public JRadioButton
checkingJRadioButton,
savingJRadioButton;
public JRadioButton getCheckingJRadioButton()
{
return checkingJRadioButton;
}
public void setCheckingJRadioButton(JRadioButton cJB)
{
checkingJRadioButton = cJB;
}
public JRadioButton getSavingJRadioButton()
{
return savingJRadioButton;
}
public void setSavingJRadioButton(JRadioButton sJB)
{
savingJRadioButton = sJB;
}
public CreateAccount()
{
createCreateAccount();
}
public void createCreateAccount()
{
createaccountJButton = new JButton("Create Account");
createaccountJButton.setBounds(280, 600, 150, 50);
createaccountJButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
double balance = validatebalance();
String address = addressJTextField.getText();
String name = nameJTextField.getText();
if(address.equals("") || name.equals(""))
{
JOptionPane.showMessageDialog(null, "Your account was not created." + "\nPlease enter a valid address and name."
, "ERROR", JOptionPane.ERROR_MESSAGE);
addressJTextField.setBackground(Color.red);
nameJTextField.setBackground(Color.red);
}
else
{
if(savingJRadioButton.isSelected())
{
getSavingJRadioButton();
savings = new savingAccount(balance, address, name);
//Pass data through the constructor
TransactionScreen screen = new TransactionScreen(savings);
closeNewAccountScreen();
JOptionPane.showMessageDialog(null, "Your Account Was Created!", "NEW ACCOUNT", JOptionPane.INFORMATION_MESSAGE);
}
else if(checkingJRadioButton.isSelected())
{
//open checking account
getCheckingJRadioButton();
checkings = new checkingAccount(balance, address, name);
TransactionScreen screen = new TransactionScreen(checkings);
closeNewAccountScreen();
JOptionPane.showMessageDialog(null, "Your Account Was Created!", "NEW ACCOUNT", JOptionPane.INFORMATION_MESSAGE);
}
}
}
}
);
contentPane.add(createaccountJButton);
}
That was my CreateAccount class, but now I have to pass it to the screen containing the withdraw and deposit buttons, but I think this is where it all goes down.
public class TransactionScreen extends JFrame
{
public JButton
depositJButton,
withdrawJButton,
createaccountJButton;
private JLabel
depositPictureJLabel,
withdrawPictureJLabel;
private JLabel screenJLabel;
private CreateAccount createAccount;
private savingAccount savings;
private checkingAccount checkings;
private CreateAccount checkingJRadioButton;
public TransactionScreen()
{
createTransactionsScreen();
createAccount = new CreateAccount();
}
public void createTransactionsScreen()
{
Container contentPane = getContentPane();
contentPane.setLayout(null);
contentPane.setBackground(Color.white);
depositJButton = new JButton("Deposit");
depositJButton.setBounds(430, 150, 150, 75);
contentPane.add(depositJButton);
depositJButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
if(createAccount.savingJRadioButton.isSelected())
{
createAccount.getSavingJRadioButton();
DepositScreen depositScreen = new DepositScreen(savings);
closeTransactionScreen();
}
if(createAccount.checkingJRadioButton.isSelected())
{
createAccount.getCheckingJRadioButton();
DepositScreen depositScreen = new DepositScreen(checkings);
closeTransactionScreen();
}
}
}
);
}
Now for some reason the JRadioButtons do not pass to the Transaction Screen. Please help.
Thanks.