Trigger a PApplet with a JButton event
in
Integration and Hardware
•
2 years ago
Hello, fellas! I'm trying to write a new app to export video from a bunch of PNG images using P5 as the video export engine.
This is how it should work:
Using NetBeans, I'll creat a simple UI with a browse folders function to look for a path in my HDD and a "Render Video" button. when clicked, the Button will create and execute a PApplet that exports the video to a RAW video Stream.
However to where my first basic attempts have gone, I've been able to implement the UI and the companion class (extends PApplet), but my button triggers errors everytime I try to make the companion class run. This is the error message I get every time:
Exception in thread "AWT-EventQueue-0" java.lang.RuntimeException: java.lang.ClassNotFoundException: PAppletRenderer So here is the code for both the Main Class and the Renderer: The
Main CLass
the Renderer Class
This is how it should work:
Using NetBeans, I'll creat a simple UI with a browse folders function to look for a path in my HDD and a "Render Video" button. when clicked, the Button will create and execute a PApplet that exports the video to a RAW video Stream.
However to where my first basic attempts have gone, I've been able to implement the UI and the companion class (extends PApplet), but my button triggers errors everytime I try to make the companion class run. This is the error message I get every time:
Exception in thread "AWT-EventQueue-0" java.lang.RuntimeException: java.lang.ClassNotFoundException: PAppletRenderer So here is the code for both the Main Class and the Renderer: The
Main CLass
package tooraw;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class TooRawMain extends JPanel implements ActionListener {
protected JButton renderButton;
public TooRawMain() {
renderButton = new JButton("Render");
renderButton.setText("Render");
renderButton.setToolTipText("Render the Selected Path as Raw Stream.");
renderButton.setActionCommand("render");
renderButton.addActionListener( this );
add( renderButton );
}
public static void createAndShowGUI() {
JFrame frame = new JFrame( "Main Frame" );
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
TooRawMain pane = new TooRawMain();
pane.setOpaque(true);
frame.setContentPane( pane );
frame.pack();
frame.setVisible(true);
}
public void actionPerformed(ActionEvent ae) {
if ( "render".equals( ae.getActionCommand() ) ) {
System.out.println("render command received");
renderButton.setText("doing");
PAppletRenderer.main( new String[] { "PAppletRenderer" } );
} else {
// do nothing
}
}
public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
}
the Renderer Class
package tooraw;
import processing.core.PApplet;
public class PAppletRenderer extends PApplet {
public String thePath;
public PAppletRenderer( String path ) {
thePath = path;
}
@Override public void setup() {
System.out.println("running setup!");
size( 200,200 );
smooth();
}
@Override public void draw() {
System.out.println("running draw!");
background( 255, 10 );
rect( 20,20,160,160 );
text( thePath,10,10 );
}
public static void main(String args[]) {
PApplet.main(new String[] { "PAppletRenderer" });
}
}
I just want to know if what I'm trying to do is actually doable or not, and if it is doable, what am I doing wrong? Thanks for your answers :)
1