Showing posts with label Java Applet in Hindi. Show all posts
Showing posts with label Java Applet in Hindi. Show all posts

Friday, August 1, 2025

Taking Input from User in Java Applet जावा एप्लेट में यूजर से इनपुट ग्रहण करना

Java Applets allow user input through components like TextFieldLabel, and Button.

जावा एप्लेट में यूजर इनपुट को प्राप्त करने के लिए TextFieldLabel, और Button जैसे कंपोनेंट्स का उपयोग किया जाता है।

To use them, we first create their objects and add them using the add() method.
इनका प्रयोग करने के लिए पहले इनके ऑब्जेक्ट बनाए जाते हैं और add() मेथड से एप्लेट में जोड़ा जाता है।

📌 Component Declaration Format कंपोनेंट डिक्लेरेशन प्रारूप:

TextField object_name = new TextField(size);  
Label label_object_name = new Label("label_name");  
Button button_object_name = new Button("button_name");

🔧 Example: Taking two inputs and displaying total दो इनपुट लेकर कुल मान प्रदर्शित करना

// File: ThreeControlApplet.java  
import java.awt.*;  
import java.applet.*;  

public class ThreeControlApplet extends Applet {  
    TextField txtBox1 = new TextField(10);  
    TextField txtBox2 = new TextField(10);  
    TextField txtTotal = new TextField(10);  

    Label lblLabel1 = new Label("First Value");  
    Label lblLabel2 = new Label("Second Value");  
    Label lblTotal = new Label("Total");  

    Button OKButton = new Button("Calculate");  

    public void init() {  
        add(lblLabel1);  
        add(txtBox1);  
        add(lblLabel2);  
        add(txtBox2);  
        add(lblTotal);  
        add(txtTotal);  
        add(OKButton);  
    }  
}

🧾 This applet displays input fields and a button, but you must add event handling using ActionListener for full interactivity.
🧾 यह एप्लेट इनपुट फील्ड्स और बटन तो दिखाता है, लेकिन पूरी इंटरैक्टिविटी हेतु ActionListener का प्रयोग आवश्यक है।

Tuesday, July 29, 2025

Displaying Numeric Values in Applet एप्लेट में संख्यात्मक मान प्रदर्शित करना

In Java applets, numeric values are displayed using the drawString() method from the Graphics class.

जावा एप्लेट्स में संख्यात्मक मानों को ग्राफ़िक्स क्लास की drawString() मेथड का उपयोग करके प्रदर्शित किया जाता है।

To do this, the numeric value must first be converted into a string using the String.valueOf() method.
इस कार्य को करने के लिए, संख्यात्मक मान को पहले String.valueOf() मेथड की सहायता से स्ट्रिंग में बदला जाता है।

🧪 Example: Displaying sum of two numbers  दो संख्याओं का योग दिखाना

// Java File: temp.java  
import java.awt.*;  
import java.applet.*;  

public class temp extends Applet {  
    public void paint(Graphics g) {  
        int x = 10;  
        int y = 25;  
        int add = x + y;  
        String s = "add: " + String.valueOf(add);  
        g.drawString(s, 100, 100);  
    }  
}

🖥️ HTML File to load applet एप्लेट लोड करने हेतु HTML फाइल:

<html>
    <body>
        <applet code="temp.class" width="600" height="400"></applet>
    </body>
</html>

☕ जावा एप्लेट क्या है? What is Java Applet?

Java Applet एक छोटा Java प्रोग्राम होता है जो ब्राउज़र पर रन करता है। इसे HTML डॉक्यूमेंट में <applet> टैग द्वारा जोड़ा जाता है।

Java एप्लेट का कोड .class फाइल में सेव होता है और जब यूजर HTML फाइल खोलता है, तो यह कोड क्लाइंट ब्राउज़र पर लोड होता है।


🔁 Java Applet का जीवन चक्र (Applet Life Cycle)

मेथड उद्देश्य (Purpose)

init() प्रारंभिक सेटअप, जैसे बैकग्राउंड कलर

start() एप्लेट का सक्रिय होना

stop() जब यूजर पेज छोड़ता है, एप्लेट रुक जाता है

paint(Graphics g) आउटपुट को स्क्रीन पर प्रदर्शित करना

destroy() ब्राउज़र बंद होने पर एप्लेट को समाप्त करना

🔧 उदाहरण (Examples)

उदाहरण 1: Basic Applet

Java File: photo.java


import java.applet.Applet;

import java.awt.*;


public class photo extends Applet {

    public void init() {

        setBackground(Color.red);

    }

    public void paint(Graphics g) {

        g.drawString("Applet is running", 30, 30);

    }

}

HTML File:


<!DOCTYPE html>

<html>

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

<body>

<applet code="photo.class" width="300" height="300"></applet>

</body>

</html>

⚠️ नोट:

<applet> टैग HTML5 में सपोर्ट नहीं करता। इसके स्थान पर <object> या <embed> का प्रयोग करें।


उदाहरण के लिए:


<object code="photo.class" width="300" height="300">

Your browser does not support applets.

</object>

📢 निष्कर्ष (Conclusion)

HTML और Java Applet का संयोजन उपयोगकर्ता को वेबपेज पर डायनामिक और इंटरैक्टिव कंटेंट प्रस्तुत करने की शक्ति देता है। हालांकि <applet> टैग अब पुराना हो चुका है, लेकिन यह अभी भी जावा सीखने वाले विद्यार्थियों के लिए उपयोगी तकनीक है।


📚 Other Stream Classes in Java जावा में अन्य स्ट्रीम क्लासेस

In Java, apart from basic byte and character streams, there are several specialized stream classes that provide advanced input-output operat...