Multiple screens

I have a screen that contains the values ​​that are changed continuously by the users, these values ​​(not all) should be seen on a second screen. does anyone know how to do? sorry but I'm new with processing ..

Answers

  • Did you search the website : I did and got these results one of these might help.

  • I tried, but no one knows how to pass variables from one screen to another .... maybe I did not understand I

  • There are two possibilities

    1) A single application that has two windows (and display each window on a separate screen)

    2) Two applications each with a single window (and each window displayed on a separate screen.

    Is it a desktop application or web application?

    What sort of data is being changed, how much and how frequently?

  • its a desktop application, i have 20 labels with int and doubles that chaning every seconds or milisecons

  • I am assuming that the desktop application -

    (a) has been created by you

    (b) is using a single window for its output

    Is this correct?

    You are going to have to provide more detailed information if you want any chance of getting an answer.

  • thanks for you help!   So I did a program in which I enter a lot of data in the first screen; on the second screen I have to see some of these data, not all. then how do I pass data from a window to the other windows ?? or if you have any idea ??, on the second screen or window do not have to do anything, you should just be able to read.. sorry guys for my bad english

  • Answer ✓

    The following code creates an application that has two windows. If you enter your name in the main window it will be duplicated in the second window. This uses the G4P library.

    Screen Shot 2014-09-07 at 19.13.39

    // Need G4P library
    import g4p_controls.*;
    
    GLabel label1; 
    GTextField txfName; 
    GWindow win1;
    GLabel lblName; 
    
    public void setup() {
      size(320, 160, JAVA2D);
      createGUI();
    }
    
    public void draw() {
      background(230, 230, 255);
    }
    
    // Event handler for the text field
    public void txfName_change(GTextField source, GEvent event) {
      if (event == GEvent.CHANGED) {
        lblName.setText(source.getText());
      }
    }
    
    // Draw method for the second window
    synchronized public void win_draw1(GWinApplet appc, GWinData data) {
      appc.background(230, 255, 230);
    }
    
    
    // Create all the GUI controls. 
    public void createGUI() {
      G4P.messagesEnabled(false);
      G4P.setGlobalColorScheme(GCScheme.BLUE_SCHEME);
      G4P.setCursor(ARROW);
      if (frame != null)
        frame.setTitle("Main Window");
      label1 = new GLabel(this, 10, 10, 300, 20);
      label1.setText("What is your name?");
      label1.setOpaque(true);
      txfName = new GTextField(this, 10, 40, 300, 30, G4P.SCROLLBARS_NONE);
      txfName.setPromptText("Name please");
      txfName.setOpaque(false);
      txfName.addEventHandler(this, "txfName_change");
      win1 = new GWindow(this, "Second Window", 0, 0, 240, 120, false, JAVA2D);
      win1.addDrawHandler(this, "win_draw1");
      lblName = new GLabel(win1.papplet, 10, 10, 220, 20);
      lblName.setOpaque(true);
    }
    
  • o.o thankssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss :D

  • edited September 2014 Answer ✓

    We can also instantiate more than 1 PApplet w/o using any 3rd-party libraries!
    Here's some template that uses 1 main() initializer for 2 PApplet nested classes called MyApp & MyFrame:

    // forum.processing.org/two/discussion/6256/
    // classnotfoundexception-when-extending-papplet
    
    // forum.processing.org/two/discussion/6822/
    // mousepressed-from-another-frame
    
    // forum.processing.org/two/discussion/7036/multiple-screens
    
    static final void main(final String[] args) {
      final String sketch = Thread.currentThread()
        .getStackTrace()[1].getClassName();
    
      final Class[] nested;
      try {
        nested = Class.forName(sketch).getClasses();
      }
      catch (final ClassNotFoundException cause) {
        throw new RuntimeException(cause);
      }
    
      println(nested);
      for (int i = 0, ii = max(0, nested.length-2); i != ii; ++i)  try {
        PApplet.main(nested[i].getName(), args);
      }
      catch (final Exception cause) {
        println(nested[i] + " isn't a PApplet or isn't public static!");
      }
    }
    
    public static final class MyApp extends PApplet {
      void setup() {
        size(300, 200, JAVA2D);
        noLoop();
        println("OK!");
      }
    
      void draw() {
        background(-1);
      }
    }
    
    public static final class MyFrame extends PApplet {
      void setup() {
        noLoop();
        println("Frame!");
      }
    
      void draw() {
        background(0);
      }
    }
    

    As long they're declared public static & extends PApplet, that main() method gonna find them!
    But watch out that any classes which aren't a PApplet be not declared as public though! (~~)

    Notice that each 1 can have their own setup(), draw() and other regular Processing's callbacks.
    And we can declare "global" field variables on the top, which any of those nested class can share access to! *-:)

  • hello, seems a bit old post. I was trying this code but there not any PApplet that open with processing 3. Is it possible to find an update of this undocumented technique ?

  • edited September 2016

    ok I find it myself. but I don't understand why from version 2 you put

    java

    for (int i = 0, ii = max(0, nested.length-2); i != ii; ++i)  try {
      PApplet.main(nested[i].getName(), args);
    }
    

    and in processing 3 I had to remove the "-2"

    for (int i = 0, ii = max(0, nested.length);i != ii; ++i)  try {
      println("tutu");
      PApplet.main(nested[i].getName(), args);
    }
    

    in order to enter in the loop

    for those who search the updated version for processing3

    static final void main(final String[] args) {
      final String sketch = Thread.currentThread()
        .getStackTrace()[1].getClassName();
    
      final Class[] nested;
      try {
        nested = Class.forName(sketch).getClasses();
      }
      catch (final ClassNotFoundException cause) {
        throw new RuntimeException(cause);
      }
    
      println(nested);
    
      for (int i = 0, ii = max(0, nested.length);i != ii; ++i)  try {
        PApplet.main(nested[i].getName(), args);
      }
      catch (final Exception cause) {
        println(nested[i] + " isn't a PApplet or isn't public static!");
      }
    }
    
    public static final class MyApp extends PApplet {
      void setup() {
        //size(300, 200, JAVA2D);
        noLoop();
        println("OK!");
      }
    
      public void settings(){
        size(300,200,"processing.awt.PGraphicsJava2D");
      }
    
      void draw() {
        background(-1);
      }
    }
    
    public static final class MyFrame extends PApplet {
      void setup() {
        noLoop();
        println("Frame!");
      }
    
      void draw() {
        background(0);
      }
    }
    
Sign In or Register to comment.