Java Code Snippet Index

Sample code for taking user input from Shell

Sample code for taking input from Shell demonstrating string and int input For simple programs or testing purpose its not always required to take input thru GUI. (Read More)

Need Additional Code

The program will give the following output 55 45 36 28 21 15 10 6 (Read More)
1

How to create a login form in javax.swing

Hi, This will show you how to create a login form using swing. Please be aware that this form does not connect to anything. ( eg. A URL or a database) This is just a little advanced example of one of the many things you can do in swing. A working example of this script can be... (Read More)

Problem in working with images in swing

I am using this code for displaying images on JPanel, in which i succeeded, but the images are volatile. When i maximize or minimize the frame, it vanishes. (Read More)

Program to find out whether a word is a 'Magic Word' or not

This code snippet allows you to know whether a word/sentence you have entered is a 'Magic Word' or not. A 'Magic Word' is a word which has at any position two consecutive letters. This can be achieved by taking the ASCII values of the characters. For example, if I enter "all the best", the... (Read More)

Day of the week GUI

This is my first GUI program in Java. If finds the day of the week for any given date which is after 1 January 1900. (Read More)

naval battle game

Hello... This is my naval battle game so far.. Just search i t if you're unfamiliar with the game it is only player vs computer.. can you adjust/fix my code so that: -the player is able to place his ships by means of dragging the JLabel ships at the left to the playing area... (Read More)

Capture and save an image of the screen

The code below captures the screen and saves it. Depending on your need, you can modify it to do just what you want import java.awt.AWTException; import java.awt.Robot; import java.awt.Rectangle; import java.awt.Toolkit; import java.awt.image.BufferedImage; import java.io.*; import... (Read More)
1

Generating a basic Fractal.

This is a very basic implementation of a Julia Set Fractal Generator. All of the variables are coded in, so feel free to change them to experiment with different results. I give an explanation of Complex Numbers and the Complex Plane, but you should look it up for your self, as I only go a little... (Read More)
-1

Tic - Tac - Toe Application

The source of my COPYRIGHTED tictactoe java game. It shows how to use multiple classes, methods, etc. (Read More)

decimal to hexadecimal

/** * @(#)dayau_0.java * * dayau_0 application * * @author * @version 1.00 2009/9/28 */ public class dayau_0 { (Read More)

Hello World

Seriously, what is any programming language without a HelloWorld app? (Read More)
6

JME(J2ME) Splash Screen

Here is simple example of static image to be displayed as logo on the start-up/splash screen. This can be improved by creating animation out of series of images or use of flash file through Project Capuchin library. As for location of image file this was placed in new folder called "res" as... (Read More)
3

Constructors & inheritance

I just wanted to demonstrate a quick point regarding Constructors & inheritance. Look at these two classes and think about what you might expect to see after the main method has run. Notice that ClassB is a subclass (inherits from) of ClassA. So, what do we expect the output to be? Here's the... (Read More)

Colour Box GUI

A program that creates a grid panel of desired dimensions and changes the colour randomly of each grid box upon dragging the mouse over the selected region. (Read More)
1

Simple Equation Solver

Solves simple string-based expressions. Currently only supports integers, but can easily be expanded to support float-types. (Read More)

Converting a decimal number to a binary number

This program converts any number that you enter to a binary number. For more information on binary numbers, visit: http://www.math.grin.edu/~rebelsky/Courses/152/97F/Readings/student-binary :) (Read More)

Date validation

Validation whether a string can be parsed to a valid date according to a supplied formatting string (which should conform to the formatting rules as supplied in DateFormat). This version can also flag dates in the past as error (we need that because many of our applications should accept only... (Read More)

A Simple Search Engine

This is a simple Search Engine that contains tokenized words as keys, in which they will return values associated with them in an ArrayList. All that is required is a text file from a valid extension. (Read More)

JAva Swing/SQL Server 2000 sending messages in a LAN

This prog uses SQL Server's Master Databases xp_cmdshell stored procedure (Shell Commands) to send messages in a LAN.Make Sure the driver name is 'netsend' and it points to Master Database. Check and change the username and passwords in the Java Program also.Make sure you have sufficient... (Read More)
1

A word displayed in descending order

This code snippet displays any word that the user enters in descending order, each time, removing the last charcter. So, sravan953 in descending order would be: sravan953 sravan95 sravan9 sravan srava srav (Read More)

Piglatin

Word: 'trouble' First vowel encountered: 'o' Therefore, the Piglatin version: 'oubletray' (From the first vowel till the last letter, concatenated with the first few letters which(or were not) left out, which concatenated with a standard 'ay') So, the Piglatin form of 'sravan953' would be:... (Read More)

Comparing numbers

This code snippet accepts a user-defined set of numbers, then accepts those many numbers, and displays the highest and lowest number. (Read More)

Simple Chatting (Beta ver ) Interface

Well , i have created a simple chatting interface . i would not call it a chatting interface actually cuz i had something else in my mind and finally landed on something else . i would like if you guys could excecute it and help me making it a real chatting interface . Well the basic thing... (Read More)

Word hunt

The program accepts a sentence, stores each word in it as a separate element in an array, then asks you for a word, and return whether or not the word is present in the sentence you entered. (Read More)

Sentence case changer

A java program which accepts a string from a user, and gives various options to change it case. Options include: UPPER CASE lower case Sentence case Title Case tOGGLE cASE (Read More)

CHESSBOARD using JAVA graphics

This particular snippet will display a chessboard in a new frame. Needless to say save it in a file named "chessboard.java". (Read More)

Heap sort

This is another sorting algorithm called heap sort that I wrote using Java programming language. The heap sort code is quiete complex but i tried my best to write it (Read More)

A CircularBuffer Data Structure--

I'm sure this has already been done, but to practice understanding Data Structures better I decided to try making one of my own, given only an idea of what type of functionality I want, a pencil and some paper (as well as .txt file, modified into a .java file =p ). The motivation of this... (Read More)

beep sound and with timer!

..this is a simple java code w/c allows to produce a beep sound. timer also is being applied here. hope it will help for any reason it may serve. :-) (Read More)

Birth DAY (of the week) finder

A program that finds the day of the week you were born on. Once again, this was adapted from a homework assignment, but I rewrote the entire thing from scratch >.< but it was a lot of fun. (Read More)

Penny Pitch Game

A JOptionPane version of the game of Penny Pitch. Uses numerical values spread on a board, and computer picks randomly chosen spot to place a penny and at the end of a run adds up the total score. *Two separate programs, PennyPitchGame and Square (Square Class)* (Read More)

“Left To Right” Principle

This program consists of a function in one class. It demonstrates the "Left To Right" Principle used by most of the languages. (Read More)

String Reverse using Stack

This code snippets shows how to reverse a string using a stack. (Read More)

Infix to Postfix

I have seen several posters asking for help on programs converting an Infix expression to a Postfix one. I have written a program to convert a simple Infix expression to a Postfix one so that people here can be directed towards some sample code from which they get the idea to writing one. I have... (Read More)

Farenheit to Celcius

Hi Dani, fine Examples (the others too) to learn programming Java, but where is the MyInput.java class? Thanks Eddi (Read More)

Seirpinski Triangle through Chaos Game

This is a simple implementation of the Chaos Game to produce a Seirpinski Triangle. (Read More)

Recursive AVL Binary Search Tree

This code demonstrates AVL insertion and deletion. The code was originally written in C by myself a little while back for a tutorial. The translation to Java was fairly trivial, and to add a little excitement I even threw in a few generics. Yes, I'm aware of this line: tree.data = heir.data; ... (Read More)

PrimeNumbers.java

This code enables the user to enter a number and finds the prime from 2 to the entered number..Please name it PrimeNumbers.java Hope it'll help u..:D (Read More)

Multi-line ToolTipText

Sometimes one line of tool tip is not enough. You may want to try and play around with JToolTip, but if you in hurry this "little hack" can be handy. With little of HTML plus CSS code you can work out various formats (font, colour, alignment, size etc.). (Read More)

Forum Tools


About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC