This repository contains Java code files created during my early learning journey. All files are aimed at practicing and understanding basic to intermediate Java programming concepts. Each file reflects a step in exploring and experimenting with Java, covering foundational topics and exercises for learning purposes.
-
EventObject.java: Demonstrates handling action events in Java Swing. Contains three buttons, each displaying a message when clicked to indicate which button was pressed.
-
ExceptionMessage.java: A program that prompts the user to enter a filename. It attempts to open the file and displays an error message if the file is not found.
-
Fact.java: Calculates the factorial of a number using recursion. This program demonstrates basic recursion concepts by finding the factorial of a given integer.
-
GridPanelWindow.java: Shows how to use a
GridLayout
in Java Swing. This program arranges six buttons and labels in a 2x3 grid layout within a JFrame. -
ListWindow.java: Demonstrates the use of
JList
to display a list of months. When a month is selected, it is displayed in a text field below the list. -
MenuWindow.java: Illustrates creating a menu bar with options to change text color and visibility. The menu allows users to set the text color or hide it using menu items.
-
MetricConverter.java: A simple metric converter that converts kilometers to miles, feet, or inches. The user enters a distance in kilometers and selects the unit for conversion.
-
MultipleIntervalSelection.java: Demonstrates multiple selection in a
JList
. The program allows users to select multiple months from a list, and displays the selected months in another list. -
MyCatImage.java: Displays a GUI with a button that changes the background color when clicked. It has a sample image icon and a placeholder for loading an external cat image (if available).
-
ParseIntError.java: Shows how to handle
NumberFormatException
. The program attempts to convert a non-numeric string to an integer and catches the exception if the conversion fails. -
RangSum.java: Uses recursion to find the sum of a range of elements in an array. This program takes an array of numbers and calculates the sum within a specified range.
-
ReadBinaryFile.java: Reads integers from a binary file
Numbers.dat
and displays them. The program usesDataInputStream
to read data and handles the end of the file withEOFException
. -
ReadRandomLetters.java: Demonstrates random access to read specific characters from a binary file
Letters.dat
. The program seeks different positions in the file and reads characters. -
SalesReport.java: Reads monthly sales data from a file and calculates the total and average sales. Handles non-numeric data and informs the user if there is an error in the file.
-
StackTrace.java: Demonstrates how a
StackTrace
works by creating an intentional error. It tries to access a character out of bounds in a string and displays the stack trace. -
TempConverter.java: A temperature converter GUI that converts Celsius to Fahrenheit. Includes a slider to adjust the Celsius value and dynamically displays the Fahrenheit equivalent.
-
TextArea.java: Shows how to use
JTextArea
with a scroll pane in Java Swing. The text area allows multi-line text input, with line wrap enabled and a scroll bar. -
WriteBinaryFile.java: Writes an array of integers to a binary file
Numbers.dat
usingDataOutputStream
. This program demonstrates writing data to a binary file. -
WriteLetters.java: Writes characters from 'a' to 'z' into a binary file
Letters.dat
usingRandomAccessFile
. Demonstrates basic file writing and data persistence. -
openFile.java: Prompts the user to enter a filename and attempts to read and display its contents line by line. If the file is not found, it displays an error message.