0% found this document useful (0 votes)
197 views

Java Foundation Class (JFC) : Features and Terminologies of GUI

The document discusses features and terminologies related to graphical user interfaces (GUIs). It describes that a GUI consists of visual components like frames, buttons, checkboxes that allow user interaction. These components are arranged using layout managers and painted on the screen by the event dispatch thread. It then discusses key Java classes for developing GUIs like the Abstract Window Toolkit (AWT), Swing, Java 2D and accessibility APIs. It explains differences between AWT and Swing, with Swing providing more powerful and lightweight components. The document outlines the container hierarchy in Swing applications and describes the key JComponent class.

Uploaded by

Viraj Salunkhe
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
197 views

Java Foundation Class (JFC) : Features and Terminologies of GUI

The document discusses features and terminologies related to graphical user interfaces (GUIs). It describes that a GUI consists of visual components like frames, buttons, checkboxes that allow user interaction. These components are arranged using layout managers and painted on the screen by the event dispatch thread. It then discusses key Java classes for developing GUIs like the Abstract Window Toolkit (AWT), Swing, Java 2D and accessibility APIs. It explains differences between AWT and Swing, with Swing providing more powerful and lightweight components. The document outlines the container hierarchy in Swing applications and describes the key JComponent class.

Uploaded by

Viraj Salunkhe
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 8

features and terminologies of GUI

GUI stands for Graphical User Interface. GUI consists of what the user sees on the screen and code to process users action such as clicking of mouse or typing on the keyboard. interactive input and output All passes through the GUI. GUI is made up of one or more component as frame, buttons, checkboxes, such radio buttons, list boxes, dialogs boxes, Windows etc. Every GUI based application haves one main container window which holds other components. In Java this window can be Frame or Applet. Such a window have title bar. border, buttons for closing, maximizing, minimizing the window Application can have components which are used to perform some action. These components are not a container and thus can not hold other components, e.g. Label, List boxes. Combo boxes. Text Fields etc. In GUI based application, there is zero or more sub-container which resides on main container and used to hold the other components, eg. JApplet ,JPanel, JDialog etc. There are some schemes to lay out the components in the display area of the container. Such .schemes called as Layout Managers. Layout are Manager provides a way to arrange the components in the container, Apart from adding the components, one can draw the custom drawing on the display area. One can achieve Graphics Context to draw the Lines, Images, and Pictures etc. In GUI every component is drawn and painted when the application for that GUI starts. This painting of componentsis handled by separate thread called Event Dispatch Thread. Every GUI must respond to the user's action for that GUI must support event handling. In eventhandling mechanism, oneor more components generate the event and there are one or more Listeners are registered to handle these events. These listeners provide the methods to handle These events and perform some action.

Java Foundation class (JFC)


JFC stands for Java Foundation Classes. JFC provides set of classes which is useddevelop and to simplify the developments of 100% pure Java programs. JFC provides the classes for developments of Java programs for networks and standalone environments. It also provides the classes to change the look and feel of the components. Java Foundation classes are grouped in to five Application Programming Interface(APIs). These are follows: as 1 The Abstract Windowing Toolkit(AWT) :The abstract windowing toolkit API was the original toolkit for developingGUIs for the Java platforms. It provides the foundation for theJFC with its support to colors, fonts, graphics, images, events, listeners , layout Manager and so forth 2 Swings Swing is a extension to the AWT components which provides feature pluggable of look and feel for the components. It provides a classes design lightweight components. to 3.Java 2D The Java2D API provides variety of painting styles and features for defining complex shapes and controlling the rendering process. Ii provides enhanced Font and drawing capabilities 4 Accessibility The accessibility API provides an interface that allows assistive technology such as screen readers, screen magnifiers and speech recognition software to be easily integrated in to application. 5 Drag and DropThe Drag and Drop API provides the ability to move the data between program created with the Java programming Language with the application created with other programming language, it provides interoperatibility bet ween the application a

Swing
Swing is a set of classes that provides more powerful and flexible components than are possible with the AWT.Swing components are not implemented by platform-specific code. Instead, they are written entirely in Java and, therefore, are platform-independent. The term lightweight is used to describe swing elements, whereas AWT components are dependent on the operating system that is why they are known as heavyweight components.

Difference between AWT and Swing API


In AWT it is very difficult lo create a custom component by directly subclassing Component or Container classes because to create a custom component you must create a peer class for that component. Maximum swing components build upon lightweight component, so there is no need to develop a peer component while creating a custom component by using Swing, Swing component do not need native support so these components are independent of native operating system. Such a component need not any native code for processing. Swing components are 100% pure Java components. The code of swing programs is consistent across multiple platform. Swing API builds upon AWT API so not all Swing components are lightweight component.

Some swing components are heavyweight component eg. JApplet, JDialog. J Frame these entire components have a native support and these components are directly derived from its AWT counterparts. . Swing components have pluggable look and feel means these components looks similar in any operating system. They are adaptable to all operating system. Swing API provides set of classes and interfaces to develop 100% pure Java Programs. All these classes starts with the letter J. Some classes provides additional methods to develop a attractive GUI. Swing you can provide Tool tip text to every component by using method setToolTipText(). You can add images and pictures in almost all swing components of swing by using setlcon() method In Swing all components are added on Glass pane, in swing we can not add components directly on main container. In swing components like JTextArea and JList does not have in-build scroll bars, to give scroll bars to such a components we must enclose these components in the JScrollPane. All Swing components follows Model View Architecture (MVC) design pattern in which manipulation of data is separate from rendering and drawing of the component

Container hierarchy of the Swing Application


Every Swing application is a set of heavyweight component and lightweight components. Each Swing application requires at least one heavyweight container, In Swing application we cannot add component directly to the heavyweight container instead we add component to the Glass pane or Content Pane. Glass pane or Content Pane is a intermediate container which is used to place all the lightweight components. We can get object of Content pane by the method getContentPane( ). In Swing, menu bar is added to the heavyweight component and not to the Glass Pane.

JComponent class
JComponent is superclass for all swing components. It is a subclass of Java.awt.Container class which in turns subclass of Java.awt.Component class. It is an abstract class and you can not create a object of this class by using new operator. Package Methods Constructor : javax.swing JComponent( ) - Default JComponent constructor.

Name Description void addXXXListener(XXXListcner ohj) This method is used lo register a Listeners for a specific type of event with the component.

void repaint() void repaint(long msec) void repaint(int x.int y, int h, int w) void repaint(long msec,int x,int y, int h, int w) void setBackground(Color c) void setBorder(Border b) void setDoubleBuffered( Boolean b)

void setEnabled{Booiean b) void setFont(Font f) void selForeground( Color c)

void setPreferedSize(Dimension d)

void setSize(Dimension d) void setSize{int w.int h) void set ToolTipText() void setVisible(Boolean b) void update(Graphics context)

This method is used to repaint the current component. Second version repaints the components after specified no of millisecond. You can repaint the specific area of the component by using third version. This method is used to set the background color for the component. This method is used to set the Border for the Component. If we pass a true parameter, then this method allows the component to be painted in the offscreen buffer and paint it on the main screen when entire bytes are available. It is used to eliminate flickering effect of the screen. It is used to set any component enabled or disabled. It is used to set the font of the text appearing on the Component. This method is used to set the foreground color of the component. Foreground color is the color of text appearing on the component. This methods sets the ideal size for the component. It takes a parameter of type Dimension which can be created by passing the two integer parameters in the constructor of the Dirnesion class. You can set a size of the component by set size method. You can pass either Dimesion object as a parameter or two integer object which specifies width and height. This method is used to associate tool tip string with the component. You can set component visible or invisible by using this method. This method in turns calls paint method to paint the component.

2. container It is subclass of Component class. This represents a Container in which we can add different component. Container can have title, border, background color and size, java.awt Package: java.awt Constructor : Container()
Methods Name :

---default container constructor


Description This method is used to add a component to the Conaiiner. This methods adds the component to the container and it specify the position of the component in case of some .layout manager, eg. Border Layout. This methods returns a array of the Components added in the Container. This method returns a current Layout of the Container. This method removes the specified component from the container. This methods set the LayoutManager for the Conatiner. This method paints the component in the Container.

void add (Component comp) void add (Component comp. Object constraint)

Component [ ] getComponents( ) Layout Manager getLayout( ) void remove ( Component c) void setLayout( Layout Manager m) void paintComponent ( Graphics g )

JDialog : This class extends java.awt.Dialog class. Dialogs arc used lo accept some inputs from User. Default layout manager for JDialog class is BorderLayoui. Package : javax.swing Constructor : JDialog ( Frame parent) This constructor creales a new JDialog object which appears on specified parent Frame. JDialog (Frame parent, boolean modal): This constructor creates a new JDialog object which appears on the specified parent frame. If we pass second parameter as 'true' Ihen we can not work o the parent window when dialog is visible, such a Dialog boxes are called as Modal dialog boxes. If we pass 'false" then we can work on the parent window when dialog is visible such a dialog box is called as non-modal dialog box. JDialog (Frame parent. String title ) : This constructor creales a dialog box which have some title. JDialog ( Frame parcnl. Siring title. Boolean modal ) : This constructor creales a Dialog box which appears on specified parent by the user and modal or non-modal nature is specified. Methods Name void hide ( ) void show( ) Container getContentPane() void setLayout(LayoutManager) void setJMenuBar(JMenuBar) boolean isModal ( ) Descripjion This method is used to hide the Dialog box. 1 his method is used to show the Dialog box. This method returns , a JDialog Content Pane for the

'

frame, with title specified

I his method sets the LayoutManauer for the Dialog This method sets the J Menu Bar to the JDialog box This method checks whether the dialog is modal or non-modal

JFrame :
This class extends Java.aw t.Frame class. This object is a window with some title and Border. Frame can have menu bar.Every GUI based application of Swing have at least one JFrame object. Default layout for JFrame is BorderLay out. Package javax.swing

Constructor JFrame() This constructs a new frame that is initially invisible. JFrame(String title) This constructor a new frame that is initially invisible,with specified title. Methods
Container getContentPane() void setLayout(LayoutManager) void setJMenuBar(JMenuBar) This method returns , a Content Pane for the JFrame I his method sets the LayoutManauer for the JFrame This method sets the J Menu Bar to the JFrame

Void setIconImage(Image image) JPanel

Paints icon image on JFrame

This class extends Jcomponent class.JPanel object doesnot have its own window.It is always added to the window.One panel can have more than one panel in it.This is required to add component at proper

position and divide the screen into numbers of region.Default layout manager for panel is FlowLayout . Package:javax.swing Constructor: JPanel() This is default constructor for creating Panel. JPanel(LayoutManager lm) This constructor creates panel with layout manager specified Methods
Container getContentPane() void setLayout(LayoutManager) void setJMenuBar(JMenuBar) This method returns , a Content Pane for the JFrame I his method sets the LayoutManauer for the JFrame This method sets the J Menu Bar to the JFrame

oid setIconImage(Image image) void setl,ayout( Layout Manager m)

Paints icon image on JFrame Sets the layout for the frame

JButton Perpose ; This class is used to create a push buttons. Package : javax.swing Constructor JButton( ) Create a empty button having no title and icon. JButton(String str) Create a button having label. JButton(lcon i) Creates a button having icon image. JButton(String str, Icon i) Creates a button having siring label and icon image. Methods : This class is subclass of Abstract Button class. So it uses following important methods of abstract button class. Name void addActionlListenerfActionLislener obj) Siring geText() void set Text! (Siring s) void setHorizontalTextPosition(int pos) void selVcrticalTextPositionfint pos) void set lcon( Icon i) vois setMnemonic(char c) Description This method is used to register the push button to throw an event. This method returns the text associated with the button. This method is used to set new Label of the button Sets the horizontal text position relative to the graphics. Sets the vertical text position relative 10 the graphics. This method sets the Icon to the button Sets the mnemonic character to the button.

import java.awt.*; import java.awt.event.*; import javax.swing.*; /* <applet code="JButtonDemo" width=250 height=300> </applet> */ public class JButtonDemo extends JApplet implements ActionListener { JTextField jtf; public void init() { // Get content pane Container contentPane = getContentPane(); contentPane.setLayout(new FlowLayout()); // Add buttons to content pane

ImageIcon lotus = new ImageIcon("lotus.gif"); JButton jb = new JButton(Lotus); jb.setActionCommand("Lotus"); jb.addActionListener(this); contentPane.add(jb); ImageIcon rose = new ImageIcon("rose.gif"); jb = new JButton(Rose); jb.setActionCommand("Rose"); jb.addActionListener(this); contentPane.add(jb); // Add text field to content pane jtf = new JTextField(15); contentPane.add(jtf); } public void actionPerformed(ActionEvent ae) { jtf.setText(ae.getActionCommand()); } }

JLabel This class is used to create single line read only text which describe the other
component. Package : javax.swing Constructor JLabel() JLabel(String str) Jl.abel(lcon i) Jl.abel(String str,Icon Methods Name void set Horizontal Alignment(int a) String getText() void setText( String s) void set ion( Icon i) Description This method sets the alignment of the text. This method returns the text associated with the Label This method is used to set the text to the Label This method sets the Icon to the icon

Create a empty label having no text and icon. Create a label having some text. Creates a label having icon image. i) Creates a label having string text and icon image.

Icons

Icons are encapsulated by the ImageIcon class, which paints an icon from an image. constructors are ImageIcon(String filename) This constructor creates object with image which is specified by filename ImageIcon(URL url) This constructor creates object with image in the resource identified by url.

Method

int getIconHeight( ) Returns the height of the icon in pixels. int getIconWidth( ) Returns the width of the icon in pixels. void paintIcon(Component comp, Graphics g, int x, int y) Paints the icon at position x, y on the graphics context g. Additional information about the paint operation can be provided in comp.
import java.awt.*; import javax.swing.*; /* JAVA <applet code="JLabelDemo" width=250 height=150> </applet> */ public class JLabelDemo extends JApplet { public void init() { // Get content pane Container contentPane = getContentPane(); // Create an icon ImageIcon ii = new ImageIcon("Lotus.gif"); // Create a label JLabel jl = new JLabel("Lotus", ii, JLabel.CENTER); // Add label to the content pane contentPane.add(jl); } }

JCheckBoxse Package Constructor: This class is used to create check box with a text or icon. javax. swing JCheckBox() Create a empty checkbox having no title and icon. JCheckBox (String I) Create a checkbox having label. JCheckBox (Icon i) Creates a checkbox having icon image. JCheckBox (Siring I, Icon i) Creates a checkbox having string label and icon image. JCheckBox (String I. Icon I. boolean selected) Creates a checkbox having string label and icon image and default selected if true is passed. JCheckBox (String I, boolean selected) Creates a checkbox having string label and option for default selected policy.

import java.awt.*; import java.awt.event.*; import javax.swing.*; /* <applet code="JCheckBoxDemo" width=400 height=50> </applet> */ public class JCheckBoxDemo extends JApplet implements ItemListener { JTextField jtf; public void init() { JAVA // Get content pane Container contentPane = getContentPane(); contentPane.setLayout(new FlowLayout()); boxes to the content pane JCheckBox cb = new JCheckBox("Sandal"); cb.addItemListener(this); contentPane.add(cb); cb = new JCheckBox("Rose"); cb.addItemListener(this); contentPane.add(cb); cb = new JCheckBox("Lotus");

cb.addItemListener(this); contentPane.add(cb); cb = new JCheckBox("Mogara); cb.addItemListener(this); contentPane.add(cb); // Add text field to the content pane jtf = new JTextField(15); contentPane.add(jtf); } public void itemStateChanged(ItemEvent e) { JCheckBox cb = (JCheckBox)ie.getItem(); jtf.setText(cb.getText()); } }

JRadioButton

Purpose :

Package : Constructor:

This class is used to create radio button with a text or icon. Once a radio button is created they must be kept in one group,which is created by using the ButtonGroup class Radio buttons must be configured into a group. Only one of the buttons in that group can be selected at any time. javax.swing J RadioButton() Create a empty radio button having no title and icon.

JRadioButton (String I) Create a radio button having label.


JRadioButton (Icon i) Creates a radio button having icon image. JRadioButton (String I, Icon i) Creates a radio button having string label and icon image. JRadioButton (Siring IJcon I,boolean selected) Creates a radio button having string label and icon image and default selected if true is passed. JRadioButton (String I, boolean selected) Creates a radio button having string label and option for default selected policy. Button G roup This class is useful lo group the component such as radio buttons. If radio button is not grouped Then they work as checkbox. And multiple selection is possible. To avoid that we group the Radio button object. This class provides the default constructor ButtonGroupO by using this constructor object of button group class is created. Then different component are added to the bulton group obj-ct by using add( ) method.

import java.awt.*; import java.awt.event.*; import javax.swing.*; /* <applet code="JRadioButtonDemo" width=300 height=50> </applet> */ public class JRadioButtonDemo extends JApplet implements ActionListener { JTextField tf; public void init() { Container contentPane = getContentPane(); contentPane.setLayout(new FlowLayout()); JRadioButton b1 = new JRadioButton("C++"); b1.addActionListener(this); contentPane.add(b1); JRadioButton b2 = new JRadioButton("Java"); b2.addActionListener(this); contentPane.add(b2); JRadioButton b3 = new JRadioButton("SmallTalk"); b3.addActionListener(this); contentPane.add(b3); ButtonGroup bg = new ButtonGroup(); bg.add(b1); bg.add(b2); bg.add(b3); tf = new JTextField(5); contentPane.add(tf); } public void actionPerformed(ActionEvent ae) { tf.setText(ae.getActionCommand()); }

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy