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 3 of 3

Thread: JFrame + JTextField Question

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

    Default JFrame + JTextField Question

    Hey guys, I need help adding a textbox for users to input text onto my JFRame. Also how come the
    frame.add(o);
    is getting an error under the "add".

    Main method class:

    import javax.swing.JFrame;
     
    public class main
    {
      public static void main(String[] args)
      {
        JFrame frame = new JFrame();
        bot o = new bot();
     
        frame.add(o);
        frame.setVisible(true);
        frame.setDefaultCloseOperation(3);
        frame.setSize(300, 400);
        frame.setTitle("Chitter");
      }
    }

    Other class (this is where I want the textbox to be)


    import javax.swing.JTextArea;
    import javax.swing.JTextField;
     
     
    public class bot {
     
    	int x;
    	int y;
     
    	JTextField f = new JTextField();
    	JTextArea a = new JTextArea(30, 50);
     
    }

    Thanks!

    - Ab


  2. #2
    Moderators
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    7,448
    My Mood
    Mellow
    Thanks
    288
    Thanked 899 Times in 879 Posts

    Default Re: JFrame + JTextField Question

    Post code that demonstrates the error and/or post the error message EXACTLY as it appears at your end, the whole thing.

  3. #3
    Administrator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    24,848
    Thanks
    64
    Thanked 2,645 Times in 2,615 Posts

    Default Re: JFrame + JTextField Question

    Read the API doc for the add() method to see what are the valid arguments for it.

Similar Threads

  1. JFrame + JTextField and Random Number Generator
    By Richard_Harrow in forum AWT / Java Swing
    Replies: 12
    Last Post: April 30th, 2016, 16:18
  2. How to repaint() a class in a JFrame, with a JTextfield user input
    By DANGEROUSSCION in forum Object Oriented Programming
    Replies: 1
    Last Post: March 23rd, 2013, 15:06
  3. GUI Question (Jlabe/JTextField)
    By aandcmedia in forum AWT / Java Swing
    Replies: 5
    Last Post: April 4th, 2012, 18:07
  4. Jframe title setting question
    By derekxec in forum AWT / Java Swing
    Replies: 5
    Last Post: June 16th, 2011, 08:01
  5. JFrame Question
    By jayjay89 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: March 29th, 2011, 07:24