0% found this document useful (0 votes)
31 views2 pages

MC Exp3

This document provides an overview for designing a mobile calculator application using Java. It describes the key classes needed like Button, TextField, Panel, and Frame. It also covers event handling using the delegation event model with event sources, listeners, and adapter classes. The ActionEvent and ActionListener interfaces are discussed for handling button click events.

Uploaded by

Omkar Dalvi
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 PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views2 pages

MC Exp3

This document provides an overview for designing a mobile calculator application using Java. It describes the key classes needed like Button, TextField, Panel, and Frame. It also covers event handling using the delegation event model with event sources, listeners, and adapter classes. The ActionEvent and ActionListener interfaces are discussed for handling button click events.

Uploaded by

Omkar Dalvi
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 PDF, TXT or read online on Scribd
You are on page 1/ 2

Aim: To design a mobile application using Java Software used: Java Development Kit 1.

5 or later Theory: The design of a calculator involves the use of the following classes or interfaces. The Button Class The Button class can be used to add interactive buttons to a container. A push button is the most widely used component. It contains a label and generates an event when it is pressed. Button(String label) constructs a button with the specified label void addActionListener(ActionListener l) adds the specified action listener to receive action events from this button. void setLabel(String label) sets the button's label to be the specified string. String getLabel() gets the label of this button. The TextField Class A TextField object is a text component that allows for the editing of a single line of text. TextField(String text, int columns) constructs a new text field initialized with the specified text to be displayed, and wide enough to hold the specified number of columns. void setText(String t) sets the text that is presented by this text component to be the specified text. void setEditable(boolean b) sets the flag that determines whether or not this text component is editable. void setBackground(Color c) sets the background color of this text component String getText() returns the text that is presented by this text component. The Panel class Panel is the simplest container class. A panel provides space where an application can attach any other component. The default layout manager for a panel is the FlowLayout layout manager. Panel() creates a new panel using the default layout manager. Component add(Component comp) adds the specified component to the end of this container. void setLayout(LayoutManager mgr) sets the layout manager for this component. void setBounds(int x, int y, int width, int height) moves and resizes this component. The new location of the top-left corner is specified by x and y, and the new size is specified by width and height. The Frame class A frame encapsulates what is commonly thought of as a window. It is a subclass of Window and may have a title bar, borders and resizing corners. void setLayout(LayoutManager mgr) method sets the layout manager for this component. void setBackground(Color c) sets the background color for this component. Component add(Component comp) adds the specified component to the end of this container. void setSize(int width, int height) resizes this component with the supplied width and height. void setResizable(boolean resizable) sets whether this frame is resizable by the user. void setVisible(boolean b) shows or hides this Window depending on the value of parameter b

Event Handling An event is an object that describes a state change in a source. It can be generated when a person interacts with the elements in a graphical user interface. For example, pressing a button, entering a character via keyboard, clicking the mouse etc. The modern approach to handle events is based on delegation event model. Here, events are handled in terms of event sources and event listeners. An event source is an object that produces an event when the internal state of the object changes in some way. A source must register listeners in order for the listeners to receive notifications about a specific type of event. Each type of event has it own registration method. Here is the general form: public void addXXXlistener(XXXlistener el) Here, XXX is the name of the event and el is the reference to the event listener. An event listener is an object that is informed when an event occurs. For example a button is an event source and an animation object might be an event listener. It has two major requirements. First, it must have been registered with one or more sources to receive notifications about specific type of events. Second, it must implement methods to receive and process these notifications. Once an event is received, the listener processes the event and then returns. The ActionEvent class An ActionEvent is generated when a button is pressed, a list item is double clicked or a menu item is selected. The event is passed to every every ActionListener object that registered to receive such events using the component's addActionListener method. Object getSource() returns the object on which the event initially occurred. The ActionListener interface The class that is interested in processing an action event implements this interface, and the object created with that class is registered with a component, using the component's addActionListener method. When the action event occurs, that object's actionPerformed method is invoked. Its general form is:public void actionPerformed(ActionEvent e) Adapter Classes Java provides a special feature called an adapter class to simplify the creation of event handlers in certain situations by providing an empty implementation of all the methods in an event listener interface. The WindowAdapter class is an abstract adapter class for receiving window events. Extend this class to create a WindowEvent listener and override the methods of interest. The windowClosing() method is invoked when the window is in the process of being closed. Its general form is shown below. public void windowClosing(WindowEvent e) Conclusion: Thus, we have designed a mobile application (calculator) using Java.

You might also like