Posts

Showing posts with the label java graphics applet shapes

Java Graphics – Drawing Rectangles & Squares (drawRect & fillRect) जावा ग्राफ़िक्स में Rectangles (आयत) और Squares (वर्ग) बनाना

Java Graphics provides predefined methods to draw shapes like rectangles and squares. जावा ग्राफ़िक्स, रेक्टेंगल और स्क्वायर जैसी आकृतियाँ बनाने के लिए पूर्व परिभाषित मेथड प्रदान करता है। Java Graphics class provides two important methods: जावा ग्राफ़िक्स क्लास दो महत्वपूर्ण मेथड प्रदान करती है – drawRect(int x, int y, int width, int height) Draws an outline of a rectangle (only border). यह केवल रेक्टेंगल की आउटलाइन (बॉर्डर) बनाता है। fillRect(int x, int y, int width, int height) Draws a filled rectangle. यह भरे हुए रेक्टेंगल को बनाता है। Parameters / पैरामीटर्स x → Starting x-coordinate / प्रारंभिक x-निर्देशांक y → Starting y-coordinate / प्रारंभिक y-निर्देशांक width → Width of rectangle / रेक्टेंगल की चौड़ाई height → Height of rectangle / रेक्टेंगल की ऊँचाई 🖥 Example 1: Draw Rectangle using drawRect() import java.awt.*; import java.applet.*; public class DrawRectExample extends Applet { public void paint(Graphics g) { g....

Java Graphics: Drawing a Line with drawLine() जावा ग्राफ़िक्स: drawLine() मेथड से लाइन ड्रा करना

Java provides the Graphics class in the AWT package to draw 2D shapes like lines, rectangles, circles, and polygons. जावा AWT पैकेज में Graphics क्लास प्रदान करता है, जिसका उपयोग 2D शेप जैसे लाइन, रेक्टेंगल, सर्कल और पॉलिगन बनाने के लिए किया जाता है। The drawLine() method of the Graphics class is used to draw a straight line between two points. Graphics क्लास का drawLine() मेथड दो बिंदुओं के बीच एक सीधी रेखा खींचने के लिए प्रयोग किया जाता है। 📌 Syntax | सिंटैक्स void drawLine(int x1, int y1, int x2, int y2); x1, y1 → starting point of the line. x1, y1 → लाइन का शुरुआती बिंदु। x2, y2 → ending point of the line. x2, y2 → लाइन का अंतिम बिंदु। 💻 Example: Drawing a Line in Applet ऐपलेट में लाइन ड्रा करना import java.applet.Applet; import java.awt.*; public class DrawLineExample extends Applet { public void paint(Graphics g) { g.setColor(Color.RED); // Set line color g.drawLine(10, 20, 200, 100); // Draw line from (10,20) to...