Hello speedmaster, welcome to the forums.
You cannot put the if statement there because it is not in a method.
Take a look at this example:
import javax.swing.*;
public class BankAccount1 {
/**
* JavaProgrammingForums.com
*/
public static int Opt;
public static String setName(){
JFrame BankAccount = new JFrame();
BankAccount.setSize(400,400);
BankAccount.setTitle("Name");
BankAccount.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
String name = JOptionPane.showInputDialog("Enter your name to create an account");
return name;
}
public static int setAccountNumber(){
JFrame BankAccount = new JFrame();
BankAccount.setSize(400,400);
BankAccount.setTitle("AccNum");
BankAccount.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
String AccountNumber = JOptionPane.showInputDialog("Enter the desired account number:");
int AccountNum = Integer.parseInt((AccountNumber));
return AccountNum;
}
public static int setInitialBalance(){
JFrame BankAccount = new JFrame();
BankAccount.setSize(400,400);
BankAccount.setTitle("IntBalance");
BankAccount.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
String InitialBalance = JOptionPane.showInputDialog("Enter your initial balance:");
int InitBalance = Integer.parseInt((InitialBalance));
return InitBalance;
}
public static int setOptions (){
JFrame BankAccount = new JFrame();
BankAccount.setSize(400,400);
BankAccount.setTitle("Options");
BankAccount.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
String Options = JOptionPane.showInputDialog("What would you like to do?: \n" +
"Enter 1 to withdraw \n" +
"Enter 2 to deposit \n" +
"Enter 3 to check current balance \n");
Opt = Integer.parseInt((Options));
return Opt;
}
public static void ifstatement(){
if(Opt == 1){
System.out.println("Opt is 1");
}
}
}
Does it help?