//When I have the GUI in a separate file it works, but having it with this entire code it won't work. Any help is great!
javac -classpath .:/run_dir/junit-4.12.jar:target/dependency/* -d . Main.javaimport java.lang.Math; // headers MUST be above the first class import javax.swing.JPanel; import javax.swing.JFrame; import javax.swing.BorderFactory; import javax.swing.JButton; import javax.swing.JLabel; import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.awt.BorderLayout; import java.awt.GridLayout; class Screen implements ActionListener { public Screen(){ JFrame frame=new JFrame(); //adds jframe JButton button=new JButton("Deposit"); //creates a button button.addActionListener(this); //makes button clickable JLabel label = new JLabel("Select deposit amount"); //sets title JPanel panel = new JPanel(); // screen for program panel.setBorder(BorderFactory.createEmptyBorder(100, 100, 100, 100));//size of screen panel.setLayout(new GridLayout(0,1));//layout for screen panel.add(button);//adds button panel.add(label);//adds label frame.add(panel, BorderLayout.CENTER);//sets screen to center frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);// exits screen frame.setTitle("Deposits");//sets tile frame.pack();// frame.setVisible(true); //set screen to visible } public static void Screen(String[] args){ new Screen(); } public void actionPerformed(ActionEvent e){ } } class Main { public static void main (String []args) { Sweringen_BankAccount BankAccountOne = new Sweringen_BankAccount(); //Settinge up account 1 Sweringen_BankAccount BankAccountTwo = new Sweringen_BankAccount(); //Setting up account 2 BankAccountOne.setAccountNumber("1"); //setting up account number BankAccountOne.setAccountType("Savings"); //setting up account type BankAccountTwo.setAccountNumber("2"); //setting up account number BankAccountOne.setAccountType("Savings"); //setting up account type BankAccountTwo.setAccountType("Checkings"); System.out.println( BankAccountOne.getAccountType()+ " is account " + BankAccountOne.getAccountNumber() + " owned by " + BankAccountOne.getAccountHolder()); //printing account type, holder, and balance System.out.println(BankAccountTwo.getAccountType() + " is account " + BankAccountTwo.getAccountNumber() + " owned by " + BankAccountTwo.getAccountHolder() );//printing account type, holder, and balance System.out.println("Savings account withholds " + BankAccountOne.getAccountBalance() + " dollars");//printing account type, holder, and balance System.out.println("Savings account withholds " + BankAccountTwo.getAccountBalance() + " dollars");//printing account type, holder, and balance } } class Sweringen_BankAccount { private String AccountNumber; //variable for account number private String AccountType;//variable for account type private String AccountHolder; //variable for account holder static private int AccountBalance=0; // variable for account balance /******************* Mutator Methods ****************/ public void setAccountNumber (String AccountNumber) { this.AccountNumber= AccountNumber;// AccountHolder = "Max"; //naming account holder } public void setAccountType (String AccountType) { this.AccountType= AccountType; AccountBalance++; } /******************* Accessor Methods ****************/ public String getAccountNumber() { return AccountNumber; } public String getAccountType() { return AccountType; } public String getAccountHolder() { return AccountHolder; } static public int getAccountBalance() { return AccountBalance; } }
java -classpath .:/run_dir/junit-4.12.jar:target/dependency/* Main
Savings is account 1 owned by Max
Checkings is account 2 owned by Max
Savings account withholds 3 dollars
Savings account withholds 3 dollars