Embedding PApplet with JFrame/Swing error on JButton
- import java.awt.BorderLayout;
- import javax.swing.JButton;
- import javax.swing.JFrame;
- public class MainClass extends JFrame
- {
-
- EmbeddedProc mEmbed;
- //Button mAButton;
- JButton mAButton;
-
- public MainClass()
- {
- super("Embedded Test");
- setSize(750, 500);
- setDefaultCloseOperation(EXIT_ON_CLOSE);
- setLayout(new BorderLayout());
- mEmbed = new EmbeddedProc();
- add(mEmbed, BorderLayout.CENTER);
- mEmbed.init();
-
- //mAButton = new Button("A Button");
- mAButton = new JButton("A Button");
- add(mAButton, BorderLayout.EAST);
-
- setVisible(true);
- }
- public static void main(String[] args) {
- new MainClass();
- }
- }
- import processing.core.PApplet;
- import java.awt.*;
- public class EmbeddedProc extends PApplet
- {
- public void setup() {
- }
- public void draw() {
- }
- }
Here is the exception:
- Exception in thread "Animation Thread" java.lang.NullPointerException
- at processing.core.PApplet.handleDraw(PApplet.java:2297)
- at processing.core.PGraphicsJava2D.requestDraw(PGraphicsJava2D.java:243)
- at processing.core.PApplet.run(PApplet.java:2140)
- at java.lang.Thread.run(Unknown Source)
As a side note, don't bother stopping by to tell me I should stop using Swing. I know that that opinion exists. I have my reasons for using Swing, and that's not what this thread is about.
UPDATE:
I just found that I can get the exact same error (while using Button) by commenting out the size() function in the program where I came across this problem. However, size() isn't in the test PApplet, and that works fine if JButton is removed, so I'm not sure how related it is. Is this a generic exception?