Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: GUI won't load up on repl.it

  1. #1
    Junior Member
    Join Date
    Mar 2021
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default GUI won't load up on repl.it

    //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!
    import 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;
     }
    }
     javac -classpath .:/run_dir/junit-4.12.jar:target/dependency/* -d . Main.java
     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
    Last edited by omegamax; March 30th, 2021 at 10:52 AM.

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,166
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: GUI won't load up on repl.it

    it won't work.
    Please explain what happens when you try to compile and execute the code.
    Copy all error messages and paste them here.

    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Load a vb.net dll in java???
    By fozzy in forum Java Theory & Questions
    Replies: 3
    Last Post: August 29th, 2014, 08:52 AM
  2. [SOLVED] Java won't load.
    By NewMember in forum What's Wrong With My Code?
    Replies: 3
    Last Post: February 18th, 2013, 06:08 PM
  3. Won't load next class...
    By Huw in forum What's Wrong With My Code?
    Replies: 14
    Last Post: September 21st, 2012, 12:07 AM
  4. won't load png
    By NewAtJava in forum What's Wrong With My Code?
    Replies: 6
    Last Post: March 30th, 2012, 03:24 PM
  5. Image Load
    By shadihrr in forum Java Theory & Questions
    Replies: 4
    Last Post: August 26th, 2010, 06:56 AM