Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-09-2007, 12:11 AM
Member
 
Join Date: Nov 2007
Location: Bay Area, CA
Posts: 13
Rep Power: 0
ibanez270dx is on a distinguished road
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:

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
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 11-09-2007, 05:32 AM
Senior Member
 
Join Date: Jul 2007
Posts: 1,389
Rep Power: 3
hardwired is on a distinguished road
Default
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
    } 
 }
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 11-09-2007, 05:04 PM
Member
 
Join Date: Nov 2007
Location: Bay Area, CA
Posts: 13
Rep Power: 0
ibanez270dx is on a distinguished road
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
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
JPanel won't update ibanez270dx New To Java 3 01-06-2009 08:59 PM
refresh JPanel olesja AWT / Swing 1 04-16-2008 03:58 PM
Genarate JPanel Bill AWT / Swing 6 03-24-2008 07:38 PM
JPanel Problems Riftwalker AWT / Swing 6 10-15-2007 11:16 PM
Draw on JPanel, Help carl Java 2D 1 07-31-2007 06:56 AM


All times are GMT +2. The time now is 03:49 AM.



VBulletin, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org