Results 1 to 3 of 3
  1. #1
    ibanez270dx is offline Member
    Join Date
    Nov 2007
    Location
    Bay Area, CA
    Posts
    13
    Rep Power
    0

    Default Problem with JPanel

    Hi everybody,
    I'm really new to Java and I'm making the GUI portion of an applet... Everything works and looks fine, except when I try to put the componants into a JPanel container... I've searched all over the web for help on it, but to no avail. If anyone can tell me where and what my error is, it would be greatly appreciated! My code is as follows:

    Java Code:
    import java.awt.*; 
    import java.applet.*; 
    import javax.swing.*;
    import java.awt.Container;
    
    public class gui5 extends Applet  
     { 
      public JLabel tailnum_Label; 
      public JButton tailnum_okButton; 
      public JTextField tailnum_TextField; 
    
      public void tailnumber()
          {  
           tailnum_Label = new JLabel("Please enter your Tail Number"); 
           tailnum_okButton = new JButton(" OK "); 
           tailnum_TextField = new JTextField("",180); 
      
           JPanel tailnum = new JPanel();
              tailnum.setLayout(null);
              tailnum.setBackground(new Color(214,223,239));
              tailnum.setBorder( BorderFactory.createLineBorder( Color.BLACK ) );
    
          	  tailnum_Label.setBounds(10,0,180,20);
         	  tailnum_TextField.setBounds(10,20,180,20);
         	  tailnum_okButton.setBounds(65,45,70,30);   
    
         	  tailnum.add(tailnum_Label);
          	  tailnum.add(tailnum_okButton); 
           	  tailnum.add(tailnum_TextField); 
          } 
    
     }
    Thanks in advance,
    - Jeff

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    9

    Default

    Java Code:
    //  <applet code="Gui5Rx" width="400" height="400"></applet>
    import java.awt.*; 
    import javax.swing.*;
    
    public class Gui5Rx extends JApplet  
    { 
        public JLabel tailnum_Label; 
        public JButton tailnum_okButton; 
        public JTextField tailnum_TextField; 
    
        // Applets use this method like applications use constructors.
        public void init()
        {  
            tailnum_Label = new JLabel("Please enter your Tail Number"); 
            tailnum_okButton = new JButton(" OK "); 
            tailnum_TextField = new JTextField("",180); 
    
            JPanel tailnum = new JPanel();
            tailnum.setLayout(null);
            tailnum.setBackground(new Color(214,223,239));
            tailnum.setBorder( BorderFactory.createLineBorder( Color.BLACK ) );
    
            tailnum_Label.setBounds(10,0,180,20);
            tailnum_TextField.setBounds(10,20,180,20);
            tailnum_okButton.setBounds(65,45,70,30);
    
            tailnum.add(tailnum_Label);
            tailnum.add(tailnum_okButton);
            tailnum.add(tailnum_TextField);
            System.out.println("default layout manager of " +
                                getClass().getName() + " = " +
                                getLayout().getClass().getName());
            Container cp = getContentPane();
            cp.add(tailnum);  // default center section
        } 
     }

  3. #3
    ibanez270dx is offline Member
    Join Date
    Nov 2007
    Location
    Bay Area, CA
    Posts
    13
    Rep Power
    0

    Default

    Thanks! I actually got it to work late last night, but its a little different. Your code definitely gives me more insight on how it should work. Thanks again!

    - Jeff

Similar Threads

  1. JPanel won't update
    By ibanez270dx in forum New To Java
    Replies: 3
    Last Post: 01-06-2009, 09:59 PM
  2. refresh JPanel
    By olesja in forum AWT / Swing
    Replies: 1
    Last Post: 04-16-2008, 04:58 PM
  3. Genarate JPanel
    By Bill in forum AWT / Swing
    Replies: 6
    Last Post: 03-24-2008, 08:38 PM
  4. JPanel Problems
    By Riftwalker in forum AWT / Swing
    Replies: 6
    Last Post: 10-16-2007, 12:16 AM
  5. Draw on JPanel, Help
    By carl in forum Java 2D
    Replies: 1
    Last Post: 07-31-2007, 07:56 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •