Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-09-2007, 01:11 AM
Member
 
Join Date: Nov 2007
Location: Bay Area, CA
Posts: 13
ibanez270dx is on a distinguished road
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
Sponsored Links
  #2 (permalink)  
Old 11-09-2007, 06:32 AM
Senior Member
 
Join Date: Jul 2007
Posts: 1,015
hardwired is on a distinguished road
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, 06:04 PM
Member
 
Join Date: Nov 2007
Location: Bay Area, CA
Posts: 13
ibanez270dx is on a distinguished road
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
Sponsored Links
Reply


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

vB 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
refresh JPanel olesja AWT / Swing 1 04-16-2008 04:58 PM
Genarate JPanel Bill AWT / Swing 6 03-24-2008 08:38 PM
JPanel won't update ibanez270dx New To Java 2 11-19-2007 05:42 AM
JPanel Problems Riftwalker AWT / Swing 6 10-16-2007 12:16 AM
Draw on JPanel, Help carl Java 2D 1 07-31-2007 07:56 AM


All times are GMT +3. The time now is 02:26 PM.


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