Java Tutorial

by Dinesh Thakur Category: Swing

A JPanel is an invisible window on which they are located and arranged the elements in the window. We can insert any type of components within a panel, including other panels. This feature is essential when creating complex graphical interfaces you have to use different Layout Managers.

 
by Dinesh Thakur Category: Swing

JFrame: Represents a basic, capable of containing other components window. Almost all applications built one JFrame. 

 
by Dinesh Thakur Category: Swing

The CardLayout constitutes a more enhanced manager that can group multiple containers in the form of cards each showing a time, or that is, only one container at a time is visible. This layout manager is based on the idea of ​​the tabs. Each container can have its layout specific, allowing different layout managers are used in a same window space.

 
by Dinesh Thakur Category: Swing

The GridLayout manager is one that divides a container into a set of cells spread on a rectangular grid , so that they all possess the same dimension. You can split a container into rows and columns according to their need . The components are arranged in the order in which they appear, with inserted in the grid from left to right and top to bottom.

 
by Dinesh Thakur Category: Swing

The FlowLayout is the simplest manager. The components are arranged from left to right in the order in which they appear, i.e., in the order they are added. When there is no more space on a line, another line is created, resembling a text editor. This process is automatically done according to the container size.

 
by Dinesh Thakur Category: Swing

The BorderLayout manager is one that divides a container into five regions distinct : north ( upper region ) , south ( lower region ) , west ( left region ) , east ( right region ) and center ( central region ) . Unlike managers seen previously, the order in which the components are added is irrelevant , because at the time we add the component , in which we define the region it will stay. In each region, managed to put only one component , or is, only five (5) components may be included in this layout. if an component is inserted in a region that already contains another , this will be overlapped. Likewise the grid layout, the components are resized according to the dimensions of the container.

 
by Dinesh Thakur Category: Swing

Frame is the most common container used to create top-level window having title, border and window-management buttons. It can also be used to create secondary windows for an application. A frame is an object of JFrame class.

 
by Dinesh Thakur Category: Swing

The flow layout manager is the simplest of all the layout managers. It positions the components in the order they are added to the container. It places the components from left to right, that is, horizontally. Once a row gets completely filled with components then the remaining components are placed in the next row. It is the default layout manager for Applet and Panel. Each component is evenly separated from its neighboring components by leaving a small space not only from above and below it, but also from left and right.

 
by Dinesh Thakur Category: Swing

In a Java Swing, A JFrame is the class that represents the window in which graphics applications running on Java. JFrame Class is the top-level container that contains content pane all visible components contain in the content pane. The usual procedure to be used to create a new class that inherits from JFrame. Normally JFrame's are used as primary containers, that is, not contained in other containers.

 
by Dinesh Thakur Category: Swing

Another approach for handling events is to create separate Listener class for each listener type.

For example : Suppose you want to create a frame window such that when the user clicks in it, the coordinates of the clicked location relative to the left comer of the window are displayed in the console window. For this, you have to create a separate Listener class (say MyMouseListener) that extends the MouseAdapter class and define the mousePressed () method which is triggered and remaining do nothing methods are inherited from the MouseAdapter class.

 
by Dinesh Thakur Category: Swing

Anonymous inner classes can also be used to provide a similar facility as that provided by inner classes.

 
by Dinesh Thakur Category: Swing

The most common use of inner classes is with event handling. An inner class can be used to implement a particular listener interface or to subclass a particular adapter. This has the benefit of separating out the control aspect of the interface from the display elements. It also means that the event handler inner class can inherit from a different class to the encompassing class.

 
by Dinesh Thakur Category: Swing

The listener class that implements the Listener interface must provide bodies for all of the methods of that interface. It is not a problem for all the semantic listener interfaces such as ActionEvent, ItemEvent, TextEvent, AdapterEvent as each of them declares only one method. However, for all the low-level listener interfaces where each interface contains multiple methods, implementing each method can be somewhat tedious, especially when we have to define methods in which we are not interested. For example: Suppose we are interested in setting up only one listener interface method windowClosing() of the WindowListener interface that causes the program to terminate. In that case, we would not only need to provide code for windowClosing() method but also need to write empty bodies for the other methods available in the WindowListener interface.

 
by Dinesh Thakur Category: Swing

Focus events occur when a component gains or loses keyboard focus. Objects representing focus events are created from FocusEvent Class. The corresponding listener interface for FocusEvent Class is FocusListener interface. Each listener for FocusEvent should implement the FocusListener interface.

 
by Dinesh Thakur Category: Swing

Window event occurs when window related activities such as closing, activating or deactivating a window are performed. Objects representing window events are created from WindowEvent class. The most common method of this class is

 
by Dinesh Thakur Category: Swing

Key events occur when a key is pressed, released or typed on a component. Objects representing key events are created from KeyEvent class. The corresponding listener interface for KeyEvent class is KeyListener. Each listener for KeyEvent should implement the KeyListener interface. The KeyListener interface defines three methods.

 
by Dinesh Thakur Category: Swing

Mouse event occurs when a mouse related activity is performed on a component such as clicking, dragging, pressing, moving or releasing a mouse etc. Objects representing mouse events are created from MouseEvent class.

 
by Dinesh Thakur Category: Swing

Item events occur when a user selects a choice item, a checkbox menu item or a list item. Objects representing item events are created from the ItemEvent class.

 
by Dinesh Thakur Category: Swing

The action event occurs when you perform an action on a component such as clicking a button, double clicking a list item, selecting a menu item etc. Objects representing action events are created from ActionEvent class.

 
by Dinesh Thakur Category: Swing

Event: An event is a signal to the program that something has happened. It can be triggered by typing in a text field, selecting an item from the menu etc. The action is initiated outside the scope of the program and it is handled by a piece of code inside the program. Events may also be triggered when timer expires, hardware or software failure occurs, operation completes, counter is increased or decreased by a value etc.

 


About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.