Informatica
Doriți să reacționați la acest mesaj? Creați un cont în câteva clickuri sau conectați-vă pentru a continua.

Biblioteca java applet

In jos

Biblioteca java applet    Empty Biblioteca java applet

Mesaj  Admin Sam Mar 03, 2012 7:03 am

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 folosind 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 către un applet:


Java Applet












Admin
Admin
Admin
Admin

Mesaje : 1113
Data de inscriere : 02/03/2012

http://dutu.p.ht/

Sus In jos

Sus

- Subiecte similare

 
Permisiunile acestui forum:
Nu puteti raspunde la subiectele acestui forum