Pagina de start a forumului Informatica
 FAQ  •  Cautare  •  Membri  •  Grupuri   •  Inregistrare  •  Profil  •  Mesaje private  •  Autentificare
Subiectul urmator
Subiectul anterior
Creaza un subiect nou   Raspunde la subiect  Pagina de start a forumului Informatica » Despre limbajele de programare
Autor Mesaj
Admin
Administrator
Administrator


Data inscrierii: 07/Dec/2013
Mesaje: 1103

MesajTrimis: 12/12/2013 21:21 Raspunde cu citat (quote) Back to top

Biblioteca java applet
Constructor
Applet ()
Metode
destroy()
Cleans up whatever resources are being held.
getAppletContext()
Gets a handle to the applet context.
getAppletInfo()
Returns a string containing information about the author, version and copyright of the applet.
getAudioClip(URL)
Gets an audio clip.
getAudioClip(URL, String)

Gets an audio clip.
getCodeBase()
Gets the base URL.
getDocumentBase()
Gets the document URL.
getImage(URL)
Gets an image given a URL.
getImage(URL, String)
Gets an image relative to a URL.
getParameter(String)
Gets a parameter of the applet.
getParameterInfo()
Returns an array of strings describing the parameters that are understood by this applet.

init()
Initializes the applet.
isActive()
Returns true if the applet is active.
play(URL)
Plays an audio clip.
play(URL, String)
Plays an audio clip.
resize(int, int)
Requests that the applet be resized.
resize(Dimension)
Requests that the applet be resized.
setStub(AppletStub)
Sets the applet stub.
showStatus(String)
Shows a status message in the applet's context.
start()
Called to start the applet.
stop()
Called to stop the applet.

Exemplu de applet :
import java.applet.* ;
import java.awt.* ;
import java.net.*;
public class TestApplet extends Applet implements Runnable{
AppletContext myAppletContext;
Thread myThread;
int height, width;
URL myURL;
String param, strURL;
Image myImage;

public void init() {
//Obtin contextul in care ruleaza miniaplicatia
myAppletContext = this.getAppletContext();
//Afiseaza un mesaj de stare utilizând contextul
myAppletContext.showStatus("Metoda init");
height = 200;
width = 400;
strURL = "file:/D:/works/web/Images/abc.gif";
sleep(2000);
}
public void start() {
if (myThread == null) {
myThread = new Thread(this) ;
myThread.start();
}
myAppletContext.showStatus("Metoda start");
sleep(2000);
}
public void stop() {
if (myThread != null) {
myThread.stop();
myThread = null;
}
}
public void run() {
myAppletContext.showStatus("Metoda run");
sleep(2000);
param = getParameter("width");
if (param != null)
width = Integer.parseInt(param);
param = getParameter("height");
if (param != null)
height = Integer.parseInt(param);
param = getParameter("URL");
if (param != null)
strURL = param;

resize(width, height);
try { myURL = new URL(strURL); }
catch (MalformedURLException e) {}
myImage = getImage(myURL);
repaint();
}
public String[][] getParameterInfo() {
String paramInfo[][] = {
{"height", "int", "..."},
{"width", "int", "..."},
{"URL", "URL", "..."}
};
return (paramInfo);
}
public void paint( Graphics g) {
g.drawString(getAppletInfo(), 10, 10);
g.drawString("adresa URL de baza= " + getCodeBase(), 10, 20);
g.drawString("adresa URL a documentului = " + getDocumentBase(), 10, 30);
if (myImage != null)
g.drawImage(myImage, 10, 40, this);
}
public void sleep(int period) {
try {Thread.sleep(period); }
catch (InterruptedException e) {}
}
public String getAppletInfo() {
return("Applet ..., Autor : ..., Versiune...");
}
}

Structura unui fişier HTML care foloseşte transmiterea de parametri spre un applet:
<html>
<head>
<title>Java Applet</title>
</head>
<body>
<hr>
<applet>
<param name="width" VALUE="700">
<param name="height" VALUE="300">
<param name="URL" VALUE="file:/D:/works/web/Images/abc.gif">
</applet>
<hr>
</body>
</html>
Vezi profilul utilizatorului Trimite mesaj privat
Afiseaza mesajele pentru a le previzualiza:   
Creaza un subiect nou   Raspunde la subiect

Subiectul urmator
Subiectul anterior
Nu puteti crea un subiect nou in acest forum
Nu puteti raspunde in subiectele acestui forum
Nu puteti modifica mesajele proprii din acest forum
Nu puteti sterge mesajele proprii din acest forum
Nu puteti vota in chestionarele din acest forum


Powered by phpBB © 2001, 2002 phpBB Group