Java

Questions about programming languages and debugging
Post Reply
User avatar
MaC-OwN
Newbie
Newbie
Posts: 3
Joined: 24 Feb 2006, 17:00
18

Java

Post by MaC-OwN »

Hi guys, im new here.. and ive got a little problem with the Javascripts..
Ive tried to download sum programs.. written in java.. but than i realized i dont know how to open them or work with it.. so ive just got a javascript..
what shud i do with it? and how shud i open it?
Help wud be appreciated :wink:

User avatar
bad_brain
Site Owner
Site Owner
Posts: 11636
Joined: 06 Apr 2005, 16:00
19
Location: In your eye floaters.
Contact:

Post by bad_brain »

um, the question is: is it Java or JavaScript?
many people confuse this at the beginning, JavaScript is embedded in HTML like in this example:

Code: Select all

<html>

<head>
<title></title>
 
<--script language="javascript"> #had to comment this out
function mouseMove(e)
         {
         var x = (navigator.appName == 'Netscape')? e.pageX :
         event.x+document.body.scrollLeft;
         var y = (navigator.appName == 'Netscape')? e.pageY :
         event.y+document.body.scrollTop;
         if(navigator.appName == 'Netscape' && e.target!=document)
         routeEvent(e);

         Clip(Hidden, 0, y + 10, WindowWidth(), 60);

         return(true);
         }

function Clip(layer, x, y, w, h)
         {
         if(navigator.appName == 'Netscape')
           {
           if(parseInt(navigator.appVersion) == 5)
             {
             layer.style.clip =
             'rect(' + y + ' ' + (x + w) + ' ' + (y + h) + ' ' + x + ')';
             }
           if(parseInt(navigator.appVersion) == 4)
             {
             layer.clip.left = x;
             layer.clip.top = y;
             layer.clip.right = x + w;
             layer.clip.bottom = y + h;
             }
           }
         else
           {
           layer.style.clip =
           'rect(' + y + ' ' + (x + w) + ' ' + (y + h) + ' ' + x + ')';
           }
         }

function GetLayer(layer)
         {
         var ReturnLayer = null;
         if(navigator.appName == 'Netscape')
           {
           if(parseInt(navigator.appVersion) == 5)
              ReturnLayer = document.getElementById(layer);
           else
              eval('ReturnLayer = document.' + layer + ';');
           }
         else
           {
           eval('ReturnLayer = document.all.' + layer + ';');
           }
         return ReturnLayer;
         }

function WindowWidth()
         {
         if(navigator.appName == 'Netscape')
           return window.innerWidth;
         else
           return document.body.clientWidth;
         }

function init()
         {
         document.onmousemove = mouseMove;
         if(navigator.appName == 'Netscape')
         document.captureEvents(Event.MOUSEMOVE);

         Hidden = GetLayer('back');
         }
<--/script> #had to comment this out
</head>

<body onload="init();" marginheight="0" marginwidth="0"
topmargin="0" leftmargin="0">

<div id="front" style="position:absolute; width:100%; height:100%;">
     <table align="center" height="100%">
     <tr>
     <td width="600" height="100%" style="font-size:24pt;">
     H<font color="ffffff">idden Tex</font>t
     H<font color="ffffff">idden Tex</font>t
     H<font color="ffffff">idden Tex</font>t
     H<font color="ffffff">idden Tex</font>t
     H<font color="ffffff">idden Tex</font>t
     H<font color="ffffff">idden Tex</font>t
     H<font color="ffffff">idden Tex</font>t
     H<font color="ffffff">idden Tex</font>t
     H<font color="ffffff">idden Tex</font>t
     H<font color="ffffff">idden Tex</font>t
     </td>
     </tr>
     </table>
</div>

<div id="back" style="position:absolute; clip:rect(0 0 0 0);
width:100%; height:100%;">
     <table align="center" height="100%">
     <tr>
     <td width="600" height="100%" style="font-size:24pt;">
     H<font color="000000">idden Tex</font>t
     H<font color="000000">idden Tex</font>t
     H<font color="000000">idden Tex</font>t
     H<font color="000000">idden Tex</font>t
     H<font color="000000">idden Tex</font>t
     H<font color="000000">idden Tex</font>t
     H<font color="000000">idden Tex</font>t
     H<font color="000000">idden Tex</font>t
     H<font color="000000">idden Tex</font>t
     H<font color="000000">idden Tex</font>t
     </td>
     </tr>
     </table>
</div>

</body>
</html>
the function is defined in the html-header, and in the html-body the function is called.

Java don´t need a browser to work like JavaScript, Java applications only need the Java runtime environment. Here´s an example for a Java code, you´ll see the difference to JavaScript:

Code: Select all

import java.awt.*;
import java.applet.Applet;
public class Rate_GUI extends Applet {
Label labelSuche1, labelSuche2, labelSuche3;
Label labelText1, labelText2;
TextField textfieldVersuch1, textfieldVersuch2, 
textfieldVersuch3;
Button buttonInfo, buttonNeu, buttonVersuch;
TextArea textareaInfo;
public void init() {
setLayout(null);
labelText1 = new Label ("Raten Sie die 3 Ziffern");
labelText2 = new Label ("Lösungen");
labelSuche1 = new Label ("X");
labelSuche2 = new Label ("X");
labelSuche3 = new Label ("X");
textfieldVersuch1 = new TextField("");
textfieldVersuch2 = new TextField("");
textfieldVersuch3 = new TextField("");
buttonInfo = new Button("Info");
buttonNeu = new Button("Neues Spiel");
buttonVersuch = new Button("Versuchen");
textareaInfo = new TextArea();
labelText1.setBounds(20,25,350,25);
labelText2.setBounds(20,70,120,25);
labelSuche1.setBounds(175,70,25,25);
labelSuche2.setBounds(255,70,25,25);
labelSuche3.setBounds(335,70,25,25);
textfieldVersuch1.setBounds(170,110,25,25);
textfieldVersuch2.setBounds(250,110,25,25);
textfieldVersuch3.setBounds(330,110,25,25);
buttonInfo.setBounds(20,160,80,25);
buttonNeu.setBounds(140,160,100,25);
buttonVersuch.setBounds(280,160,100,25);
textareaInfo.setBounds(20,210,360,140);
add(labelText1); add(labelText2);
add(labelSuche1); add(labelSuche2); add(labelSuche3);
add(textfieldVersuch1); add(textfieldVersuch2); 
add(textfieldVersuch3);
add(buttonInfo); add(buttonNeu); add(buttonVersuch);
add(textareaInfo);
}
}
to make this code work you have to compile it and turn this code into an executable file. the source file has the ending ".java" then, and you compile it with javac:

Code: Select all

javac filename.java
um,ok,the code above may be not a good example because it´s an applet and has a GUI, but well, compling is the same... :wink:

ok, to compile Java source code you need the Java Develpment Kit:
http://java.sun.com/j2se/1.5.0/download.jsp
to check if/what version you have Java installed check in command prompt for

Code: Select all

java -version
if you get an error then you have either Java not installed at all or the path to Java´s bin-folder isn´t set in the environment variables...

and if you have an already compiled .class or .jar-file you need to decompile it first to be able to look at the source, use a decompiler like Mocha, you can get it in the development download-section.


hope it helped a bit
:wink:


oops...welcome to the site btw... :lol: :wink:

User avatar
MaC-OwN
Newbie
Newbie
Posts: 3
Joined: 24 Feb 2006, 17:00
18

Post by MaC-OwN »

wow, thanks!,, ur a great help m8.. thank you! if i have any problems.. could i mail u? 8)

User avatar
bad_brain
Site Owner
Site Owner
Posts: 11636
Joined: 06 Apr 2005, 16:00
19
Location: In your eye floaters.
Contact:

Post by bad_brain »

simply post here mate, then others can learn from the questions/answers too... :wink:

Post Reply