This is driving me crazy!!!


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: This is driving me crazy!!!

  1. #1
    Join Date
    Mar 2003
    Posts
    1

    Angry This is driving me crazy!!!

    The SDK is giving me and error with this Java code.

    It gives this error message:

    Code:
    guiprogram.java:43: cannot resolve symbol
    symbol  : variable pane
    location: class guiprogram
      pane.setJMenuBar(menubar1);
      ^
    1 error
    Please help! Here is my code:

    Code:
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class guiprogram extends JFrame {
     public guiprogram() {
      super("My Program that does Absolutely Nothing");
      setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      setSize(700, 500);
      JMenuItem m1 = new JMenuItem("Item 1");
      JMenuItem m2 = new JMenuItem("Item 2");
      JMenuItem m3 = new JMenuItem("Item 3");
      JMenuItem m4 = new JMenuItem("Item 4");
      JMenuItem m5 = new JMenuItem("Item 5");
      JMenuItem m6 = new JMenuItem("Item 6");
      JMenu menu1 = new JMenu("Menu 1");
      menu1.add(m1);
      menu1.add(m2);
      menu1.add(m3);
      menu1.addSeparator();
      menu1.add(m4);
      menu1.add(m5);
      menu1.add(m6);
      JMenu menu2 = new JMenu("Menu 2");
      menu2.add(m1);
      menu2.add(m2);
      menu2.add(m3);
      menu2.addSeparator();
      menu2.add(m4);
      menu2.add(m5);
      menu2.add(m6);
      JMenu menu3 = new JMenu("Menu 3");
      menu3.add(m1);
      menu3.add(m2);
      menu3.add(m3);
      menu3.addSeparator();
      menu3.add(m4);
      menu3.add(m5);
      menu3.add(m6);
      JMenuBar menubar1 = new JMenuBar();
      menubar1.add(menu1);
      menubar1.add(menu2);
      menubar1.add(menu3);
      JPanel pane = new JPanel();
      pane.setJMenuBar(menubar1);
      setContentPane(pane);
      try {
       UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
       SwingUtilities.updateComponentTreeUI(this);
      }
      catch (Exception e) {
       System.err.println("Can't set GUI: " + e);
      }
     }
     public static void main(String[] arguments) {
      guiprogram frame = new guiprogram();
      frame.setVisible(true);
     }
    }
    5Y573M XP10173R

  2. #2
    Join Date
    Mar 2003
    Posts
    834
    (Small point - your class names should really begin capitalized: GuiProgram)
    I actually got a different error:
    Code:
    C:\docs\forums\gui_test>javac guiprogram.java
    guiprogram.java:44: cannot resolve symbol
    symbol  : method setJMenuBar (javax.swing.JMenuBar)
    location: class javax.swing.JPanel
      pane.setJMenuBar(menubar1);
          ^
    1 error
    Basically, there isn't a method on JPanel called 'setJMenuBar'. It's on JFrame. Change line 44 to read:
    Code:
      this.setJMenuBar(menubar1);
    Then it should all work fine.

    Hope this helps,

    David.
    Attached Files Attached Files
    ArchAngel.
    O:-)

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
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

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