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 11 of 11

Thread: ProgramMenuBar problems

  1. #1
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Unhappy ProgramMenuBar problems

    I'm using the class ProgramMenuBar to make a Menu Bar that has print and will actually print.

    However, while the options are there, they throw Null Pointer Exceptions when selected.

    I have a big program I'm using, but you guys always want something smaller, so:


    import java.awt.color.ColorSpace;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.AdjustmentEvent;
    import java.awt.event.ItemEvent;
    import java.awt.event.ItemListener;
    import java.awt.event.KeyEvent;
    import java.awt.event.MouseEvent;
     
    import javax.swing.event.MenuEvent;
    import javax.swing.event.MenuListener;
    import javax.swing.event.PopupMenuEvent;
    import javax.swing.event.PopupMenuListener;
    import javax.swing.text.DefaultStyledDocument;
     
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
     
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JOptionPane;
    import javax.swing.JPanel;
    import javax.swing.JTextArea;
    import javax.swing.ScrollPaneConstants;
     
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
     
    import java.util.*;
    import java.io.*;
    import javax.swing.ImageIcon;
     
     
    import java.awt.event.WindowEvent;
    import java.awt.Window;
    import javax.swing.JScrollPane;
    import java.awt.Component;
    import javax.swing.JMenu;
    import javax.swing.JMenuItem;
    import acm.io.*;
    import acm.graphics.*;
    import acm.program.*;
    import acm.gui.*;
    import acm.util.*;
    import java.awt.Container;
     
    public class sampleClass extends JFrame
    {
    JPanel panel;
    JMenu menu;
    ProgramMenuBar bar;
     
    public sampleClass()
    {
    setTitle("Title");
    panel = new JPanel();
    bar = new ProgramMenuBar();
    menu = new JMenu();
    panel.add(bar);
    bar.add(menu);
    bar.setVisible(true);
    panel.setVisible(true);
    menu.setVisible(true);
    bar.addFileMenu();
    bar.addFileMenuItems(menu);
    bar.addEditMenu();
    bar.addEditMenuItems(menu);
    bar.init();
     
     
    getContentPane.add(panel);
    }
     
    public static void main(String[] args)
    {
    sampleClass referenceVariable = new sampleClass();
    referenceVariable.showGUI();
    }
     
    public void showGUI(){
    		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		setSize(300,300);
    		setLocation(100,100);
    		setVisible(true);
    	} 
    }

    How do I get the parts of the menu to work?

    Last edited by javapenguin; July 31st, 2010 at 08:12 AM.


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

    Default Re: ProgramMenuBar problems

    What is ProgramMenuBar? This isn't part of the standard java library, so I recommend posting its source or library, because without its hard to help debug

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: ProgramMenuBar problems

    Also when posting code, please include all the import statements.

  4. #4
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: ProgramMenuBar problems

    Quote Originally Posted by Norm View Post
    Also when posting code, please include all the import statements.
    Ok, I'm going to edit original post rather than just copy and paste and make a new post.

    ProgramMenuBar is from acm.program.

    The acm.program.ProgramMenuBar Class

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: ProgramMenuBar problems

    If you'll get rid of the acm packages, then more people could help you. Not everyone has those packages.

  6. #6
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: ProgramMenuBar problems

    Well, I have no clue how to make a menu that lets it print. acm will do it, somehow.

    Is there another way...a way that won't involve something very very complex?

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

    Default Re: ProgramMenuBar problems


  8. The Following User Says Thank You to copeg For This Useful Post:

    javapenguin (July 31st, 2010)

  9. #8
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: ProgramMenuBar problems

    ACM also has a save as feature, and, as most practical programs aren't much good if they can't save, I really would like to know how to make that part work.

  10. #9
    Member Darryl.Burke's Avatar
    Join Date
    Mar 2010
    Location
    Madgaon, Goa, India
    Posts
    494
    Thanks
    8
    Thanked 48 Times in 46 Posts

    Default Re: ProgramMenuBar problems

    See #2 and #5

    db

  11. #10
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Question Re: ProgramMenuBar problems

    Quote Originally Posted by Darryl.Burke View Post
    See #2 and #5

    db
    Ok, but what about saving? Is this a FileSaver class or something?

    Also, my print job won't let me print select pages, say pages 1 -10 of a 20 page document. It only lets my do all the pages.

    So tired, biked at least 16 miles.


    Ok, I fixed the printing dilemma but how do you get it to save something, say a bunch of text fields, or a JTable being used as a sort of database, or just a plain regular file? Can you save a file as .exe?

    Also, how may I ask is it possible for a method, not a method call but a method, to be inside the main method, or any other type of method for that matter? I've seen it and sometimes those programs actually compiled for me. I thought you could have inner classes but not inner methods. Did I learn it wrong?

    Also, why does main have to have a String array as a parameter. Why not just a String, or even a String Vector, or some other variable even?

    Is pretty much every class auto-implementing something, just like every class I make automatically extends Object if I don't tell it to extend something else, which by the way, that other class extends Object or is an ancestor. Speaking of which, what is an Ancestor Listener?

    Is it

    a.) A Listener that, say I push a button in window one and it opens window two; I then do something in window two and the Ancestor Listener makes something happen in window one

    b.) A Listener that will use a Listener of a super class or one of it's ancestors

    c.) A Listener that simply tells which Component called it.

    d.) A Listener that shows your family tree

    e.) A Listener that quite seriously has to do with the Java Tree classes.

    f.) A Listener that somehow involves a JOptionPane and it's parent component.

    g.) None of the above

    h.) More than one of the above (please explain)

    Anyway, does it auto-implement something that requires a main, something not required for some reason for JApplets, method.
    Last edited by javapenguin; July 31st, 2010 at 08:55 PM.

  12. #11
    Member Darryl.Burke's Avatar
    Join Date
    Mar 2010
    Location
    Madgaon, Goa, India
    Posts
    494
    Thanks
    8
    Thanked 48 Times in 46 Posts

    Default Re: ProgramMenuBar problems

    Nothing similar about it at all, spammer. Abuse reported on all 11 posts.

    db

Similar Threads

  1. Image problems
    By Bekuraryou1228 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: May 19th, 2010, 05:53 PM
  2. Exercise problems
    By Virgildonatifan in forum Java Theory & Questions
    Replies: 0
    Last Post: February 14th, 2010, 04:12 AM
  3. Problems with If validation
    By websey in forum Loops & Control Statements
    Replies: 1
    Last Post: November 18th, 2009, 09:43 AM
  4. How to compile and run java program?
    By ebalari56 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: September 27th, 2009, 09:33 PM
  5. If you have any .NET problems
    By antony_t in forum The Cafe
    Replies: 1
    Last Post: August 26th, 2009, 10:49 AM