Sei sulla pagina 1di 8

Menu Bar Program

Calculator Program
Form Program
Applet Program
Interface Program
Inner Class Program

Difference between Swing and AWT?

What is the difference between text field and text area?

TextField TextArea
TextField is an AWT component TextArea is an AWT component
that allows entering a single line of that allows entering multiple lines of
text in a GUI application text in a GUI application.
It doesn’t have a scrollbar. It does have a scrollbar.

What is the method used to retrieve the text of a Label?


String getText() is the method used to retrieve the text of a Label.

What is the method used to place some text in the text field?
void setText(String str) is the method used to place some text in the text
field
.
Explain Component and Container.
The component is an abstract class that encapsulates all of the
attributes of a visual component. Except for menus, all user interface
elements that are displayed on the screen and that interact with the user
are subclasses of Component. It defines over a hundred public methods
that are responsible for managing events, such as mouse and keyboard
input, positioning and sizing the window, and repainting.

The Container is a component in AWT that can contain another


components like buttons, textfields, labels etc. The classes that extends
Container class are known as container such as Frame, Dialog and Panel.
A container is responsible for laying out (that is, positioning)
any components that it contains.

Explain swing is build on AWT?


Swing eliminates a number of the limitations inherent in the AWT and
Swing does not replace it.
Instead, Swing is built on the foundation of the AWT. Swing also uses the
same event handling mechanism as the AWT. Therefore, a basic
understanding of the AWT and of event handling is required to use Swing.
How do you add/remove component in AWT?
Using add() and remove() method, we can add/remove component in AWT.
Following forms is used to add/remove component in AWT.
Component add(Component compRef)
void remove(Component compRef)

Difference between Panel and Frame?


List out methods defined inside Key Listener interface with their method
signature?
Methods defined inside Key Listener interface with their method signature
are
keyPressed( ): Methods are invoked when a key is pressed
keyReleased( ): Methods are invoked when a key is released, respectively.
keyTyped( ): Method is invoked when a character has been entered.
What are the two types of Applet?
Applet class: Based on (AWT) to provide the graphical user interface.
JApplet class (Based on Swing Class): Easier-to-use user interface than
does the AWT.

Define event source and event listener?


Event sources are components, subclasses of java.awt.Component,
capable to generate events. The event source can be a button, TextField or
a Frame etc. Each type of event has its own registration method.
General form:
public void addTypeListener (TypeListener el )
For example, the method that registers a keyboard event listener is called
addKeyListener( ).

A listener is an object that is notified when an event occurs. The events


generated by the GUI components are handled by a special group of
interfaces known as "listeners".
For example, ActionListener handles the events of Button, TextField, List
and Menus. Listeners are from java.awt.event package.

Define the layout manager?


LayoutManager is an interface that is implemented by all the classes of
layout managers. The LayoutManagers are used to arrange components in
a particular manner.
The setLayout( ) method has the following general form:
void setLayout(LayoutManager layoutObj)

Write two feature of swing?


Swing Components Are Lightweight
Swing Supports a Pluggable Look and Feel
Differentiate between button and toggle button?

What is AWT classes?


It is one of Java’s largest packages contained in the java.awt package. It
contains numerous classes and methods that allow you to create windows
and simple controls. It is used built GUI or window-based application in
java. The java.awt package provides classes for AWT such as TextField,
Label, TextArea, RadioButton, CheckBox, Choice, List etc.

What is hiding and showing a frame in AWT?

Write steps to compile and run applet program?


c:\>javac fileName.java
c:\>appletviewer fileName.java
What is an Applet skeleton?
What is Applet?
Applet are small applications that are accessed on an Internet server,
transported over the Internet, automatically installed, and run as part of a
web document. After an applet arrives on the client, it has limited access to
resources so that it can produce a graphical user interface and
run various computations without introducing the risk of viruses or
breaching data integrity.

What is Adapter classes and Inner classes?


Adapter class is a special feature provided in java that can simplify the
creation of event handlers in certain situations. An adapter class provides
an empty implementation of all methods in an event listener interface. It is
useful when you want to receive and process only some of the events that
are handled by a particular event listener interface.
An inner class is a class which is defined inside another class. The inner
class can access all the members of an outer class, but vice-versa is not
true.

How to make text field non-editable in java?


We make text field non-editable in java by calling method:
void setEditable(boolean canEdit)

What is MVC?
MVC framework is software architecture used to separate the data access
layer, business logic code and the graphical user interface that has to be
defined and designed to let the user interact with the application. This
application has three parts,
MODEL
VIEW
CONTROLLER

How to pass Parameters to Applets?

To retrieve a parameter, use the getParameter( ) method. It returns the


value of the specified parameter in the form of a String object. Thus, for
numeric and boolean values, you will need to convert their string
representations into their internal formats.

Here is an example that demonstrates passing parameters:

import java.applet.Applet;
import java.awt.Graphics;
/*
<applet code="UseParam.class" width="300" height="300">
<param name="msg" value="Welcome to applet">
</applet>
*/
public class UseParam extends Applet {
public void paint(Graphics g) {
String str = getParameter("msg");
g.drawString(str, 50, 50);
}
}

Write two ways to run an applet?


There are two ways to run an applet
By html file.
By appletViewer tool (for testing purpose)

Potrebbero piacerti anche