Swing AWT

  Home  Java Programing  Swing AWT


“Java Swing frequently Asked Questions in various Swing AWT job Interviews by interviewer. The set of Swing AWT interview questions here ensures that you offer a perfect answer to the interview questions posed to you. Get preparation of Swing AWT job interview”



29 Swing AWT Questions And Answers

21⟩ What is JFC and explain the features of JFC?

The Java Foundation Classes are a set of GUI components and services which simplify the development and deployment of commercial-quality desktop and Internet/Intranet applications.

Java Foundation classes are core to the Java 2 Platform.

All JFC components are JavaBeans components and therefore reusable, interoperable, and portable.

JFC offers an open architecture. Third-party JavaBeans components can be used to enhance applications written using JFC.

Truly cross-platform.

Fully customizable.

 135 views

23⟩ What are heavyweight and lightweight components?

In Java AWT - Abstract Window Toolkit, GUI components created are OS dependent. When they are created, each component forms a peer component due to which they are called heavyweight components.

Swing components are platform independent. No peer components are formed due to which they are called lightweight components.

 128 views

25⟩ What is the purpose of action interface in Swing?

Action is performed on a state to allow it to change. It defines the interface that it is implementing. The library that is used for the action interface is javax.swing.Action. This action interface extends the ActionListener interface class that is being provided from the AWT. Action interface allow the concrete classes to implement the actionPerformed() method and provide the action that is associated with it. The use of actionPerformed() method allow the implementation of the behavior that is desired in the programming and allow it to show the functionality of the action class. The action can be added to the container class that accepts the parameters on an event like JMenu, JPopupMenu, or JtoolBar. The container used in this automatically registers the action that is taken on the event and it acts as an ActionListener of the user interface.

 143 views

26⟩ What is the purpose of Serialization in Swings?

Serialization is used when an object extends the Jcomponent class. The object's data in this case points out to the stream that is written or serialized and gives an output stream. This output stream can be sent through then network and it can be saved in the file if required. The serialized file can be de-serialized in the memory. This will allow the operation to continue to perform the original state functions that were getting used. The serialization used in object allows easy retrieval of the object data and easy transmission of state data from one place to another. This can also be placed in custom made storage files that provide the transfer of the components to be fast and it uses the concept of virtual machine that transfers from one machine to another machine. It uses the remote method invocation to allow the use of distributed computing that provide with some exceptions to the use of transient keyword. The components can be serialized using the classes that can pass the reference to an object using the writeObject() method of the ObjectOutputStream object this way it calls the serialization function recursively.

 143 views

27⟩ What is the function of Abstract Action class?

AbstractAction class allows the implementation of the abstract functions and the action interfaces. AbstractAction provides with the default functionality that are provided with the methods in the Action interface. The action can extend the class to create some specific actions for the users. The methods that is provided to implement the actionPerformed() method and it is used to provide the overall functionality for the action. ActionEvent is used to show the action command that can be used to add some features of the contents and provide ready to use action functionality on the event that can be carried for all the user interface fields.

class MyAction extends AbstractAction

{ }

public MyAction(String text, Icon icon)

{ super(text,icon); }

public void actionPerformed(ActionEvent e)

{ System.out.println("Action ["+e.getActionCommand()+"]!"); }

 138 views

28⟩ What is the use of JComponent Class in Swing?

Jcomponent is used as an abstract class that extends the functionality of the swing components. It allows the common swing component library to get involved in providing the functionality and the visual appearance that is required. The class that serves this purpose is given as: java.awt.Component class. This class also provides the framework for AWT components as well. The other class javax.swing.JComponent provides the role that is identical to other classes for the Swing components. JComponent class extends the class java.awt.Container that itself extend another class of java.awt.Component. This allows the AWT functionality to be used and added while writing the code for a program that needs to be executed. Jcomponents uses the swing component and allow the containers to handle the request for all the components like add() the component in the container, etc.

 147 views

29⟩ What is the use of double buffering in swings?

Double buffering can be achieved by using the Jcomponent class that allows the Swing component to enable this feature. Double buffering allows the component to execute faster or take less time to render the individual parts of the screen. It allows the component to be drawn and doesn't refresh it all the times. The refreshes done, in the background for the processes that requires the dynamic content to be displayed. Due to this, the flickering of the component gets reduced and the component appears to be smooth. The screen updates the monitor at very high speed so that the component appears to perform well. Copies of the component within the area are faster and the rendering can be performed at higher speed by knowing the position of the component. The program that can be used to activate the buffering is:

boolean doubleBuffered property of JComponent. Passing in true to the

setDoubleBuffered()

// This is the method that enables the double buffering for the component. It holds two values true or false

JButton button = new JButton("test");

button.setDoubleBuffered(true);

// The value true is used to turn on double buffering

 142 views