Here is the listing of Java programming examples on Event Handling.
1. Java Examples on Delegation Event Model
MouseEvents class extends Applet and implements both the MouseListener and MouseMotionListener interfaces. These two interfaces contain methods that receive and process the various types of mouse events. KeyListener interface is found in java.awt.event package. KeyListener is notified whenever you change the state of key. This section contains Java programs on handling mouseevent and keyboardevent.
Java Applet Programs to Handle MouseEvent
Java Applet Programs to Handle KeyBoardEvent
2. Java Examples on Handling Check Boxes
Checkbox class is used to create a checkbox. It is used to turn an option true or false. This section contains Java programs on get and set the state of checkbox. It also contains the lable of check box.
Java Program to Get the State of a Check Box
Java Program to Set the State of a Check Box
Java Program to Get the Lable of a Check Box
3. Java Examples on Handling a TextField
TextField class is a text component that allows the editing of a single line text. TextArea class is a multi line region that displays text. It allows the editing of multiple line text. It inherits TextComponent class. This section contains Java programs to create two text fields for entering name and password, password typed by user in text field should be hidden, displaying some texts in the frames with the help of labels, creating text fields and text areas, creates a text area and displays mouse event actions. it also contains programs on trapping the key codes and key names.
Java Program to Create Two Lables and Two Text Fields for Entering Name and Passwords. The Password Typed by the User in the Text Field is Hidden
Java Program to Display Text in the Frame by Overriding PaintComponent() Method of JPanel Class
Java Program to Display Some Text in the Frame with the Help of a Label
Java Program to Create a Text Area and Display the Mouse Event When the Button on the Mouse is Clicked, When the Mouse is Moved etc is Done by the User
Java Program to Create Some Text Fields and Text Areas to Demonstrate Features
Java Program to Trap the Key Code and Key Name Typed by the User on the KeyBoard and Display them in a Text Area
Java Program to Trap a Key Which is Pressed on the KeyBoard and Display its Name in the Text Area .In this Program, We Consider Some Keys Only for Demonstration Purpose
4. Java Examples on Menu Bars and Menus
Menu bar displays a list of top-level menu choices. Each choice is associated with a drop-down menu. Menu is a subclass of MenuItem. PopupMenu provides a flexible, useful alternative for some types of menuing situations. This section contains Java programs on creating a menu with several menu items, creating a menu and handling the file open event, performing menu driven arithmetic operations using switch cases. It also contains real time examples to display the languages menu bars with the help of frames.
Java Program to Create a Menu with Several Menu Items
Java Program to Create a Menu and Handle the File Open Event for the User
Java Program to Perform Menu Driven Arithmetic Operations Using Switch Case
Java Program to Create a Choice Menu with Names of Some Languages from Where the User has to Select Any One Item. The Selected Item Must Also be Displayed in the Frame
5. Java Examples on Applet Class
Applet is a special type of program that is embedded in the webpage to generate the dynamic content. It works on client side. Applet are mostly used in games, animation and images. public void paint is used to paint the Applet. It provides Graphics class object that can be used for drawing oval, rectangle, arc etc. Clock can be created by using the SimpleDateFormat class. java.awt.Graphics class provide a method drawImage() to display the image. This section contains Java programs on creating a basic applets, creating banners using applet, displaying clock and image using applets, creating event listener in applet, creating different shapes using applets graphics, read a file using applet, using swing applets in java and displaying human face using applets.
Java Program to Create a Basic Applet
Java Program to Create a Banner Using Applet
Java Program to Display Clock Using Applet
Java Program to Create Different Shapes Using Applet
Java Program to Fill Colors in Shapes Using Applet
Java Program to Goto a Link using Applet
Java Program to Create an Event Listener in Applet
Java Program to Display Image Using Applet
Java Program to Open a Link in a New window using Applet
Java Program to Play Sound Using Applet
Java Program to Read a File Using Applet
Java Program to Java Program for to a File Using Applet
Java Program to Use Swing Applet in JAVA
Java Program of an Applet that will Demonstrate a Basic Calculator
Java Program to Display Human Face using Applet
Java Program to Load and Display an Image Using Applet
Java Program to Find Square of a Given Number Using Applet
6. Java Examples on GUI
An API for providing a graphical user interface (GUI) for Java programs. Swing was developed to provide a more sophisticated set. This section contains Java programs on drawing text, line, solid rectangle and polygon using GUI. It also contain programs on displaying different shapes using GUI.
Java Program to Draw Text Using GUI
Java Program to Draw a Line Using GUI
Java Program to Draw a Polygon Using GUI
Java Program to Display Different Shapes Using GUI
Java Program to Draw a Solid Rectange Using GUI
7. Java Examples on Frame
Frame is an instance of the JFrame class, is a window that has decorations such as a border, title and supports button components that close the window. Applications with a GUI usually include at least one frame. WindowAdapter is an abstract class for receiving window events. All methods of this class are empty. DrawString is the method from Graphics class to generate text out in a Swing Window. This section contains Java programs on displaying colours in a frame, displays pie charts using frames, displays sting with some colors in frame, displays a message in new frame and closes the frame using WindowAdapter and anonymous class.
Java Program to Display Colours in a Frame
Java Program to Display a Pie Chart Using a Frame
Java Program to Display a Message in a New Frame
Java Program to Display String with Background Color as Cyan in a Frame
Java Program to Display Some Text in the Frame Using DrawString() Method
Java Program to Close the Frame Using WindowAdapter Class
Java Program to Close the Frame Using an Annonymous Class
8. Java Example on Fonts Working
AWT supports multiple type fonts. Fonts have a family name, a logical font name, and a face name. This section contains Java programs on displaying text in different fonts, changing the background colour of applet, changes the look and feel of components, create a dialog box and sets colors for the frames.
Java Program to Display Text in Different Fonts
Java Program to Change the Background Colour of Applet by Clicking on Command Button
Java Program that Changes the Look and Feel of the Component
Java Program to know Which Fonts are Available in a Local System
Java Program to Create a Color Dialog Box for the User to Select a Color from and the Selected Color is Displayed as Background Color for the Frame
9. Java Examples on Graphics
Graphics class defines a number of drawing functions. Each shape can be drawn edge-only or filled. Graphics are drawn relative to a window, graphics can be the main window of an applet. This section contains Java programs to print concentric circles, draw smiling face using graphics class, display several dots on the screen, display string in rectangle, creating a transparent cursor and jtree.
Java Program to Draw a Smiling Face Using the Methods of Graphics Class
Java Program to Display Serveral Dots on the Screen Continuously
Java Program to Print Concentric Circles
Java Program to Display String in a Rectangle
Java Program to Create a Transparent Cursor
Java Program to Check Whether Antialiasing is Enabled or Not
Java Program to Create a JTree with a Root Node and Other Nodes Spanning from Root Node
10. Java Examples on Handling Buttons
Each time a button is pressed, an action event is generated. Each listener implements the ActionListener interface. ActionEvent object is supplied as the argument to this method. The button class is used to create a labeled button that has platform independent implementation. This section contains Java programs on creating push buttons using flow layout manager, creating a frame with next and close buttons, program to create a tool bar with 3 push buttons. creating a push button, if we click that button image will display.
Java Program to Create a Group of Push Button and Arrange them in the Container Using Flow Layout Manager. The Buttons are Right Justified
Java Program to Create a Push Button and a Progress Bar, Such that Everytime the Button is Clicked by the User the Progress Bar Progresses by 5 Units
Java Program to Create a Frame ‘Frame1’ with Next and Close Buttons
Java Program to Create Frame2 With Back Button, such that When the User Clicks Back Button, Frame2 is Closed and we See the Frame1 Only
Java Program in Which We Create a Push Button with a Label andImage on it and then set Different Features for the Button
Java Program to Create a Push Button When the Button is Clicked an Image is Displayed in the Frame
Java Program to Create a Tool Bar with 3 Push Buttons Added to it .The Push Button are Created with Image to Denote New, Open and Print Options. When the User Clicks on Any Button, the Selcted Button is Displayed in the Label
11. Java Examples on Classes
Vector class implements a growable array of objects. The Java programs in this section illustrate the use of methods ov vector class, using of various methods of url class, verify the collection has same object and iterater subclass object.
Java Program to illustrate the Use of Methods of Vector Class
Java Program for Showing the Use of Various Methods of URL Class
Java Program to Verify that Collection has Same Object and Get the Iterater SubClass Object to Replace
12. Java Examples on Handling Scroll Bars & Lists
User interacts with a scroll bar, an AdjustmentEvent object is generated. getAdjustmentType( ) method can be used to determine the type of the adjustment. Toggle button is a two-state button that allows the user to switch on and off. To create a toggle button in Swing we can use JToggleButton class. This section contains Java programs on showing functioning of toggle button, creating a scrollbar and scroll buttons with ranging, creating a list boxes.
Java Program to Create a List Box with Names of Some Languages from Where the User can Select One or More
Java Program to Show the Functioning of a Toggle Button
Java Program to Create a Vertical Scrollbar with Scroll Button Length 30 px and With the Starting and Ending Positions Ranging from 0 to 400px
Java Program to Create a List Box with Names of Some Countries such that the User can Select any One of More Items from the List and the Selected Country Names are Displayed Again in the Frame
13. Java Examples on Handling Events by Extending AWT Components
This section contains Java programs on creating radio buttons, check boxes, push buttons and combo box. Creating a tabbed pane with two tab sheets, creating a split plane to divide frames into two parts horizantally.
Java Porgram that Creates 2 Radio Buttons ‘Yes’ and ‘No’. The User Selects a Button from them , and Display the Selected Button Lable
Java Program to Create Some Push Buttons Using JButton Class and Draw Different Borders Around the Buttons
Java Program that Helps in Creating some Check Boxes and Radio Buttons When the User on a Check Box or Radio Button the Selected Option Text will be Displayed in a Text Area
Java Program to Create a Tabbed Pane with Two Tab Sheets. In the First Tab Sheet, We Display Some Push Buttons with Names of Capital Cities. In the Second Tab Sheet, We Display some CheckBoxes with Names of Countries.
Java Program that Creates a Split Pane. Which Divides the Frame into Two Parts Horizontally. In the Left Part, We Create a Button and in the Right Part We Create a Text Area. When the Button is Clicked, the Text is Displayed Inside the Text Area
Java Program to Create a Combo Box with Names of Some Countries The User Can Select Any One Name from the List and the Selected Country Name is Displayed Again in the Frame