<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
      <title>Tagged with isassignablefrom() - Processing 2.x and 3.x Forum</title>
      <link>https://forum.processing.org/two/discussions/tagged/feed.rss?Tag=isassignablefrom%28%29</link>
      <pubDate>Sun, 08 Aug 2021 19:44:02 +0000</pubDate>
         <description>Tagged with isassignablefrom() - Processing 2.x and 3.x Forum</description>
   <language>en-CA</language>
   <atom:link href="/two/discussions/taggedisassignablefrom%28%29/feed.rss" rel="self" type="application/rss+xml" />
   <item>
      <title>Sending data over serial</title>
      <link>https://forum.processing.org/two/discussion/24265/sending-data-over-serial</link>
      <pubDate>Tue, 26 Sep 2017 13:41:04 +0000</pubDate>
      <dc:creator>Blad2021</dc:creator>
      <guid isPermaLink="false">24265@/two/discussions</guid>
      <description><![CDATA[<p>Hello all,</p>

<p>I'm working on a program that will be sending a text file to a machine over serial communication.  So far the program looks great however I have not been able to find how to program the application to start and stop bits, and even or odd encoding.  Is this possible to be done using the serial library?  Again this is still a work in progress.</p>

<p>Please advise,
- M</p>

<p>My code so far:</p>

<pre><code>//import processing.serial.*;
import controlP5.*;
import java.io.*;

//Serial myPort;
ControlP5 cp5;
int waitTime = 500;
boolean connectionStatus = false;
String fileName = "textfile.txt";
char endChar = '\n';
boolean stopTrigger = false;
Textarea consoletext;
//Println console;

void setup()
{
  noStroke();
  size(800, 520);
  cp5 = new ControlP5(this);
  cp5.enableShortcuts();

  cp5.addTextlabel("title")
    .setText("Monarch Interface Application")
    .setPosition(10, 10)
    .setFont(createFont("Arial", 22))
    .setColor(color(255, 255, 250, 255))
    ;
  cp5.addButton("stopButton")
    .setSize(90, 50)
    .setFont(createFont("arial", 22))
    .setCaptionLabel("STOP")
    .setPosition(20, 70)
    ;
  cp5.addButton("sendButton")
    .setFont(createFont("arial", 22))
    .setSize(90, 50)
    .setCaptionLabel("SEND")
    .setPosition(20, 140)
    ;

  cp5.addTextfield("waitTimeInput")
    .setId(6)
    .setPosition(20, 420)
    .setSize(200, 35)
    .setFont(createFont("arial", 20))
    .setAutoClear(false)
    .setCaptionLabel("Wait per Line")
    .setText(Integer.toString(waitTime))
    ;
  cp5.addTextfield("fileNameInput")
    .setId(6)
    .setPosition(20, 340)
    .setSize(200, 35)
    .setFont(createFont("arial", 20))
    .setAutoClear(false)
    .setCaptionLabel("Filename")
    .setText(fileName)
    ;
  cp5.addTextlabel("statusLabel")
    .setText("Status:")
    .setPosition(20, 220)
    .setFont(createFont("Arial", 20))
    .setColor(color(255, 255, 250, 255))
    ;
  cp5.addTextlabel("statusLabelb")
    .setText("DISCONNECTED")
    .setPosition(55, 255)
    .setFont(createFont("Arial", 20))
    .setColor(color(255, 255, 250, 255))
    ;
  cp5.addTextlabel("ctext")
    .setText("Console | Serial Injection")
    .setPosition(365, 3)
    .setColor(color(200, 0, 0, 255))
    .setFont(createFont("Arial", 18))
    ;
  consoletext = cp5.addTextarea("txt")
    .setPosition(370, 30)
    .setSize(420, 480)
    .setFont(createFont("", 12))
    .setLineHeight(14)
    .setColor(color(255, 255, 255, 255))
    .setColorBackground(color(100, 100))
    .setColorForeground(color(255, 100))

    ;

  //console = cp5.addConsole(consoletext);
  println("SYSTEM: GUI Loaded");
}

void draw()
{
  background(0);
  fill(255);
}

public void sendButton() {
  stopTrigger = false;
  sendCode();
}
public void stopButton() {
  stopTrigger = true;
}


void sendCode() {
  try {
    FileInputStream fstream = new FileInputStream(sketchPath(fileName));

    DataInputStream in = new DataInputStream(fstream);
    BufferedReader br = new BufferedReader(new InputStreamReader(in));

    String strLine;
    while (((strLine = br.readLine()) != null) &amp;&amp; (stopTrigger != true)){
      //myPort.write(strLine +endChar);
      println("Sent: " +strLine);
      //delay(waitTime);
      Thread.sleep(waitTime);
    }
    in.close();
  }
  catch(Exception e) {
    println("SYSTEM ERROR:");
    println(e.getMessage());
    System.err.println("Error: " +e.getMessage());
  }
}

void controlEvent(ControlEvent event) {
  if (event.isAssignableFrom(Textfield.class)) {
    if ("waitTimeInput".equals(event.getName())) {
      waitTime = Integer.parseInt(event.getStringValue());
      println("*   Wait Time Updated: " +waitTime);
    }
    if ("fileNameInput".equals(event.getName())) {
      fileName = event.getStringValue();
      if (fileName.endsWith(".txt")) {
        println("*   Filename Updated: " +fileName);
      } else {
        fileName = fileName += ".txt";
        println("*   Filename Updated: " +fileName);
      }
    }
  }
} //End of controlEvent
</code></pre>
]]></description>
   </item>
   <item>
      <title>[Eclipse] Use PApplet methods (e.g. 'fill()') in another class</title>
      <link>https://forum.processing.org/two/discussion/21596/eclipse-use-papplet-methods-e-g-fill-in-another-class</link>
      <pubDate>Fri, 24 Mar 2017 22:49:48 +0000</pubDate>
      <dc:creator>TPRammus</dc:creator>
      <guid isPermaLink="false">21596@/two/discussions</guid>
      <description><![CDATA[<p>Hey!
I am still pretty unexperienced with classes and everything so I would like to know why I cant call methods like ellipse() or fill() in a class other then 'UsingProcessing' (I did everything like in <a rel="nofollow" href="https://processing.org/tutorials/eclipse/"><strong>this</strong></a> tutorial explained).</p>

<blockquote class="Quote">
  <p>The method ellipse() is undefined for the type TestClass</p>
</blockquote>

<p>I first thought like I need to <strong>import processing.core.PApplet;</strong> but that doesn't seem to work for me :/</p>

<p>regards, TPRammus</p>

<p>EDIT:
Thanks to the answers, I edited my code.
Now I fist pass "this" to a static (PApplet) variable "PA" in my class. 
And I can use "PA" like this: 
<strong>PA.ellipse(1, 2, 3, 4);</strong></p>
]]></description>
   </item>
   <item>
      <title>Need a better way of creating a list of text field objects</title>
      <link>https://forum.processing.org/two/discussion/20249/need-a-better-way-of-creating-a-list-of-text-field-objects</link>
      <pubDate>Fri, 13 Jan 2017 23:40:37 +0000</pubDate>
      <dc:creator>deano</dc:creator>
      <guid isPermaLink="false">20249@/two/discussions</guid>
      <description><![CDATA[<p>Hi there,</p>

<p>Have constructed a bit of code that creates say 5 text fields along with corresponding submit buttons.</p>

<p>Have managed this with For Loops. Is there a more elegant way to do this?</p>

<p>I feel my code can be improved as it would be very cumbersome to keep copy-pasting and changing the relative numbers especially for the submit() function. The overall code would take up too much space.</p>

<p>Can the submit function reside within a for loop as well?</p>

<p>Would love to hear some ideas so that I can take it forward. Thanks!</p>

<p>Here is the code I'm using:</p>

<pre><code>import controlP5.*;

ControlP5 cp5;

// Should we do an array for this initialization?
// I don't want to type out say 30 textValues. What is the more elegant way to represent this?
// Arrays.fill()??

String textValue_1 = "";
String textValue_2 = "";
String textValue_3 = "";
String textValue_4 = "";
String textValue_5 = "";

void setup() {
  size(800, 1000);
  cp5 = new ControlP5(this);

  for (int i = 1; i &lt; 6; ++i) {
    cp5.addTextfield("textValue" + "_" + i)
      .setPosition(20, 80*i)
        .setSize(200, 40)
          .setFont(createFont("arial", 20))
            .setCaptionLabel("Enter Text for field " + i)
              .setAutoClear(false)
                ;

    cp5.addButton("submit"+ "_" + i)
      .setPosition(240, 80*i)
        .setSize(80, 40)
          .setCaptionLabel("submit")
            .getCaptionLabel().align(ControlP5.CENTER, ControlP5.CENTER)
              ;
  }
} 

void draw() {
  background(0);
}

// The function for submit... can this be done in a for loop?
// I may want a large number of text fields
// and it can get tedious typing it all out every time I change the number


public void submit_1() {
  cp5.get(Textfield.class, "textValue_1").submit();
}

public void submit_2() {
  cp5.get(Textfield.class, "textValue_2").submit();
}

public void submit_3() {
  cp5.get(Textfield.class, "textValue_3").submit();
}

public void submit_4() {
  cp5.get(Textfield.class, "textValue_4").submit();
}

public void submit_5() {
  cp5.get(Textfield.class, "textValue_5").submit();
}


void controlEvent(ControlEvent theEvent) {
  if (theEvent.isAssignableFrom(Textfield.class)) {
    println("controlEvent: accessing a string from controller '"
      +theEvent.getName()+"': "
      +theEvent.getStringValue()
      );
  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Inheritance</title>
      <link>https://forum.processing.org/two/discussion/18736/inheritance</link>
      <pubDate>Wed, 26 Oct 2016 20:17:58 +0000</pubDate>
      <dc:creator>poisson86</dc:creator>
      <guid isPermaLink="false">18736@/two/discussions</guid>
      <description><![CDATA[<p>So I have a problem with a code when I compile it, it says <code>implicit super constructor Entity() is undefined for default constructor. Must define an explicit constructor</code>  <a href="https://paste2.org/ty3zUmxx" target="_blank" rel="nofollow">https://paste2.org/ty3zUmxx</a>  (the class Entity is abstract)</p>
]]></description>
   </item>
   <item>
      <title>check sub class with instanceof</title>
      <link>https://forum.processing.org/two/discussion/17645/check-sub-class-with-instanceof</link>
      <pubDate>Mon, 25 Jul 2016 20:58:06 +0000</pubDate>
      <dc:creator>Stanlepunk</dc:creator>
      <guid isPermaLink="false">17645@/two/discussions</guid>
      <description><![CDATA[<p>I try this code to check if my class match with the subclass, but Processing say no, because my Class array is null or invalid I don't know :</p>

<pre><code>void setup() {
  // if a class is an instance of creating class
   Child_1 c = new Child_1() ;

   for(int i = 0 ; i &lt; child_class(this, "Mother").length ; i++) {
    if(c instanceof child_class(this, "Mother")[i] ) println(i, "yes") ;
   }
}

Class [] child_class(PApplet parent, String super_class_name) {
  Class[] c = parent.getClass().getDeclaredClasses();
  c = new Class[c.length -1] ;
  return c ;
}

class Mother {
  Mother() {}
}

class Child_1 extends Mother {
  Child_1 () {}
}

class Child_2 extends Mother {
  Child_2 () {}
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>ControlP5 Icon Class - Switch mode does not call controlEvent function</title>
      <link>https://forum.processing.org/two/discussion/15506/controlp5-icon-class-switch-mode-does-not-call-controlevent-function</link>
      <pubDate>Tue, 15 Mar 2016 13:46:57 +0000</pubDate>
      <dc:creator>Bluefarmer</dc:creator>
      <guid isPermaLink="false">15506@/two/discussions</guid>
      <description><![CDATA[<p>So I'm working with controlP5 and the Icon class which works great except when I turn on "setSwitch(true)". The moment I add this line of code it does not reach the controlEvent function anymore. I've solved it before by checking isPressed on the specific controller and then setting things with iconObject.isOn(), but I've got quite a few more buttons now so I'd love to be able to use the controlEvent function.</p>

<p>Has anyone encountered or fixed this before?</p>

<p>Thanks</p>
]]></description>
   </item>
   <item>
      <title>How to lock a textfield after it receives an input? (ControlP5)</title>
      <link>https://forum.processing.org/two/discussion/14629/how-to-lock-a-textfield-after-it-receives-an-input-controlp5</link>
      <pubDate>Tue, 26 Jan 2016 21:28:27 +0000</pubDate>
      <dc:creator>luisandresgonzalez</dc:creator>
      <guid isPermaLink="false">14629@/two/discussions</guid>
      <description><![CDATA[<p>I want the textfield to block once it receives a value.</p>

<p>I've seen there is a Textfield lock() method but I don't know how to use it.</p>

<pre>

import controlP5.*;

ControlP5 cp5;



color ccolor=color(250, random(100), random(100));

void setup() {
  size(700,400);
  
  PFont font = createFont("arial",20);
  
  cp5 = new ControlP5(this);
  
  cp5.addTextfield("Subject number")
     .setPosition(20,170)
     .setSize(200,40)
     .setFont(createFont("arial",20))
     .setAutoClear(true)
     .setColorLabel(ccolor);
     ;
       
  cp5.addBang("OK")
     .setPosition(240,170)
     .setSize(40,40)
     .getCaptionLabel().align(ControlP5.CENTER, ControlP5.CENTER)
     ;      
     
  textFont(font);
}

void draw() {
  background(0);
  fill(255);
  
}



void controlEvent(ControlEvent theEvent) {
  if(theEvent.isAssignableFrom(Textfield.class)) {
    println("controlEvent: accessing a string from controller '"
            +theEvent.getName()+"': "
            +theEvent.getStringValue()
            );
  }
}
</pre>
]]></description>
   </item>
   <item>
      <title>Multiple windows with Processing 3 ? ? ?</title>
      <link>https://forum.processing.org/two/discussion/12272/multiple-windows-with-processing-3</link>
      <pubDate>Thu, 27 Aug 2015 17:34:26 +0000</pubDate>
      <dc:creator>quark</dc:creator>
      <guid isPermaLink="false">12272@/two/discussions</guid>
      <description><![CDATA[<p>I hope to be able to update G4P for Processing 3. One of the key features of G4P was the ability to create apps with multiple windows. This was straightforward with PS2 because Applet inherited from PApplet, a windowed component.</p>

<p>I have been looking through PS source code but I have not found an obvious way of doing this.</p>

<p>Any hints or ideas gratefully received.</p>

<p>Thanks</p>
]]></description>
   </item>
   </channel>
</rss>