G4P in extended Applet

Hello guys,

I have a problem when trying to use the objects of G4P library in an extended Applet. In the example I have two programs, the first one is the menu, the G4P events normally run. But on the second program, G4P objects appear, but can not trigger events (eg Click event)...

Below is the code (only left some things to try to simplify the example)...

//First Program

//Importa Bibliotecas
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.awt.*;
import java.io.File;
import g4p_controls.*;

GWindow wndManual;
GButton btnOpcao01, btnOpcao02;

//Constantes
static final String UNIDADE           = "D:";
static final String PATHIMGPACIENTES  = UNIDADE + "/Projetos/Dados/ImgPacientes";
static final String PATHIMGMENUVIDEOS = UNIDADE + "/Projetos/Dados/ImgMenuVideos";

//Variáveis Globais
static int idPessoa = 0;
static int posBtnX, posBtnY;
static boolean pressMouse = false;
static PFont fontA;  //Define fonte padrão para o Projeto

static String nomePessoa;

void setup(){
  size(800, 600, JAVA2D);
  frame.setTitle("C.A.L. Anima ADM - Manutenção de Imagens para Link de Vídeos/Histórias");

  //Define fonte para o Texto e seta cor
  fontA = loadFont("BuxtonSketch-48.vlw");   

  btnOpcao01 = new GButton(this, 50, 100, 120, 30, "Cadastrar Link Vídeos");
  btnOpcao02 = new GButton(this, 50, 160, 120, 30, "Cadastrar Link Histórias");
}


void draw(){
  background(#F3F0F7);
  textFont(fontA, 40);
  fill(#1273C1);

  text("Menu Opção Cadastros", 10, 40);
}

void handleButtonEvents( GButton button, GEvent event) {
  if ( event == GEvent.CLICKED){
    if (button == btnOpcao01){ 
      PApplet calAnimaCad01 = new CalAnimaCad01();
      runSketch(new String[] { "Cadastros" }, calAnimaCad01);

      //wndManual = new GWindow(this, "Manual Control", 0, 0, 300, 300, false, JAVA2D);
      //btnOpcao03 = new GButton (wndManual.papplet, 0, 0, 120, 30, "Release");
      //wndManual.addDrawHandler(this, "wndManualDraw");
      //wndManual.setOnTop(false);
      //btnManual.setEnabled(false);
    } else if (button == btnOpcao02){ 
      println("Não disponível - Em Desenvolvimento!");
    }
  } 
}

//Second Program

public class CalAnimaCad01 extends PApplet {
  //public static class CalAnimaADM extends PApplet {
  /*-----------------------------
    Tela de Manutenção
  -------------------------------*/

  //Declara Objetos
  GDropList dplPacientes;
  GLabel lblPaciente,  lblImagem;
  GButton btnCapturaIMG, btnCapturaURL, btnSalvarXML;

  //Variáveis
  int opcaoIMG = 0;

  String[] itens;
  String[] lines;
  String pastedMessage;

  PImage imgPaciente;
  PImage pastedImage;

  //Configurações Iniciais
  void setup(){
    size(800, 600, JAVA2D);
    frame.setTitle("C.A.L. Anima ADM - Manutenção de Imagens para Link de Vídeos"); //Título da aplicação na 

Janela do Windows

    criaObjetos(); //Cria objetos tela ( GUI )
  }

  //Loop enquanto rodar o programa
  void draw(){
    background(#F3F0F7);
    fill(255);

    //Área da Foto
    stroke(0);
    rect(width-135, 10, 103, 121);

    //Área da Imagem
    noStroke();
    rect(10, 65, 640, 510);

    //Exibe imagem do Paciente
    if (imgPaciente != null)
      image(imgPaciente, width-134, 11);

    //Exibe url capturada
    if (pastedImage != null){
      image(pastedImage, 10, 70);
    }
  }

  //Evento de Teclado
  void keyPressed(){
    //if (key == 0x16){ // Ctrl+v
      //pastedMessage = GetTextFromClipboard();
      //pastedImage   = GetImageFromClipboard();
    //}
  }

  //Evento acionado ao Selecionar Item no Combo Box ( ou List Box )
  void handleDropListEvents(GDropList list, GEvent event) { 
    println("Evento List Acionado...");
    if (list == dplPacientes) {
      idPessoa   = int(list.getSelectedText().substring(0, 4));
      nomePessoa = list.getSelectedText();
      //println("Item: "+ dplPacientes.getSelectedIndex() + " - Texto: " + list.getSelectedText());
      println("OK, Codigo/Nome: " + idPessoa + " - " + nomePessoa); 
    }
  }

  //Evento acionado ao Clicar em um Botão
  void handleButtonEvents(GButton button, GEvent event) {
    //if (button == btn01 && event == GEvent.CLICKED) {
    println("Evento Button Acionado...");
    if ( event == GEvent.CLICKED){
      if (button == btnCapturaIMG){  
        println("OK, evento Botão Acionado");
      }
    }
  }

  //Cria objetos Gráficos para montar tela
  void criaObjetos() {
    lblPaciente = new GLabel(this, 10, 5, 560, 20, "Pacientes:");
    lblPaciente.setFont(new Font("Arial", Font.PLAIN, 18));
    lblPaciente.setTextAlign(GAlign.LEFT, null);

    lblImagem = new GLabel(this, 10, 45, 560, 20, "Imagem:");
    lblImagem.setFont(new Font("Arial", Font.PLAIN, 12));
    lblImagem.setTextAlign(GAlign.LEFT, null);

    btnCapturaIMG = new GButton(this, width-140, 140, 120, 30, "Capturar Imagem Vídeo");
    btnCapturaURL = new GButton(this, width-140, 180, 120, 30, "Capturar URL Vídeo");
    btnSalvarXML  = new GButton(this, width-140, 220, 120, 30, "Salvar");

    //Cria Array com registros do pacientes, para usar no Combo
    itens = new String[] {"Selecione um Paciente", "1 - Paciente 1", "2 - Paciente 2", "3 - Paciente 3", "9 

- Paciente Teste"}; 

    //ComboBox - Lista com Nomes
    dplPacientes = new GDropList(this, 10, 27, width-165, 100, 5);
    dplPacientes.setItems(itens, 0);
    dplPacientes.setFont(new Font("Arial", Font.PLAIN, 14)); 
  }
}

Could anyone give some hints? How do I fix this?

Thank you,

Answers

  • Which version of G4P and Processing are you using

  • You appear to be using Processing 2 and probably G4P 3.5.4

    I would recommend using the GWindow class rather than trying to create your own class.

    In the sketch code below (acut down version of what you posted) a second window will open when you click on the button. If you then click on the button in the second window then a message will appear in the console showing that the event was detected.

    //Importa Bibliotecas
    import g4p_controls.*;
    
    GWindow wndManual;
    GButton btnOpcao01, btnOpcao03;
    
    //Constantes
    static final String UNIDADE           = "D:";
    static final String PATHIMGPACIENTES  = UNIDADE + "/Projetos/Dados/ImgPacientes";
    static final String PATHIMGMENUVIDEOS = UNIDADE + "/Projetos/Dados/ImgMenuVideos";
    
    //Variáveis Globais
    static int idPessoa = 0;
    static int posBtnX, posBtnY;
    static boolean pressMouse = false;
    static PFont fontA;  //Define fonte padrão para o Projeto
    
    static String nomePessoa;
    
    void setup() {
      size(800, 600, JAVA2D);
      frame.setTitle("C.A.L. Anima ADM - Manutenção de Imagens para Link de Vídeos/Histórias");
      btnOpcao01 = new GButton(this, 50, 100, 120, 30, "Cadastrar Link Vídeos");
    }
    
    void draw() {
      background(#F3F0F7);
      textSize(40);
      fill(#1273C1);
    
      text("Menu Opção Cadastros", 10, 40);
    }
    
    void handleButtonEvents( GButton button, GEvent event) {
      if ( event == GEvent.CLICKED) {
        if (button == btnOpcao01 && wndManual == null) { 
          wndManual = new GWindow(this, "Manual Control", 0, 0, 300, 300, false, JAVA2D);
          btnOpcao03 = new GButton (wndManual.papplet, 0, 0, 120, 30, "Release");
          wndManual.addDrawHandler(this, "wndManualDraw");
          wndManual.setOnTop(false);
        } 
        if (button == btnOpcao03) {
          println("Button pressaed at " + millis());
        }
      }
    }
    
  • Hello Peter, thanks for the feedback.

    I understood how to do, I will adapt my need here ... in this case the progrma is much smaller, it is "cleaner" ...

    A doubt as would be the case, in draw() of the second window is independent? For example, in addition to events such as Click, each screen is different, would the code in one place (draw() the first window)?

    Note: I'm using 2.2.1 Processing, how do you see what G4P version that is installed?

    One more detail please ... how to close only the second open window?

    As it stands, does not close with (x), and closing the first window, closes all ...

    I could control the closing of the second window with the ESC key?

    Thanks for attention,

  • When you run a sketch with uses G4P its version is shown in the console window..


    By default the red-cross close icon is ignored. To change that use

    wndManual.setActionOnClose(G4P.CLOSE_WINDOW);

    after you have created the window i.e. after line 37


    The line

    wndManual.addDrawHandler(this, "wndManualDraw");

    specifies the function responsible for drawing to the second window. So you need to add this method to my sketch code above.

    public void wndManualDraw(GWinApplet appc, GWinData data) {
      appc.background(230);
    }
    

    This is equivalent to the draw() method for the first window but drawing commands MUST be prefixed with appc.


    Note that all development work for PS2 versions of my tools / libraries has stopped because I have released PS3 versions and I will be concentrating on them.

  • Hello Peter, thank you for clarification ...

    The version was lack of attention even, sorry ...

    Now, abusing a little (laughs), you imagine that I have several windows, ie several programs, as would be specific to each program for Mouse and keyboard events?

    For example, in a program have a control on mouseMove (), on the other, this control in other programa, is different ... the same thing could happen in keyPressed () ...

    I saw for example in the case of Mouse, which can be controlled from a single point, but I wish I could do this in separate programs, with calls from the Home Menu for various programs.

    void handleButtonEvents( GButton button, GEvent event) {
      if ( event == GEvent.CLICKED) {
         ...
      }
    }
    

    Sorry so many questions, is that it took me a while to get organize a project that I'm working from the menu, we use several programs, possibly I may need to use the G4P library, and in this case are in "tabs" or separate programs.

    I could not really use the independently (extend Applet)? to have these facilities to separate the code for the program?

    Below is a print, to get an idea of how the project is going, and how said eventually I need to use the G4P library, as well as other ...

    Most are adapted models obtained in OpenProcessing and other sources, and also with the help here in the forum Processing ...

    Tela02 Tela03

    Thank you very much for your attention, it has helped a lot ...

  • I forgot to tell you the version I'm using ...

    is G4P V3.5.3

  • In the pictures it looks like you have a number of 'icons' do these represent images and videos?

  • Yes, I used GP4 for the therapist to register the menu of each patient, so even though limited by the moves, they can use the computer with the help of LeapMotion, Kinect Camera, etc ...

    I'll put some prints, to get a better idea of how it's getting (is not all set), we are developing ...

  • As I said, below is a sequence of images, trying to get a better idea of how the project where a person who can not use the mouse or keyboard, you can access certain features with devices that spoke ...

    the Click fires automatically like "xbox"... (We made with controlP5 ...) sorry (laughs) I found it easier to use the controls that libraries offer ... as well as more intituitiva Maintenance screen of entries with G4P, I'm combining the two libraries, that work very well by the way ...

    Tela04 Tela05 Tela06 Tela07 Tela08

    We are now developing a part, to "tell" illustrated stories, which through images will riding the sequence of the story ...

  • edited October 2015

    therapist to register the menu of each patient,

    Are the patients physically impaired?

    Does the menu of each patient a list of sketches for the patients to use?

  • That's right, they are deficient, ranging including the many type of disability ... use a wheelchair and can move with some difficulty the other hand ... already has more limited movement yet, so we use a webcam (with a hadMouse software) ... that works well too ...

    The Truth with 3 or 4 programs I could help lot form the independent menu for each patient (to access videos).

    But we have other options, trying to use animations, and now we also try adpatar stories ... so that they themselves can put together with the help of the therapist ...

    Animations is where most programs have a number ... I sometimes I collate sequence in the same draft ... but lay elsewhere when are different ... and the idea is that we will always adding more, to always have novelty in the project ...

  • Hello,

    Someone tell if a problem is occurring some problem in the Processing forum? I was unable to access for a few days ... thought some access problem here in the company, but now returned to normal.

    Thank you,

Sign In or Register to comment.