Skip to main content

Java Applets 

Introduction to Java Applets 

Applet एक java program होता है जो browser में run होता है। ये एक ऐसा प्रोग्राम होता है जो HTML के साथ काम कर सकता है। इसे HTML code में ही include कर लिया जाता है।
Java program की file और HTML program की files अलग अलग होती है। HTML में java program को load करने के लिए आप <applet> tag यूज़ करते है।
जब कोई भी यूज़र इस HTML पेज को browser पर देखता है तो HTML के साथ java program भी load हो जाता है। लेकिन इसके लिए आपको applet (java program) को और HTML file को एक ही server पर save करना पड़ता है। 
Applet ऐसा java program होता है जो Applet class को extend करता है। Applet program को .class extension से save किया जाता है। जब कोई यूज़र browser में applet को देखता है तो applet का code उस user की machine में download हो जाता है।
पहले applet का code user की machine में download होता है फिर applet browser में रन होता है। इसलिए आप कह सकते है की applets client side applications होती है।Applets को run होने के लिए JVM की जरुरत होती है। JVM browser plugin के रूप में भी हो सकती है या आपके system में भी हो सकती है। 
Applet प्रोग्राम को आप browser में ना देख कर एक applet viewer में भी देख सकते है। जब आप किसी applet program को HTML में include ना करके directly रन करवा देते है, तो java automatically applet को applet viewer में शो कर देती है।    
एक applet java program में main() मेथड नहीं होता है। Applet class कई life cycle methods provide करती है जिनसे applet को handle किया जाता है। हर method को एक specific task perform करने के लिए बनाया गया है।
Applet की life cycle में ये सभी methods एक ना एक बार जरूर execute किये जाते है। आइये इन सभी methods के बारे में जानने का प्रयास करते है।

Life cycle of Java Applets 

Applet क्लास 5 important methods provide करती है, जिन्हे आप override करते है। इन methods को life cycle methods भी कहते है। एक applet program अपनी life cycle में इन सभी methods से होकर गुजरता है। ये सभी methods आपको applet program पर पूरा पूरा control provide करते है। ये सभी methods निचे दिए जा रहे है। 
  • init() – इस method में आप variables को initialize कर सकते है या फिर कोई object क्रिएट कर सकते है। किसी भी तरह का initialization आप इस method में कर सकते है। जैसे की applet का background color set कर सकते है। 
  • start() – ये मेथड init() method के बाद automatically call होता है। ये method browser में applet को call करता है। 
  • stop() – ये मेथड applet को stop करने के लिए यूज़ किया जाता है। आप जब applet वाले HTML page को छोड़ कर किसी दूसरी window पर जाते है तो ये method call होता है और applet pause हो जाता है। जब आप वापस उसी window पर आते है, तो applet फिर से शुरू हो जाता है। 
  • destroy() – जब आप browser को close करते है तो ये मेथड call होता है और applet destroy हो जाता है। 
  • paint() – इस method को आप applet में कुछ draw करने के लिए यूज़ किया जाता है। ये method start() मेथड के बाद call होता है।                          
आइये अब applet का एक complete उदाहरण देखते है। 

Example of Java Applets

// Java
code
class
picture extends Applet
{
   public void init()
   {
     void setBackground(color.red);
   }

   public void paint(Graphics g)
   {
     g.drawString(“Applet are for GUI”,30,30);
   }
}
//HTML
code
<html>

<head>
<title>applet example</applet>
</head>

<applet code=”picture.class” width=”300″
height=”300″>
</applet>
</html>

Parameter Passing in Java Applets 

आप java file को HTML file के through parameters भी पास कर सकते है। कई बार ऐसा होता है की आप input user से किसी form के द्वारा लेते है। और further processing के लिए आपको इस input को java file को pass करने के आवश्यकता होती है।
इसलिए applet API parameter passing का feature provide करती है। Java file को parameters pass करने के लिए HTML एक <param> नाम का tag provide करती है। इस tag को आप <applet> starting और </applet> closing tags के बीच में लिखते है। इस टैग के 2 attributes होते है।
पहला attribute name होता है। इस attribute में आप उस value का नाम लिखते है जो आप parameters के द्वारा pass करना चाहते है। दूसरा attribute value होता है। इस आप name attribute में pass किये गए naam की value देते है। ये key value pair की तरह work करते है।
Java file में इन parameters को include करने के लिए सबसे पहले आप एक variable क्रिएट करते है। इसके बाद आप इस variable की value provide करने के लिए एक getParameters() method कॉल करते है।
इस method में आप उस parameter का नाम pass करते है, जिसकी value आप variable में store करवाना चाहते है। ये method उस parameter की value variable में store कर देता है। इसका उदाहरण निचे दिया जा रहा है।
Applets java को बहुत ही advanced feature है, इसकी मदद से आप कई प्रकार के graphics design कर सकते है।
//html file
<html>

<head>
<title>applet example</applet>
</head>

<applet code=”picture.class” width=”300″
height=”300″>
<param name=userName value=Vipin Sharma>
</applet>
</html>
//java file
class userName extends Applet
{
   String username;

   public void start()
   {
     username = getParameter(“userName”);
   }
   public void paint(Graphics g)
   {
     g.drawString(username,30,30);
   }
}

Comments

Popular posts from this blog

    METACHAR ACTER   UNIX  shell  अनेक मेटाचारेक्टर प्रोवाइड करता है जो किसी भी शैल स्कफ्रिप्त में उनका उसे करते टाइम विषेस माइनिंग रखते और जब तक काशी सोवळे नहीं हो जाते तब काट किसी वर्ड का एंडिंग का कारन बनते है।                                                     ex:--     एक directory में फिलो को लिस्टिंग करते टाइम एक सिंगल चैरेक्टर में रखा जाता है और * एक से अधिक वर्ड को मैचेस करता है यह शैल के अधिकांश पत्रों को लिस्ट दी गयी है जिन्हे metacharacter बोला  जाता है.   * ? [ ] " ' \    /    $ : ; ( ) | ^ < >  \.   नई लाइन स्पेस तब   #!/bin/sh  echo hello; word  #!/bin/sh  echo "I have \$1200" 1. <  single quotes : all special charecters between these quotes lose their special.  ex. --...
UNIX in Hindi UNIX एक multi tasking, multi user operating system  है जिसे सन 1969  में AT & T LABS  में बनाया गया था। जिसे AT & T में काम करने वाले computer  scientist  ken Thompson  &   Denis Ritchie and  उनके friends ने मिलकर  बनाया गया था.  ऐसे AT & T   ने अपने उसे के लिए बनाया गया था लेकिन बाद में सन 1970 में इसे commercialize कर दिया गया था।  इस Operating System को ख़ास तौर पर Programmers और developers के लिए बनाया गया था। इसकी बजह यह थी की यह Modular Programming Interface design provide करता था जिसे "Unix Philosophy" भी कहा जाता है। UNIX Operating System को 'C' और Assembly Programming Languages में लिखा गया था। C Programming language को खास तौर पर UNIX बनाने के लिए ही develop किया गया था और इसे भी Denis Ritchie द्वारा ही बनाया गया था। आज भी 'C' Programming Language को बहुत ख़ास माना जाता है क्यूंकि Device Drivers इसी language में ज्यादातर लिखे जाते हैं और साथ ही इसे  Mother...
Addressing modes of microprocessor 8085 The way of specifying data to be operated by an instruction is called addressing Types of addressing modes – In 8085 microprocessor there are 5 types of addressing modes: Immediate Addressing Mode – In immediate addressing mode the source operand is always data. If the data is 8-bit, then the instruction will be of 2 bytes, if the data is of 16-bit then the instruction will be of 3 bytes. Examples: MVI B 45 (move the data 45H immediately to register B) LXI H 3050 (load the H-L pair with the operand 3050H immediately) JMP address (jump to the operand address immediately). Register Addressing Mode – In register addressing mode, the data to be operated is available inside the register(s) and register(s) is(are) operands. Therefore the operation is performed within various registers of the microprocessor. Examples: MOV A, B (move the contents of register B to register A) ADD B (add contents of registers A and B and s...