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

Thread: Popup menu in diffrent class then main Applet, how to repaint()?

  1. #1
    Junior Member
    Join Date
    Oct 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Popup menu in diffrent class then main Applet, how to repaint()?

    In an attempt to better organise my code, I decided to have a main class,
    public class MainClass extends Applet implements MouseListener, MouseMotionListener

    and a second DrawMenu class,
    public class DrawMenu extends PopupMenu implements MouseListener, MouseMotionListener, ActionListener

    And it works perfect, except that after issuing a command in the menu, I need a repaint() in MainClass... ofc I can't create an instance of MainClass in DrawMenu, can't call MainClass.repaint() as it is not static... so I'm kind of stuck. Is there a proper way to do this, or do I have to put them in the same class?


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

    Default Re: Popup menu in diffrent class then main Applet, how to repaint()?

    Pass a reference to your DrawMenu class with your MainClass in the constructor. Then within DrawMenu you can call instance methods from the MainClass reference
    Something like this:
    public class DrawMenu...{
        private MainClass main = null;
        public DrawMenu(MainClass c){
            super();
            this.main = c;
        }
        public void someFunction(){
            //do something
            main.repaint();
        }
    }

Similar Threads

  1. Having trouble printing object information in main class
    By KingLane in forum Object Oriented Programming
    Replies: 1
    Last Post: October 11th, 2009, 06:53 PM
  2. help writeing to a jtextarea from a diffrent class
    By mdstrauss in forum AWT / Java Swing
    Replies: 6
    Last Post: October 6th, 2009, 09:56 AM
  3. Main Class Not Found Problem
    By shadow in forum Java Theory & Questions
    Replies: 3
    Last Post: September 29th, 2009, 09:42 AM
  4. could not find the main class
    By Tisofa in forum Object Oriented Programming
    Replies: 1
    Last Post: September 27th, 2009, 02:58 AM
  5. Problem while implementing a basic user interface menu
    By Rastabot in forum File I/O & Other I/O Streams
    Replies: 3
    Last Post: April 3rd, 2009, 04:38 PM