AWT Components in Java

The Abstract Window Toolkit (AWT) is Java’s original platform-dependent windowing, graphics, and user-interface widget toolkit preceding Swing.AWT Components in Java

Create MenuBar, Menu Items, Menus Java Example

Menus Java are a number of pull-down combo boxes (In Java called as Choice) placed at single place for easy selection by the user. To create menus, the java.awt package comes with mainly four classes – MenuBar, Menu, MenuItem and CheckboxMenuItem. All these four classes are not AWT components as they are not subclasses of …

Create MenuBar, Menu Items, Menus Java Example Read More »

Radio button and Radio button group

1. What is Radio button? Infact, there is no radio button class in Java. Radio buttons are nothing but checkboxes only but grouped as one unit. 2. What the advantage of grouping checkboxes? Once grouped, in the group if one checkbox is selected, the other gets automatically deselected. This is the only advantage. Sometimes, it …

Radio button and Radio button group Read More »

Java Button Example with ActionListener Event Handling

A simple Java Button Example given to understand how to create components and link to event handling mechanism. User interface (communication-point) with a running Java program can be in two ways – using keyboard input and the other with GUI. Java supports GUI environment through GUI components like button, check box, radio button and menu …

Java Button Example with ActionListener Event Handling Read More »

Mouse Double Click Example Java

The code explains how to handle double clicks of mouse key. You even can handle triple clicks also, if required. Example on Mouse Double Click Example import java.awt.*; import java.awt.event.*; public class Demo extends Frame { Button btn; public Demo() { setLayout(new FlowLayout()); btn = new Button(“OK”); btn.addMouseListener(new MyListener()); add(btn); setSize(300,300); setVisible(true); } public static …

Mouse Double Click Example Java Read More »

Mouse Right Click Example Java

This Java code on Mouse Right Click Example explains how to handle the right clicks of mouse key. Mouse Right Click Example import java.awt.*; import java.awt.event.*; public class Demo extends Frame { Button btn; public Demo() { setLayout(new FlowLayout()); btn = new Button(“OK”); btn.addMouseListener(new MyListener()); add(btn); setSize(300,300); setVisible(true); } public static void main(String args[]) { …

Mouse Right Click Example Java Read More »

Java AWT CardLayout Manager

After learning the basic layout managers (Flow, Border and Grid), let us study the advanced layout managers – CardLayout and GridBagLayout. These two managers are used in specific cases, but not often, where basic layout managers with panel combinations fail to fulfill the layout requirements. Layout management is the procedure of deciding the size and …

Java AWT CardLayout Manager Read More »

Java Create Random Color

We know using java.awt.Color class, different colors (nearly 16 million shades) can be created and applied to graphics or components. Using java.util.Random class, various colors can be produced randomly and applied to any component. In the following program, each button click gives different color to the frame. For generating colors randomly, here we use java.util.Random …

Java Create Random Color Read More »

TextField Applet Adding Two Numbers

After validating user name and password using TextField in an application (application extends frame), let us rewrite the same program using applets but with a different functionality. We take two numbers from the user and display the sum of two numbers. The following program comes with 3 text fields. In two text fields, user enters …

TextField Applet Adding Two Numbers Read More »

Java Component Preferred Size

To develop user friendly and good look environment, the layout of the components in a container is very important to the programmer like the selection of colors and fonts for graphics. The user should feel free and comfortable to stay some time in GUI. To give attractive graphical user interface design, the AWT package comes …

Java Component Preferred Size Read More »