Java processing applet not running - java

When I try to run my java code for processing it shows an error "selection does not contain applet". This is how I am supposed to run my code.
Here is my code:
package proccesing;
import processing.core.*;
public class proccesing extends PApplet {
public void setup() {
background(100,100);
}
public void draw() {
line(0,0,0,100);
}
}

As of Processing 3, PApplet no longer extends Applet. In other words, you can't deploy as an applet anymore.
You could try using the Applet exporting tool, but you're much better off using Processing.js to deploy as JavaScript. Applets are pretty much dead and shouldn't really be used anymore.

Related

Eclipse not having run as java applet application

I setup my eclipse for PROCESSING perfectely..
I am using Eclipse Oxygen and installed PROCESSING 3.3.6
i am trying to run processing program in eclipse and there is no option is run as Applet
My code is below :
package processing01;
import processing.core.PApplet;
public class Processing01 extends PApplet{
public static void main(String[] args) {
PApplet.main("Processing01");
}
public void settings(){
size(300,300);
}
public void setup(){
fill(120,50,240);
}
public void draw(){
ellipse(width/2,height/2,second(),second());
}
}
Processing 3 no longer supports running as an applet. From the Processing 3 change list:
Applet is gone — Java's java.awt.Applet is no longer the base class used by PApplet, so any sketches that make use of Applet-specific methods (or assume that a PApplet is a Java AWT Component object) will need to be rewritten.
The PApplet class no longer extends the Applet class, which means you can't treat Processing sketches as a component anymore, and you can't run them as an applet. You can only run them as an application.
Applets are dead, and shouldn't be used anyway.
Because having package the code would be
//replace
PApplet.main("Processing01");
//with
PApplet.main("processing01.Processing01");

Need help setting up intellij java project with multiple .java files from scratch

Edited to restart question from scratch due to complaints. I am a newbie to this format and to intellij so please excuse...
I am building a project in intellij for class. This project imports jnetcap and uses it to process a captured pcap file. My issue is I have two class files I am trying to integrate. NetTraffic which is the user interface class, and ProcessPacket that actually reads in the packet and does the work.
I have tried to make a project and import ProcessPacket into NetPacket but have been unsuccessful so far. I am sure I am missing something simple in this process but I just can not find anything showing the proper way to do this.
I have gotten it working by making a package under the src directory and adding both files to that package. This doesn't require an import from the NetPacket class and seems to work but my worry is that I need to be able to run this from a linux command line. I have been working all semester so far with everything in one source file so it hasn't been an issue until now. I don't remember using packages in the past under eclipse to do this.
Can someone offer a step by step process on how to properly add these source files to my project so that I am able to import ProcessPacket into NetTraffic or will leaving like this in a package work fine?
The files in question reside in package named nettraffic in src directory.
NetTraffic.java
package nettraffic;
public class NetTraffic {
public static ProcessPacket pp;
public static void main (String args[]) {
pp = new ProcessPacket();
pp.PrintOut();
}
}
ProcessPacket.java
package nettraffic;
import org.jnetpcap.*;
public class ProcessPacket {
public ProcessPacket() {
}
public void PrintOut() {
System.out.println("Test");
}
}
Note there is no real functionality in these at this time. Just trying to get the class import syntax correct before continuing. Again while this seems to work as a package I want to have it done without using a package and importing ProcessPacket.java into NetTraffic.java.
public class NetTraffic {
ProcessPacket pp = new ProcessPacket();
pp.PrintOut();
}
You're calling the PrintOut() method outside of any constructor or method or similar block (static or non-static initializer blocks...), and this isn't legal. Put it in a constructor or method.
public class NetTraffic {
public NetTraffic() {
ProcessPacket pp = new ProcessPacket();
pp.PrintOut();
}
}

How do I use IKVM from IronPython?

Let's say I'm writing an app in IronPython and I'd like to use some classes stored in a Java jar (which I don't control and I'd rather not wrap in a DLL).
I downloaded IKVM and tested that command line tools work fine.
Let's say the class I'd like to access is like this:
package some.thing;
class Hello {
public static void myMethod(String arg){
System.out.println("you got me!");
}
}
Which DLLs should I import from IronPython in order to be able to then call Hello.myMethod('a')?
Is this possible at all with IKVM? If not, is there any other way you can see to make this work?

java.lang.reflect.invocationtargetexception in browser

I made this little java code that runs notepad:
import java.io.IOException;
public class pad {
public static void main(String[] args) throws IOException, InterruptedException {
execute();
}
private static void execute() throws IOException, InterruptedException {
Process exec = Runtime.getRuntime().exec("notepad.exe");
exec.waitFor();
}
}
The code works fine before and after building into a .jar file, however when running from an html page it gives me a java.lang.reflect.invocationtargetexception error, here is the html source:
<applet code="pad.class"
archive="not.jar"
width=400 height=400>
</applet>
Please note that I am still new to Java, thanks for your help.
In order to run your code in a web browser, the pad class needs to extend Applet class (or if you use Swing - JApplet).
The first thing you need to know, is that applets are not started using the main(String[]) method - they have a lifecycle methods like init(), start(), etc.
There is a good tutorial on Applets on Oracle site, I strongly suggest you check it out.

NoClassDefFoundError in Java Applet on invokeLater()

I have an applet I've built using NetBeans, called AKApplet. It runs fine in the IDE, but when I put it in a web page it throws the following error:
Exception in thread "Thread-15" java.lang.NoClassDefFoundError: AKApplet$2
at AKApplet.run(AKApplet.java:675)
The applet uses the run() method to load some data in the background while keeping the UI responsive. Pretty standard stuff. At line 675, after the data has been loaded, I'm trying to update the UI components using invokeLater():
public void run() {
// ... data loads ...
// line 675:
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
userMessages.setText("Data loaded.");
panelList.setVisible(true);
validate();
}
});
}
The components I'm trying to update are userMessages, a JLabel and panelList which is a Panel. I don't think it's getting that far however.
Does anyone know what might be happening? At this point the applet has loaded and the components can be seen and have been updated, etc.
Make sure you're deploying not only AKApplet.class, but also AKApplet$1.class, AKApplet$2.class, etc.
I guess I don't understand what the $ classes refer to. There is only a single AKApplet class, no inner classes. There are no static definitions either.
I do have two other classes defined, but they are separate classes:
class ThreadFlags { /*...*/ }
class DeleteButton extends JLabel { /*...*/ }
Also, I've verified that they are in AKApplet.jar file at the root level:
META-INF/MANIFEST.MF
META-INF/AKAPPLET.SF
META-INF/AKAPPLET.DSA
META-INF/
AKApplet.class
DeleteButton.class
ThreadFlags.class
Update: Ok, I found the AKApplet$.class files in the /build/classes/ directory of the NetBeans project. I added them, and it works. Thanks for your help. Can someone give me a brief explanantion of what those files are? As I said, there are no inner classes that I've defined...
Are there any static definitions in the second inner class of AKApplet that could throw any kind of exception?
Exceptions in the static initializer are the most common cause for NoClassDefFoundErrors after you have made sure that the class file exists and is on the classpath.

Categories