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
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 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
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: JFrame + JTextField Question

    Read the API doc for the add() method to see what are the valid arguments for it.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. JFrame + JTextField and Random Number Generator
    By Richard_Harrow in forum AWT / Java Swing
    Replies: 7
    Last Post: December 8th, 2013, 05:30 PM
  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, 03:06 PM
  3. GUI Question (Jlabe/JTextField)
    By aandcmedia in forum AWT / Java Swing
    Replies: 5
    Last Post: April 4th, 2012, 06:07 PM
  4. Jframe title setting question
    By derekxec in forum AWT / Java Swing
    Replies: 5
    Last Post: June 16th, 2011, 08:01 AM
  5. JFrame Question
    By jayjay89 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: March 29th, 2011, 07:24 AM