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

Thread: PApplet question

  1. #1
    Junior Member
    Join Date
    Aug 2011
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default PApplet question

    Hello, in this example I have two applets which I'm running as a Java Application. This might sound silly but how can I close one of the windows so that the other one remains open? because every time I close it my program just ends.

    Normally, if I were using an ordinary frame I would write "myFrame.setVisible(false);" but I don't know how to do that with applets. On the PApplet webpage it says that 'set'Visible()' is inherited from java.awt.Component. Problem is, I just don't know how to call the setVisible method from an applet.

    Thanks for your help.

     
    import processing.core.PApplet;
     
    public class Class1 extends PApplet {
     
        public void setup() {
            size(200, 200);
            background(0);
        }
     
        public void draw() {
     
        }
     
        public static void main(final String[] args) {
            PApplet.main(new String[]{"Class1"});
            PApplet.main(new String[]{"Class2"});
        }
    }
     
    import processing.core.PApplet;
     
    public class Class2 extends PApplet{
     
        public void setup() {
            size(400, 400);
            background(0);
        }
     
        public void draw() {
     
        }
     
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: PApplet question

    No idea what the PApplet class does. You will have to read its API doc to see how to use it.
    In java, an applet extends the Applet class which looks like it is not related to the PApplet class.
    An applet runs in a browser, not as an application.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Aug 2011
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: PApplet question

    Quote Originally Posted by Norm View Post
    No idea what the PApplet class does. You will have to read its API doc to see how to use it.
    In java, an applet extends the Applet class which looks like it is not related to the PApplet class.
    An applet runs in a browser, not as an application.
    Thanks, I've asked around in several forums and it seems nobody knows the PApplet class.

  4. #4
    Forum Squatter newbie's Avatar
    Join Date
    Nov 2010
    Location
    North Wales
    Posts
    661
    My Mood
    Stressed
    Thanks
    28
    Thanked 115 Times in 106 Posts
    Blog Entries
    1

    Default Re: PApplet question

    If I recall, PApplet has a public member called frame which you can access, failing that, it might have a getFrame method.
    All this is off the top of my head though.
    Please use [highlight=Java]//code goes here...[/highlight] tags when posting your code

  5. #5
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: PApplet question

    PApplet is used by Processing, and it extends java.awt.Frame. If you're running this from Java (as opposed to from Processing itself), you should just be able to call setVisible(). That method is indeed inherited from Component, but it's overriden by Frame. Frame extends Window, which extends Container, which extends Component.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  6. #6
    Member
    Join Date
    Feb 2012
    Posts
    58
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Default Re: PApplet question

    Quote Originally Posted by knightmetal View Post

    Normally, if I were using an ordinary frame I would write "myFrame.setVisible(false);" but I don't know how to do that with applets. On the PApplet webpage it says that 'set'Visible()' is inherited from java.awt.Component. Problem is, I just don't know how to call the setVisible method from an applet.
    Have you tried the following?

    super.setVisible(false);

  7. #7
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: PApplet question

    You shouldn't even have to call super.setVisible(). Like I said, simply calling setVisible() should do the trick.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!