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: Help me please errors with code

  1. #1
    Junior Member
    Join Date
    Jun 2019
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Help me please errors with code

    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    import java.util.*;
     
    public static void main(String args[]){
    {
     
    JFrame frame = new JFrame("Login");
     frame.setSize(350, 200);
     frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
    public class NewUser extends JFrame {
      JButton create;
      JPanel newUserPanel;
      JTextField txuserer;
      JTextField passer;
     
     
      public NewUser(){
        super("Registration");
     
        create = new JButton("Create");
        newUserPanel = new JPanel();
        txuserer = new JTextField(15);
        passer = new JPasswordField(15);
     
     
        setSize(300,200);
        setLocation(500,280);
        newUserPanel.setLayout (null); 
     
     
        txuserer.setBounds(70,30,150,20);
        passer.setBounds(70,65,150,20);
        create.setBounds(110,100,80,20);
     
        newUserPanel.add(create);
        newUserPanel.add(txuserer);
        newUserPanel.add(passer);
     
        getContentPane().add(newUserPanel);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setVisible(true);
     
            }
            } 
        }
     
          }
        });
      } 
     
    }


    I'm getting 6 errors. Can you help me fix them?


    Error M<esssages:
    ----jGRASP exec: javac -g NewUser (1).java
    NewUser (1).java:7: error: class, interface, or enum expected
    public static void main(String args[]){
    ^
    NewUser (1).java:11: error: class, interface, or enum expected
    frame.setSize(350, 200);
    ^
    NewUser (1).java:12: error: class, interface, or enum expected
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);
    ^
    NewUser (1).java:13: error: class, interface, or enum expected
    }
    ^
    NewUser (1).java:49: error: class, interface, or enum expected
    }
    ^
    NewUser (1).java:53: error: class, interface, or enum expected
    }
    ^
    6 errors

    ----jGRASP wedge2: exit code for process is 1.
    ----jGRASP: operation complete.

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,407
    Thanks
    53
    Thanked 2,399 Times in 2,352 Posts

    Default Re: Help me please errors with code

    NewUser (1).java:7: error: class, interface, or enum expected
    All methods must be inside of a class.
    The code needs to define a class before defining methods. Move the method inside of the class.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Replies: 7
    Last Post: May 8th, 2014, 12:51 PM
  2. Few errors on my code.
    By hkfrenchtoast in forum What's Wrong With My Code?
    Replies: 25
    Last Post: February 23rd, 2014, 10:37 PM
  3. Replies: 3
    Last Post: April 27th, 2013, 07:19 AM
  4. Someone help me with my code it has some errors? Thanks!
    By skitheeast8 in forum What's Wrong With My Code?
    Replies: 7
    Last Post: November 1st, 2012, 06:37 PM
  5. Code is giving an error in console, but there are no errors apparent in the code!
    By JamEngulfer221 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 15th, 2011, 09:30 PM

Tags for this Thread