I am trying to make a Java applet. So far I have this:
import javax.swing.*;
import java.awt.*;
public class Applet extends JApplet {
public void start(){}
public void init(){}
public void paint(Graphics g){}
}
But I get this message: javax.swing.JApplet is not present in JRE Emulation Library
Also this message: java.awt.Graphics is not present JRE Emulation Library
If I change the import statements to the following:
import javax.swing.JApplet;
import java.awt.Graphics;
I still get the same message.
I have come across many links but nothing gives me the option to download javax.swing.JApplet and java.awt.Graphics to get my applet to work
Related
My professor gave me these classes but when I try to run them it seems that AnimationNoApplet cannot find NoApplet the title is the error I receive. I have both files in the same folder and have tried switching the package names to be identical but no success.
This is AnimationNoApplet:
package noapplet.example;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import javax.swing.Timer;
import noapplet.NoApplet;
/** Reusable class implementing the animation idiom. */
#SuppressWarnings("serial")
public abstract class AnimationNoApplet extends NoApplet {
This is NoApplet
package noapplet;
#SuppressWarnings("serial")
public class NoApplet extends JPanel {
There is many lines to the two files but I believe this is the root of the problem. Another thing that I noticed was the class made for AnimationNoApplet was NoApplet$1.class. I'm not sure if this is relevant information but I thought I should call it out. The last thing I want to call out is that this is on visual studio code I have not used another editor.
import java.awt.*;
import java.applet.*;
/* <applet code="Demonstration_21" width=300 height=300> </applet> */
public class Demonstration_21 extends Applet{
public void paint(Graphics g){
g.drawString("Welcome",150,150);
}
}
I have written this code to run an applet program but whenever I compile it gives some warning as:
Demonstration_21.java uses or overrides a deprecated API
Recompile with Xlint:deprecation for details.
And whenever I run this code it gives error as:
Demonstration_21 has been compiled by a more recent version of Java
Runtime(class file version 55.0),this version of Java Runtime only
recognizes class file versions up to 52.0
My appletviewer is not initialized.
You should build it with Java 8 instead of Java 11.
Here is a list of class file versions an the related Java major versions
List of Java class file format major version numbers?
you miss something..
In applet tag code attribute you have to specify .class file.
import java.awt.*;
import java.applet.*;
/* <applet code="Demonstration_21.class" width=300 height=300> </applet> */
public class Demonstration_21 extends Applet{
public void paint(Graphics g){
g.drawString("Welcome",150,150);
}
}
I cannot seem to import the opengl properly.
I am following this simple tutorial:
https://www.youtube.com/watch?v=ZKJC2cloIqc
As far as I understand, I have the correct jar and native files.
// I can import these
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
//I cannot however import this:
import org.lwjgl.LWJGLEXCEPTION;
//and gl methods such as this are not recognized:
glClear(GL_COLOR_BUFFER_BIT);
I am using eclipse, I also have netbeans and am debating getting the intelij IDE being used in this tutorial if it will make this work.
You didn't Import GL11 to use gl methods (or other versions for certain methods )
You can use a static import so you don't have to put GL11 in front of every method or anything else
I am working in an Android project recently. Our project uses a computer vision library called boofcv:
http://boofcv.org/index.php?title=Main_Page
After importing the library source code into our project, I found that Android Studio cannot revolve symbols from sun.awt.image.* and java.awt.color.ColorSpace.
package boofcv.core.image;
import boofcv.struct.image.*;
import sun.awt.image.ByteInterleavedRaster;
import sun.awt.image.IntegerInterleavedRaster;
import sun.awt.image.ShortInterleavedRaster;
import javax.swing.*;
import java.awt.*;
import java.awt.color.ColorSpace;
import java.awt.image.*;
import java.lang.reflect.Array;
/**
* Functions for converting to and from {#link BufferedImage}.
*
* #author Peter Abeles
*/
public class ConvertBufferedImage {
......
But then I wrote a very simple test program and found that my jdk did contain those classes. my program:
import sun.awt.image.ByteInterleavedRaster;
import sun.awt.image.IntegerInterleavedRaster;
import sun.awt.image.ShortInterleavedRaster;
import javax.swing.*;
import java.awt.*;
import java.awt.color.ColorSpace;
import java.awt.image.*;
class test{
public static void main(String[] args) {
ByteInterleavedRaster b;
IntegerInterleavedRaster i;
ShortInterleavedRaster s;
ColorSpace c;
System.out.println("testing");
}
}
Did I miss some configuration or it is just the issue of Android Studio?
Any help is greatly appreciated.
Don't use the visualization package for anything on Android. It's based off on swing which isn't supported on Android. Use the android package in integration. It has similar functions for visualizing data.
https://github.com/lessthanoptimal/BoofAndroidDemo
that might be useful for you.
I am trying to create a Java applet with JInternalFrames. For this I believe you need a JFrame in one form or another. I heard you could wrap your applet in a JFrame, is that best? If you could tell me what I should do I would appreciate it. TYIA -Roland
/**
* #(#)rebuiltgui.java
*
* rebuiltgui Applet application
*
* #author
* #version 1.00 2013/1/21
*/
import javax.swing.JInternalFrame;
import javax.swing.JDesktopPane;
import javax.swing.plaf.basic.BasicInternalFrameUI;
import java.awt.event.*;
import java.awt.Desktop;
import javax.swing.*;
import javax.swing.BoxLayout;
import java.awt.*;
import java.applet.*;
public class rebuiltgui extends JApplet {
public void init() {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
private void createAndShowGUI() {
// This is where I would put the internal frames.
}
}
You can create JFrame in the applet code same way you do in a stand alone Swing application:
JFrame frame = new JFrame("Hello");
....
frame.show();
The frame will leave the browser window, showing up as a separate window, just it will contain some warning tags that this is a Java applet running. Such frame can be resized or moved around.
Actually, some "applets" do not show much more than a single button to launch the frame in they main view.
See http://baba.sourceforge.net/ for an example of the applet that shows four buttons to launch four different visualizations (source code is available).
If, very differently, you actually want frames that could not leave your applet area, use InternalFrame. It is a LayeredPane so you can also put your main component as a background layer.