728x90
Java Applets
General Steps to Creating, Compiling and Running Java Programs
Applets in Unix & Linux server
- Open a Unix window.
- Now, change to the directory of your choice from within the window.
For example:prompt% cd MyJavaStuff
- Using the editor of your choice, create some Java source code.
For example, suppose we want a class named "A",
then we would start vi, emacs, pico, or whatever editor with the name of the Java file:
orprompt% vi A.java
orprompt% emacs A.java
prompt% pico A.java
- The source code, A.java, might look like this:
Don't forget to save the file!// This program draws a tall rectangle via the A.html applet tag. // mlc // 9/1999 import java.applet.*; import java.awt.*; public class A extends Applet { private int w, h; public void init( ) { w = 45; h = 50; } public void paint(Graphics g) { g.drawRect(w, h, 20, 80); } }
- Double check the name of the Java program file you just saved
by listing out the files in the current directory:prompt% ls
- If the name of the Java program file listed does not end in .java,
you need to rename or move (mv) it so that it does
For instance, if the file appears as A.java.txt, type Now if you list the files in the directory, you should see it named correctlyprompt% mv A.java.txt A.java
- Now, since this is an applet, we'll need to make a HTML file.
We could call it A.html and create it from the command line using your favorite editor again:
orprompt% vi A.html
orprompt% emacs A.html
prompt% pico A.html
- The A.html file might look like this:
<html> <p> This file launches the 'A' applet: A.class! </p> <applet code="A.class" height=200 width=320> No Java?! </applet> </html>
- Again, be sure to save the file
Also be sure that the name of the file ends in .html (not .txt) - Assuming we saved the Java source code (as in step 4) from within your editor,
we can now go back to the command prompt and compile it.
This is done with the javac compiler command:prompt% javac A.java
- If there were compile errors, go back to the editor and edit the A.java file
to remove the error.
Then repeat step 10 after saving the changes.
You may need to do this several times before there are no more compile errors. - If everything compiles fine
(we know this by the fact we had no error messages
and the "A.class" file exists),
we are ready to run it. - At this point (assuming we saved the HTML file in step 5),
we can run either a Java-enabled browser or
simply use the appletviewer program from the command line:prompt% appletviewer A.html
- The above command should bring up a window using the HTML file and
then launch (or run) the Java applet from within the viewer.This file launches the 'A' applet: A.class!
No Java?!You should see a tall rectangle. Good work!
appletviewer 속성 파일을 읽을 수 없음:... 기본값을 사용하는 중입니다.
can't read appletviewer properties file:
------- 읽을 수 있게 해주면 된다.
-------Set the permissions to be able to read
prompt% chmod 774 TestApplet.* // TestApplet.java TestApplet.class TestApplet.html
'my_lesson > _JAVA' 카테고리의 다른 글
Java JDBC (0) | 2016.05.10 |
---|---|
Java Applications (0) | 2016.02.16 |
Java Platform Standard Edition 8 Documentation (0) | 2016.02.16 |
댓글