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 का प्रयोग आवश्यक है।

No comments:

Post a Comment

📚 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...