Results 1 to 3 of 3
Thread: Problem with JPanel
- 11-09-2007, 12:11 AM #1
Member
- Join Date
- Nov 2007
- Location
- Bay Area, CA
- Posts
- 13
- Rep Power
- 0
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:
Thanks in advance,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); } }
- Jeff
- 11-09-2007, 05:32 AM #2
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 } }
- 11-09-2007, 05:04 PM #3
Member
- Join Date
- Nov 2007
- Location
- Bay Area, CA
- Posts
- 13
- Rep Power
- 0
Similar Threads
-
JPanel won't update
By ibanez270dx in forum New To JavaReplies: 3Last Post: 01-06-2009, 08:59 PM -
refresh JPanel
By olesja in forum AWT / SwingReplies: 1Last Post: 04-16-2008, 03:58 PM -
Genarate JPanel
By Bill in forum AWT / SwingReplies: 6Last Post: 03-24-2008, 07:38 PM -
JPanel Problems
By Riftwalker in forum AWT / SwingReplies: 6Last Post: 10-15-2007, 11:16 PM -
Draw on JPanel, Help
By carl in forum Java 2DReplies: 1Last Post: 07-31-2007, 06:56 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks