mmmm...java

This forum is for actual topics of discussion that do not fit the above categories.
Locked
User avatar
Chef
Joined: Mon May 06, 2002 4:41 pm
Location: Ever seen "Pecker"?
Contact:
Org Profile

mmmm...java

Post by Chef » Fri Oct 17, 2003 6:32 pm

i know there are a few java programmers on this site...so heres a dumb question: if i write a program, how do i put it on a website? ^_^;

User avatar
Eek-1
Joined: Sat Jun 22, 2002 10:06 am
Status: 0xc00000e9
Location: Cyberjaya
Org Profile

Post by Eek-1 » Fri Oct 17, 2003 7:35 pm

once you're done, compile your .java and then write in html

Code: Select all

<html>
...
<applet code="whateverthenameis.class" width="12345" height="67890">
</applet>
...
</html>

User avatar
Chef
Joined: Mon May 06, 2002 4:41 pm
Location: Ever seen "Pecker"?
Contact:
Org Profile

Post by Chef » Fri Oct 17, 2003 7:55 pm

i keep getting a blank page...

User avatar
downwithpants
BIG PICTURE person
Joined: Tue Dec 03, 2002 1:28 am
Status: out of service
Location: storrs, ct
Org Profile

Post by downwithpants » Fri Oct 17, 2003 8:24 pm

have you written your paint(Graphics); method and it works all right?

if the .class file is in a different directory from the html file, you have to add codebase="location" to the <applet> tag, where location is the location of the directory the .class file is in.
maskandlayer()|My Guide to WMM 2.x
a-m-v.org Last.fm|<a href="http://www.frappr.com/animemusicvideosdotorg">Animemusicvideos.org Frappr</a>|<a href="http://tinyurl.com/2lryta"> Editors and fans against the misattribution of AMVs</a>

User avatar
Chef
Joined: Mon May 06, 2002 4:41 pm
Location: Ever seen "Pecker"?
Contact:
Org Profile

Post by Chef » Fri Oct 17, 2003 8:26 pm

downwithpants wrote:have you written your paint(Graphics); method and it works all right?

if the .class file is in a different directory from the html file, you have to add codebase="location" to the <applet> tag, where location is the location of the directory the .class file is in.
i dont know what that is. i dont know much about java ^_^;

User avatar
downwithpants
BIG PICTURE person
Joined: Tue Dec 03, 2002 1:28 am
Status: out of service
Location: storrs, ct
Org Profile

Post by downwithpants » Fri Oct 17, 2003 8:56 pm

hmm, ok
is your program already written in java? and are you familiar with object oriented programming?

if so, to create a java program that will run in a webpage, you need to create a class that extends class Applet or JApplet (a subclass of Applet).

Class Applet has the five methods: (JApplet also has them through inheritance)

init();
start();
paint(Graphics);
stop();
destroy();

the browser calls init(); (either from class Applet or your class) to load the applet. You can write an init(); method in your class to create a modified version of the init(); method that will override the init(); method in class Applet. you can write into your init(); method statements that you want to execute when the applet loads in an init(); method in your class.

the browser calls paint(Graphics); to create the display of the window. you can write statements in a paint(Graphics); method in your class in order to control the display.
maskandlayer()|My Guide to WMM 2.x
a-m-v.org Last.fm|<a href="http://www.frappr.com/animemusicvideosdotorg">Animemusicvideos.org Frappr</a>|<a href="http://tinyurl.com/2lryta"> Editors and fans against the misattribution of AMVs</a>

User avatar
Chef
Joined: Mon May 06, 2002 4:41 pm
Location: Ever seen "Pecker"?
Contact:
Org Profile

Post by Chef » Fri Oct 17, 2003 9:01 pm

downwithpants wrote:hmm, ok
is your program already written in java? and are you familiar with object oriented programming?

if so, to create a java program that will run in a webpage, you need to create a class that extends class Applet or JApplet (a subclass of Applet).

Class Applet has the five methods: (JApplet also has them through inheritance)

init();
start();
paint(Graphics);
stop();
destroy();

the browser calls init(); (either from class Applet or your class) to load the applet. You can write an init(); method in your class to create a modified version of the init(); method that will override the init(); method in class Applet. you can write into your init(); method statements that you want to execute when the applet loads in an init(); method in your class.

the browser calls paint(Graphics); to create the display of the window. you can write statements in a paint(Graphics); method in your class in order to control the display.
how would i do that?

im really new at this ^_^;

User avatar
downwithpants
BIG PICTURE person
Joined: Tue Dec 03, 2002 1:28 am
Status: out of service
Location: storrs, ct
Org Profile

Post by downwithpants » Fri Oct 17, 2003 9:37 pm

it might look something like:

import java.awt.*;
import java.applet.*;
import java.util.*;

public class myProgram extends JApplet{

private int x;
private int y;

public void init() {
Date d= new Date;
x= d.getHours();
y= d.getDay();
}

public void paint (Graphics g){
g.drawString("The hour is" + x +". The day is" + y);
}

}


When the browser calls init(); it will get the statements
{Date d= new Date;
x= d.getHours();
y= d.getDay();}

Then when it calls paint(Graphics g); it will get the statements
{g.drawString("The hour is" + x +". The day is" + y);}

When it calls start(); stop(); or destroy(); it will use the methods defined in Class Applet
maskandlayer()|My Guide to WMM 2.x
a-m-v.org Last.fm|<a href="http://www.frappr.com/animemusicvideosdotorg">Animemusicvideos.org Frappr</a>|<a href="http://tinyurl.com/2lryta"> Editors and fans against the misattribution of AMVs</a>

User avatar
Eek-1
Joined: Sat Jun 22, 2002 10:06 am
Status: 0xc00000e9
Location: Cyberjaya
Org Profile

Post by Eek-1 » Fri Oct 17, 2003 11:33 pm

before programming your own, why not copy/paste a simple Hello World example in java online tutorials, to see if it works. If not, you probably have not installed java virtual machine for your browser.

Locked

Return to “General Off Topic”