Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: lost

  1. #1
    Junior Member
    Join Date
    May 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default lost

    i'm trying to use a2d array to make a menubar

    why am i getting an error class expected at 48??


    import java.awt.*;
    import java.awt.event.KeyEvent;
    import javax.swing.*;
     
    public class Driver{
     
       public static void main(String[] args) {
          TheWindowObject aTestFrame = new TheWindowObject ("A MENU FOR YOU");  
     
          }
       }
    class TheWindowObject{
     
       TheWindowObject(String windowTitle)
       {
       CreateWindow () ;
       }
       TheWindowObject(String windowTitle, int height, int width){
       }
       JFrame CreateWindow (){
     
          String title ="test";
          int height =200 ;
          int width=400 ;
          JFrame frame= null;
     
          frame =new JFrame("A MENU FOR YOU");
          frame.setSize (width, height);
          frame.setVisible (true);
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
             generate();
             return frame;
          }
       }
    class MenuFactory {
     
    MenuFactory (String [][] menuInput)
    {}
     
     public JMenuBar generate()
    {
     JMenuBar generate= new JMenuBar();
     frame.setJMenuBar (generate);
    JMenu createMenu=null;
    JMenuItem createMenuItem = null ; 
    String  [][]menuInput= null;
    array();
    createMenu = new JMenu(menuInput[][]);
    generate.add(createMenu);
    return generate;
    }
     
    String [][]array (){
     
    String [][] menuInput ={{"File", "Edit", "Windows", "Help"},{"Open","Cut","First","About"},{"Close","Paste","Second", null},{"Exit","Copy",null, null},{null, "Select All", null, null,}};                    
       for (int row=0; row<array.length; row++){
       for ( int col=0; col< array[row].length; col++) 
       menuInput=(array[row][col]);
      }
      return menuInput;
       }
    }

    thanks


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: lost

    Looking towards line 48....the constructor for JMenu
    createMenu = new JMenu(menuInput[][]);
    does not exist. You should iterate through your menu input arrays a populate that way. In addition, you need to assign your menuInput array
    menuInput = array();
    or when you loop through your array you will end up receiving a null pointer exception

  3. #3
    Junior Member
    Join Date
    Sep 2009
    Location
    zambia
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: lost

    i would suggest you use object oriented approach where you put your test class and your methods in separate classes. that way it will be essay for you to debug and modify your code and its a good programming skill that you should develop..

Similar Threads

  1. Completely Lost in this problem(multiple methods)
    By wacarter in forum What's Wrong With My Code?
    Replies: 0
    Last Post: March 31st, 2010, 04:44 PM
  2. Need Help! I'm completly lost!
    By DeMolay8613 in forum Java Theory & Questions
    Replies: 0
    Last Post: January 11th, 2010, 01:21 PM
  3. please could you help me with this java problem im very lost
    By eyeore in forum Java Theory & Questions
    Replies: 4
    Last Post: September 7th, 2009, 09:19 AM