java

Creating Sleepy Face in Java

Submitted by mehfuza on
In this tutorial we will learn to create a simple face(only eyes) which change when sleep button or wakeup button is clicked. This Application has two JButtons and a Panel for displaying the face. This Application handles Action Events for the buttons. In all we will create three class to make the design simple and clear.

Part 1: Creating a Class FacePanel for drawing face

Step 1: This class is used to draw the face based on whether the face is awake or asleep. For that we require a boolean variable awake which is set false initialy.

Converting Java Applet to Application

Submitted by mehfuza on
Applets are programs which run on web browser and Application means the stand alone program in a computer. In Java we can convert Applets to Application and Application to Applet. Using this idea we can make any program run as either applet or as an application. Following are the steps for converting applets to Application. Step 1: Change init() method's name to the constructor. Java Applets contains init() method which is used for initializing the applet, this method should be changed to constructor for that class.

Creating simple Calculator in Java

Submitted by mehfuza on

Introduction

This tutorial is about creating simple calculator which performs only four operations. For creating a simple Calculator we require two JTextFields where the user can enter two numbers, four JButton for four operations namely addition, subtraction,multiplication and division, a JLabel for displaying the result.

Implementation

Step 1: Creating a class which extends JFrame because we are going to create an Application. After this we have to define the constructor of the class as follows. Super() is used to give title to the frame.

Creating a Simple Paint Program in Java

Submitted by mehfuza on
Introduction In this tutorial, a simple Paint program is created, which enables us to draw anything to screen. It's a basic program to understand the logic behind creating a paint program. Here main concept is implementing MouseMotionListener which handles mouse events. Whenever mouse is dragged a mouse event is sent to Java which finds the event listener in the program in order to take any action. We need to implement only mouseDragged() of many functions of MouseMotionListener class to draw to the Panel.

Word Counter in Java

Submitted by tutgeeks on
Here is a Java program I made in Java that counts the number of words and number of lines in of an inputted String. Check this out! import java.util.Scanner; public class PrintPerWord { public static void main(String[] args) { Scanner read = new Scanner(System.in); String myString = new String(); System.out.print("Please enter any string: "); myString = read.nextLine(); int line = 0, let = 0, size

Easy Way to implement A Dynamic Clock in Java using Threads

Submitted by mehfuza on
Introduction: In this Tutorial, creation of clock which updates every second is explained. Here we create an Application for clock. It shows Hour, minutes and seconds which updates every second. Main Idea: The Dynamic clock can be created using Java's Timer thread but here we will see how to use our own thread and accomplish the task. This tutorial can clear any doubts you have in Java Threads.

Palyndrome in Java

Submitted by tutgeeks on
This code will show you if the word is Palyndrome or not. import java.util.Scanner; public class Palyndrome { public static void main(String[] args) { Scanner read = new Scanner(System.in); int ctr = 0; System.out.print("Enter any string: "); String str = read.next(); if(str.length()+1>3) { for(int x=0,y=str.length()-1;x

Registration Simulator

Submitted by blackwoods on
I'm not pro, I'm still a beginner so if you find somethin' that is wrong in my code, please don't hesitate to correct it. Just tell me so that I'll know what should i do. Here's a code, that resembles a registration simulator. It organizes the name, that you enter in the proper case as well as the location.