
-----------------------------------
ProgrammingFun
Fri Jan 21, 2011 6:25 pm

Java Applet?
-----------------------------------
Disclaimer: After hours of Googling, I found nothing I understood so I decided to post here...

Is there an easy way to make an applet for a Java program which uses the console as opposed to GUI?
I want to post my Java Culminating here on this website but I do not want to show the source code (because my school might be giving the same project in the future).

Is this even possible?

My program includes one main .java file which also extends to another .java file and reads/writes to .txt files as well.

Thanks for the help. :vi:

-----------------------------------
TheGuardian001
Fri Jan 21, 2011 6:31 pm

Re: Java Applet?
-----------------------------------
Highly doubt it. The Java console is not owned by your program. If it isn't launched from a console, the console doesn't exist.

-----------------------------------
Tony
Fri Jan 21, 2011 6:33 pm

RE:Java Applet?
-----------------------------------
How about a compiled JAR?

-----------------------------------
ProgrammingFun
Fri Jan 21, 2011 6:33 pm

RE:Java Applet?
-----------------------------------
Is there any way to hide the source code then?

EDIT: How can I compile a JAR?

-----------------------------------
Insectoid
Fri Jan 21, 2011 7:35 pm

RE:Java Applet?
-----------------------------------
http://java.sun.com/developer/Books/javaprogramming/JAR/basics/

-----------------------------------
ProgrammingFun
Fri Jan 21, 2011 8:13 pm

RE:Java Applet?
-----------------------------------
Using this: http://java.sun.com/developer/Books/javaprogramming/JAR/basics/build.html

I always get the following error:
http://i56.tinypic.com/mskthj.jpg

-----------------------------------
TerranceN
Fri Jan 21, 2011 8:42 pm

RE:Java Applet?
-----------------------------------
Edit your PATH environment variable to include /YOUR_JAVA_SDK_DIRECTORY/bin, then you should be able to use the jar command.

-----------------------------------
ProgrammingFun
Fri Jan 21, 2011 8:47 pm

RE:Java Applet?
-----------------------------------
Which one is that?

EDIT: When I try to do so, I get the error: "Too much parameters"

I am using instructions from: http://www.skylit.com/javamethods/faqs/createjar.html

   1. Start Command Prompt.
   2. Navigate to the folder that holds your class files:

      C:\>cd \mywork

   3. Set path to include JDK?s bin.  For example:

      C:\mywork> path c:\Program Files\Java\jdk1.5.0_09\bin;%path%

   4. Compile your class(es):

      C:\mywork> javac *.java

   5. Create a manifest file:

      C:\mywork> echo Main-Class: DanceStudio >manifest.txt

   6. Create a jar file:

      C:\mywork> jar cvfm DanceStudio.jar manifest.txt *.class

   7. Test your jar:

      C:\mywork> DanceStudio.jar



-----------------------------------
DemonWasp
Fri Jan 21, 2011 11:11 pm

RE:Java Applet?
-----------------------------------
Your jar line is wrong; the way you specify the m option, the first file specified must be your manifest:

[code]jar cvmf manifest.txt *.class[/code]

-----------------------------------
ProgrammingFun
Sat Jan 22, 2011 1:47 pm

RE:Java Applet?
-----------------------------------
I still get errors. Do I need to import anything into the java files before compiling?

-----------------------------------
DemonWasp
Sat Jan 22, 2011 3:31 pm

RE:Java Applet?
-----------------------------------
...that's because I ALSO managed to screw up the command line. Sorry. I'll try to get it right this time:

[code]jar cvmf manifest.txt out.jar *.class[/code]

-----------------------------------
ProgrammingFun
Sat Jan 22, 2011 3:50 pm

Re: Java Applet?
-----------------------------------
Since I am so noob, I decided to download and use JCreator to do it for me, BUT:

I get this error from my jar file:

Failed to load Main-Class manifest attribute from Othello.jar

I have already included the attribute as follows but I still get the same error:

Main-Class: 

How will the jar file read/write to text files in the root and subfolders?
This is my structure:


Culminating
 |
 |- 

This is the log that JCreator creates when making the JAR file:

--------------------Custom Tool: Create Jar File--------------------
Command   : "C:\Program Files\Java\jdk1.6.0_21\bin\jar.exe" cvfm Othello.jar manifest.txt *.class *.txt
Directory : ""

added manifest
adding: Methods.class(in = 14312) (out= 7723)(deflated 46%)
adding: Two_Player_Othello_MuhammadOsama.class(in = 458) (out= 290)(deflated 36%)
adding: Instructions.txt(in = 5082) (out= 1567)(deflated 69%)
adding: manifest.txt(in = 75) (out= 68)(deflated 9%)

Process completed.


-----------------------------------
TerranceN
Sat Jan 22, 2011 3:58 pm

RE:Java Applet?
-----------------------------------
Does your Manifest.txt end with a newline? It says here, that it must end with a newline or carriage return, otherwise the last command will not be parsed properly.

-----------------------------------
ProgrammingFun
Sat Jan 22, 2011 4:12 pm

RE:Java Applet?
-----------------------------------
Like this?

Class-Path: Othello.jar\r\n
Main-Class: Two_Player_Othello_ProgrammingFun.class\r\n


I still get the same error.

-----------------------------------
TerranceN
Sat Jan 22, 2011 4:30 pm

Re: Java Applet?
-----------------------------------
First of all, Class-Path is for JAR extensions, from your previous post, I don't think thats what you want. Also, you only use the class name, without the .class, in the manifest file.

No, just put a new empty line, like this
[code]
Main-Class: Two_Player_Othello_ProgrammingFun
This line, the last line, will not be parsed, it can be anything.
[/code]

-----------------------------------
ProgrammingFun
Sat Jan 22, 2011 5:16 pm

RE:Java Applet?
-----------------------------------
Sorry, now I get this error:


--------------------Custom Tool: Create Jar File--------------------
Command   : "C:\Program Files\Java\jdk1.6.0_21\bin\jar.exe" cvfm Othello.jar manifest.txt *.class *.txt saveData/
Directory : ""

java.io.FileNotFoundException: manifest.txt (The system cannot find the file specified)
    at java.io.FileInputStream.open(Native Method)
    at java.io.FileInputStream.(FileInputStream.java:106)
    at java.io.FileInputStream.(FileInputStream.java:66)
    at sun.tools.jar.Main.run(Main.java:150)
    at sun.tools.jar.Main.main(Main.java:1149)

Process completed.


-----------------------------------
ProgrammingFun
Sat Jan 22, 2011 11:11 pm

RE:Java Applet?
-----------------------------------
Never mind, I got it work.
Thanks a lot!

Please check out my program here: http://compsci.ca/v3/viewtopic.php?p=229279#229279
