Tag: Java

Java Program to Draw Star Shapes

This Java program creates a simple graphical application that draws rows of stars using Java’s Swing library. The program creates a window with rows of stars drawn on it. The Star class defines the shape of a star, the StarPane class handles the drawing logic, and the StarApplet class sets up the main frame for the application. This example showcases basic GUI programming with Swing.

Read More

Interactive Java Stopwatch Component

The StopWatch class introduces a versatile stopwatch component with enhanced functionality in Java. Extending JLabel and implementing the MouseListener interface, this interactive component not only measures elapsed time but also dynamically updates to display the current time in the format “Hours:Minutes:Seconds:Milliseconds”.

Read More

Java Code to Demonstrate Recursion

The Java code implements a simple graphical application that visually represents and counts blobs within a grid by using recursion. A blob is a group of adjacent filled squares in the grid. The application uses Java Swing for creating the graphical user interface (GUI) components. It includes buttons for generating a new set of blobs, counting the number of blobs, and a grid where users can click to get information about the blob size at that specific position. This Java code uses recursion in the getBlobSize method to calculate the size of a blob.

Read More

A Java Application for Two-Way Chatting

This Java Code supports two-way chatting between users. It implements a client for the ConnectionBroker server, which can set up a relayed connection between a pair of such clients. There are really two functions: The user can register with the server as a client who is willing to accept a connection, or the user can make a connection with one of the clients who is waiting on the server. The code retrieves and displays a list of waiting clients when it starts. There is a Refresh button that the user can click to refresh this list (since the list of waiting clients can change from time to time).

Read More