DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2
  1. #1
    Join Date
    May 2005

    Question Probably simple...

    Hello there. Just starting off in Java, I have experience in other languages, and have read a Java book (and then forgot most of it).

    Anyways, I simply cannot figure out why this program won't work properly. When I try to execute it, it just closes before actually starting, but after compiling.

    Here's what I'm trying to do:
    Make a window with 2 panels, each with their own tabs.

    Right now tab2, called content, is just plain and is using nothign special, to be changed once I get the first one to work.

    If you have any other questions feel free to ask. Thanks in advance, and check the source code attached.
    Attached Files Attached Files

  2. #2
    Join Date
    Nov 2004

    Some remarks

    Note: I've made it a JApplet, after all, you were using swing components
    inside an awt component and that is not a recommended practise...

    // our imports
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class GUIBreasts
        extends JApplet {
      // creates the border
      BorderLayout myLayout = new BorderLayout();
      // right now this is static, well change after we get menu working
      Panel content = new Panel();
      // our menu
      private JTabbedPane menu;
      // our menu tabs
      //private Panel System; /// <======== NOOOOOO ! System is a java.lang basic 
                             // class, and you don't want to 'disable' it like this, 
                             // no way...
      private Panel ASystem;
      private Panel Games;
      private Panel Apps;
       * An applet constructor is useless, the browser will use the basic
       * parameterless constructor no matter what you do,  so the init()
       * method may be regarded as *the* applet constructor
      public void init() { // <========= autoinvoked by browser after instantiation
        // sets the size... duh
        setSize(300, 200);
        // creates the panel
        Panel topPanel = new Panel();
        // sets the layout
        // and then adds it
        // adds a button to content as a control type thing
        content.add(new Button("Test2"));
        // setting up our menu
        //add out 2 panels
        topPanel.add(menu, BorderLayout.WEST);
        topPanel.add(content, BorderLayout.CENTER);
      public void addMenu() {
        // makes our menu tab
        menu = new JTabbedPane();
        // makes our first tab
        ASystem = new Panel();
        ASystem.add(new Button("Games"));
        menu.addTab("System", null, ASystem, "System");
        // and our second tab
        Panel Games = new Panel();
        Games.add(new Button("Games"));
        menu.addTab("Games", null, Games, "Games");
        // and third
        Panel Apps = new Panel();
        Apps.add(new Button("Applications"));
        menu.addTab("Applications", null, Apps, "Applications");
       * Standalone addition.
       * An applet is a panel descendant, and making it visible has no effect 
       * whatsoever unless it is contained in some  kind of window 
       * (a Frame/JFrame or a browser) 
       * @param args
      public static void main(String[] args) {
        // creates a type of this
        GUIBreasts gui = new GUIBreasts();
        Frame f=new Frame("Breasts ...! (pant! pant! pant!)");
        f.setLayout(new GridLayout());
        gui.init(); // no browser in this mode.... must do init() "manually"
        // ensure proper termination
        f.addWindowListener(new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
        // exectutes it
    eschew obfuscation

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center