Quantcast
Channel: Library Questions - Processing 2.x and 3.x Forum
Viewing all articles
Browse latest Browse all 2896

G4P in extended Applet

$
0
0

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,


Viewing all articles
Browse latest Browse all 2896

Trending Articles