Java

Styling Java Buttons & Labels with HTML tags

Submitted by mehfuza on

Introduction:

Java buttons and labels support using different HTML (Hyper Text Markup Language) tags. HTML is Web page development language where as Java is Programming language but still Java executes the HTML tags and displays the output according to the HTML tags. These tags can be used to insert new line on the button or labels or styling the text on the buttons and labels. Text Area does not support executing HTML tags it displays the tags as it is. Buttons and label support following HTML tags.

Tags Supported by Labels and Buttons

1.

Cursor and Combo Box Demo in Java

Submitted by mehfuza on

Introduction:

In this tutorial we will see changing cursor when it is selected from Combo Box in Java. You will learn about cursor as well as JComboBox. The position of the mouse is represented on the computer's screen by a small image called a cursor. It has a hot spot, which is a Point that specifies the pixel within the image that corresponds to the exact point on the screen where the mouse is pointing. The Cursor class has many predefined cursor which can be used with Cursor.getPredefinedCursor(code) method. Where code represent type of cursor.

Simple Image Viewer in Java

Submitted by mehfuza on
Introduction In this tutorial we will learn how to display picture in Java Application. There is difference between how a picture displayed in application and applet. For application we require drawImage() method which draws the image to specific component and not the entire frame. Implementation Step 1: Creating the components We require a label, text field where user will enter name or address

Creating Executable Program in Java

Submitted by mehfuza on
Executable software can be created using JAR(Java Archive) utility. Once you create jar file of the program it can run on any machine having JRE(Java Runtime Environment ) installed. JAR file should contain the .class files and resource such images, audio or any other files required. Including only .class files makes the code private. It can also include .java files, the source code of the program. Following are the commands to be run at Command Prompt or Terminal in Linux. Step 1: Compiling the Java Programs First compile all the Java programs of an application.

Simple Editor in Java

Submitted by mehfuza on

Introduction

This simple editor has only one menu with New, Open, Save, Exit option. It requires JMenuBar, JMenu, JMenuItem, ActionListener, File related classes. This tutorial demonstrate creation of menu and reading and writing the files. Once user clicks on open menu then Open dialog box is displayed and File is displayed in the display area. This simple editor can be created easily with following steps. File reading and writing part is similar to previous tutorial.

Implementation

Step 1: Designing the Menu The class is application so it extends JFrame.

Simple Web Browser in Java

Submitted by mehfuza on
In this tutorial we will see how to create a simple web browser. It contains an address bar where a user can type the address and a go button which when clicked loads the web page. For displaying the web pages we require JEditor Pane and HyperlinkListener is required to respond when the user clicks on a link in the document. Following are the steps for creating the web browser. Step 1: Defining the constructor of the class The main class extends the JPanel.

Reading from and Writing to a Text File in Java

Submitted by mehfuza on
Introduction: This tutorial demonstrate the method of reading from and writing to a text file in Java. Java has two type of files: Binary and Text. Text file is processed as a sequence of characters where as Binary file is processed a sequence of bytes. This application has 4 JButtons for reading, writing, exiting, and clearing the Display Area. Also It has a display area where we can type the data to be written to text and in the same area content from file are displayed. Step 1: Creating GUI Components Create the four buttons, label, text area and text field.

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.

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.