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);
}
}
Related
I am studying python and I am using python 3.5 with the Jpype module.
The issue I am running into is that I want to override a function that was made in Java from python.
My Java Code:
package test;
public class TestApi
{
public void processMessage() {}
}
I compiled the java code to the jar file, TestApi.jar, and then I used the Jpype module in python in order to load it the class in my python script.
Here is my python code:
from jpype import *
jvmpath = getDefaultJVMPath()
startJVM(jvmpath, "-ea", ("-Djava.class.path=TestApi.jar"))
TestApiClass = JClass("test.TestApi") #i can read java class
javaApi = TestApiClass()
def PythonApi():
print("hello world")
With this code I would like to override the proccessMessage function from the class in Java using the PythonAPI function in my python code. Is this possible? and if it is how can this be done?
I am testing a few Java API, I've created my project called 'MyLearning' where all my src files are located, in src I created another Package callede 'myfiles', now when I import the java.nio.file.Files API, IntelliJ doesn't show me suggestions for this class. But in the main package i.e src folder, the suggestion works totally fine.
Example:
The above picture shows my main src folder, where the Files API works totally fine.
But then in the new Package that I've created i.e myfiles, it is showing error on retrieving the methods of Files API. Error is
Cannot resolve symbol 'exists'
Can anyone tell me what could be the poblem here?
You have to put method calls inside a method.
public void foo()
{
Files.exists(path);
}
I also noticed that one of the tags you put is intellij-14. The latest version of IntelliJ is 2016.2.
You have to call it in a method, not in the class
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
public class Main {
public static void main(String[] args) {
System.out.println("Hello World!");
Path path = Paths.get("C:\\log.txt");
System.out.println(Files.exists(path));
}
}
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
Hi I had a program which worked fine in a .jar file.
Basically all the classes were part of the same package called : "eu.floraresearch.lablib.gui.checkboxtree"
They ALL are located in the SAME "checkboxTree" folder. Each file has a line stating
package eu.floraresearch.lablib.gui.checkboxtree;
I need to modify the code and to integrate it in another project.
So I took all the .java files, copied them in my Eclipse project folder (no package anymore), and got rid of the "package eu.floraresearch.lablib.gui.checkboxtree;" line in each files. Everything is fine except for one file comprising an enumeration.
Originally the file looked like this:
package eu.floraresearch.lablib.gui.checkboxtree;
public class QuadristateButtonModel extends DefaultButtonModel {
public enum State {
CHECKED, GREY_CHECKED, GREY_UNCHECKED, UNCHECKED
}
...
}
The problem is, there is another class which originally imported the above class enumeration:
import eu.floraresearch.lablib.gui.checkboxtree.QuadristateButtonModel.State;
public class QuadristateCheckbox extends JCheckBox {
public QuadristateCheckbox() {
this(null);
}
public QuadristateCheckbox(String text) {
this(text, State.UNCHECKED);
}
...
}
First of all I find it weird how enumerations can be imported.. But it worked fine when everything was inside the package.
Since all my .java files are in the same folder now, I just removed the package line.
However I have this issue with the QuadristateCheckbox class which imports "QuadristateButtonModel.State".
If I change the import line with
import QuadristateButtonModel.State;
it states
The import QuadristateButtonModel cannot be resolved
I tried various things I found on the internet like
import static QuadristateButtonModel.State.*;
or
import QuadristateButtonModel.State.*;
but the same error messages occur:
The import QuadristateButtonModel cannot be resolved
On top of that, in the above code from QuadristateCheckbox class:
public QuadristateCheckbox(String text) {
this(text, State.UNCHECKED);
}
an error message
State cannot be resolved to a variable
which is understandable given the fact that I fail to import the State enumeration.
What can I do? Please explain to me what is wrong
PS: The code was taken from this site: http://www.javaworld.com/article/2077762/core-java/swing-based-tree-layouts-with-checkboxtree.html
The authors provide classes to build checkable trees.
I'm new to java and I'm trying to compile and run a web service example from a book.
The example uses 3 files.
I can create an Eclipse Project and Run it. It works fine this way.
From the command line I tried
javac TimeServer.java TimeServerImpl.java TimeServerPublisher.java
And got no errors
This program does not run on the command line returns error:
"Could not find the main class"
java TimeServerPublisher
running using the -classpath option returns the same result.
Set classpath does not help either. ie
java -classpath . TimeServerPublisher
fails as well
Most of the online docs specify I need a classpath. I tried everything they suggested.
Please Help. Thanks in advance
Source:
TimeServer.java
package ch01.ts;
import javax.jws.WebService;
import javax.jws.WebMethod;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.Style;
#WebService
#SOAPBinding(style = Style.RPC) // more on this later
public interface TimeServer
{
#WebMethod String getTimeAsString();
#WebMethod long getTimeAsElapsed();
}
TimeServerImpl.java
package ch01.ts;
import java.util.Date;
import javax.jws.WebService;
#WebService(endpointInterface = "ch01.ts.TimeServer")
public class TimeServerImpl implements TimeServer
{
#Override
public String getTimeAsString()
{
return new Date().toString();
}
#Override
public long getTimeAsElapsed()
{
return new Date().getTime();
}
TimeServerPublisher.java
package ch01.ts;
import javax.xml.ws.Endpoint;
public class TimeServerPublisher
{
public static void main(String[ ] args)
{
Endpoint.publish("http://127.0.0.1:9876/ts", new TimeServerImpl());
}
}
Your class is not named TimeServerPublisher; it's named ch01.ts.TimeServerPublisher. Even if you manage to get the JVM to find your class file, it will reject it with a wrong-name error, as you must invoke the class with its full name.
Put all the class files into a directory ch01/ts if they're not there already, and from ch01's parent directory, type
java -cp . ch01.ts.TimeServerPublisher
I guarantee that done correctly this will work.
get rid of the package statements until you know how they work. to have that package, your sources and binaries should be under ./ch01/ts/ and you would compile and invoke as:
javac ch01/ts/*.java
java ch01.ts.TimeServerPublisher
Move all your class files to folder ch01/ts.
and then execute command
java ch01.ts.TimeServerPublisher
There you go. If you say javac -d ch01/ts *.java during compilation, it will be solved.