Java Swing interview
http://www.careerride.com/Swing-AWT-Interview-Questions.aspx
Swing interview questions and answers for freshers and experienced candidates. These interview questions and answers on Swing will help you strengthen your technical skills, prepare for the interviews and quickly revise the concepts. Many candidates appear for the interview for one role - many of the them give the right answers to the questions asked. The one who provides the best answer with a perfect presentation is the one who wins the interview race. The set of Swing AWT interview questions here ensures that you offer a perfect answer to the interview questions posed to you.
What is the use of JFC in Java Swing?- JFC stands for Java Foundation Classes that consists of the collection of libraries designed to make the programmers that are creating the enterprise applications using Java Swing. Swing APIs are used to create a suite of library known as JFC. - These classes also consist of AWT (Abstract Window Toolkit) that is used to access the API to increase the compatibility and enhance the support for the drag and drop capabilities that are provided by the JFC. - The AWT that comes under JFC is a toolkit that comes with the Java Development Kit. It is made up of lightweight component. - JFC consists of accessibility package that is used to provide assistance to the users who are having traditional interfaces. - It is used for the devices like text readers and this allows the direct access to be given to the swing components. The accessibility consists of APIs that comes with swing distributions and utilities that are distributed separately. - JFC consists of drag and drop facilities that provide graphical interfaces by which user can view the object and then it can be moved to another window or frame that is used in the desktop. The API allows the user to implement the elements that are used to transfer the information of Java applications. |
What is the difference between swing and AWT?- AWT is a heavyweight component that is used to associate the language with the native component. Whereas, Swing is the lightweight component that doesn't associate, any language with the component that it uses. - AWT draws the own component on the screen and it uses their own view-port that sends the output to the screen that displays the result. Whereas, Swing doesn't include any writing option to show the result on the screen so it does redirect to the components that makes it. - AWT components are of the z-ordering and it is not possible to combine any other in the same container. Whereas, Swing doesn't include the z-ordering and it always come below the AWT. - AWT is less consistent when used on different platforms. Whereas, Swing is more consistent across different platforms. |
What is the function of lightweight Components used in Swing?Lightweight component allow the components to be dependent on the native group of other components. These components are simplified types that are used to display themselves on the screen and allow the result to be transparent from others. Each component in this renders itself using the graphics objects and the functions that are provided with it like: drawLine(), fillRect(). They render themselves on the heavyweight level component that they are used to be in. The libraries that are included in this involves: java.awt.Component or java.awt.Container classes. These classes are used to create lightweight components and it doesn't depend on the native group of components. It produces fast results and these components are memory-intensive that allows the user to create the look and feel of the application at run time. Swing component also allow modification to be done in the design easily. |
Why is Model-View-Controller Architecture used in Swing?Model-View-Controller Architecture is used to show the design of the components that are made up of three elements and these elements show the behavior of components as: Model: View: Controller: |
How is multi-threading gets implemented using Swing?Swing uses multi-threading techniques to utilize the resources that are provided by the Java classes. Swing allows the users to create independent threads that can be used to change the model states of the components. If any changes happens in the component that is reflected on the screen then just updating the model state of the class that is used from the event dispatching queue. This event dispatching queue allows the component to communicate with each other. It also handles the user interface events that are used by the components. To increase the performance it requires the modifications to be refreshed so that the updated data is always received every time the component gets repeated. Multi-threading allows the swing program to run faster. This decreases the delay time and reduces the CPU usage that is used by the programs running on a single thread environment. |
What are the different types of layout managers used in Swing?- Layout manager is an object that is used to implement an interface which determines the size and position of the component that is used inside a container. - Components can provide the size and the alignments regarding the container's layout. - The main layouts that are used in the layout managers are given as: BorderLayout: BoxLayout: CardLayout: FlowLayout: GridBagLayout: GridLayout: GroupLayout: |
What is the process of setting the layout manager?- The layout managers uses Jpanels and content panes to initializes the object that is to be used with the FlowLayout by default and it can be changed by defining a different layout. - Content panes uses border layout by default and it uses appropriate tools that can be used to code the appropriate object that has to be used. - The panel layout manger can be setup by using the Jpanel constructor and it can be shown by an example given as: JPanel panel = new JPanel(new BorderLayout());
- The setLayout method is used to set the layout manager after the container is being created. Container contentPane = frame.getContentPane();
contentPane.setLayout(new FlowLayout()); - The container's layout property can be changed to NULL to allow the absolute positioning to take place where the specification is given in the form of size and positon of each component that is used inside the container. |
What are the different components that are used to show a container?- There are few components that are used to show the container used to define the visual properties of it. Layout manager: Invisible components: Empty borders: |
What is the function of Internal Frame in Swing?Internal frame allow one window to be displayed within another window. Adding of internal frame can be used to the desktop pane or the content pane. The user interface allows choosing the base of the application that is surrounded around the frames. The frames can be switched and other frames can be chosen over the other one. This internal frame has the same function that is provided in the normal Frame object, this object is confined inside the visible area of the container. The internal frame can have icons that can be used inside the application frame and have the properties of maximize and minimize so that the frame consists of main application frame. It closes the frame using the standard controls that is given for a popup window. Internal frame can be given in a layer that uses the display function to display the relative to the other internal frames. |
Write a program to include the Internal Frame in Swing.- Internal frame is the frame that keeps one window inside another window and allows them to switch from one frame to another frame. - The program shows the display of the internal frame. - To set the internal frame their need to be set up the layered pane. - The desktop pane is setup and then command is given to create a new internal frame using the properties. - The JinternalFrame method is used as a constructor to take some parameters and provide the look and feel as well as the functionality of the frame. JDesktopPane desktop = new JDesktopPane();
add(desktop, BorderLayout.CENTER); public JInternalFrame(String title, boolean resizable, boolean closable, boolean maximizable, boolean iconifiable); internalFrame = new JInternalFrame("Internal Frame", true, true, true, true); internalFrame.setBounds(50, 50, 200, 100); desktop.add(internalFrame, new Integer(1)); - The desktop.add() method allows the call to be done to the internal frame to allow the layer frame to be called for the frame it belongs to. - Layers are used as an integer objects that determine the order of the layer and shows the functionality on top of the frame. |
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. |
What is the function of AbstractAction 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()+"]!"); } |
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. |
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"); |
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. |
How does Accessibility works in Swings?The feature that is used in swing consists of accessibility technology that allows the class archives like JAR file. This file resides on separate machine and can not be accessed without the permissions given from the owner. Java is used to load the technology in the virtual machine that is used as an application. The technologies allow the replacement to be done using the virtual machine. It uses the queue method and the class as java.awt.EventQueue. The properties are used using the configuration file that is stored in awt.properties and it consists of all the specialized classes. Virtual machine in Java accesses the configuration file accessibility.properties that is contained in the jre/lib directory to allow the namespaces to be fetched to execute the process. The format is given of awt.properties file as: AWT.alt=Alt
AWT.meta=Meta # Assistive technologies AWT.assistive_technologies=SpeechRecognition AWT.EventQueueClass=com.sun.java.accessibility.util.EventQueueMonitor # Key names AWT.enter=Enter AWT.backSpace=Backspace |
How is Parsing HTML used in Swing?JEditorPane class is used to display the HTML content that is being written using the classes. When there is a file consisting of the HTML text gives the request to read the file identify the method to read the HTML text using the read() method that is given in HTMLEditorKit. This kit provides lot of tools that delegates the file to a separate parser object. This kid also consists of tools and the abstract inner class consisting of the method as: public abstract void parse(Reader r, ParserCallback cb) throws IOException
The read() method calls the getParser() method allowing the subclasses to parse the object and use the HTML text. The parser currently uses the package javax.swing.text.html.parser that allow the reading of the file and parse the HTML code. The parameter of the type ParserCallback is used to communicate the progress of the process that is parsing the HTML file. |
Write a program to paint the off-screen buffer in swings.To paint the off-screen buffer in swings requires the paint component that is using an image allowing easy to create set of images and its components in different states. This image that is stored, remain useful for automated regression testing that is also known as the golden image approach that is used to compare the images with the current and old images that uses the last stable build of the image. The code that displays it is as follows: JButton b = new JButton("Image buffer");
button.setSize(100, 50); // This set the initial size of the image. BufferedImage image = new BufferedImage(b.getWidth(), b.getHeight(), BufferedImage.TYPE_INT_RGB); Graphics g = image.getGraphics(); button.paint(g); ImageIO.write(image, "png", new File("image.png")); |
What are the steps required in creating an empty table drop?The dragging and dropping for an empty table allows it to be portable and the data can be moved with ease. The steps that are followed for this is: - The creation of an empty table that is used to get some data and the insertion gets performed in using the database techniques. - After creation of an empty table then the creating and attaching of the TransferHandler class gets included that allow the proper transfer of the data from one place to another. It also handles the interrupts that may occur while transferring the data. - Enable the data transfer to allow the calling of the object setDragEnabled(true). When this value is set to true then the table can be draggable and the data can be moved. - Creation of the scroll pane takes place to allow the adding of the table so that it can be dragged from one pane to another pane with ease and comfort. |
What is the purpose of TransferHandler Class?- TransferHandler class is used for data transfer and it provides an easy way to transfer the data from the Jcomponent. - All the details of the data are contained in the class and it support the classes as well. - The Components are provided with the default handler that can create own handler of their own. - There are three methods that can be used to use theTransferHandler on a component and these are as follows: 1. setDragEnabled(boolean): 2. setDropMode(DropMode): 3. setTransferHandler(TransferHandler): |
Java Swing interview的更多相关文章
- Java Swing 第03记 布局管理器
几种Swing常用的布局管理器 BorderLaout 它将容器分为5个部分,即东.南.西.北.中,每一个区域可以容纳一个组件,使用的时候也是通过BorderLayout中5个方位常量来确定组件所在的 ...
- Java Swing 第01记 Hello Word
首先来一个Java Swing的HelloWord程序. package cn.java.swing.chapter03; import javax.swing.JButton; import jav ...
- Java swing项目-图书管理系统(swing+mysql+jdbc) 总结
(一)java Swing的学习. (1)学习如何安装windowbuilder插件的安装. <1>在eclipse中点击help <2>在help的下拉选中选择install ...
- 【小型系统】抽奖系统-使用Java Swing完成
一.需求分析 1. 显示候选人照片和姓名. 2. 可以使用多种模式进行抽奖,包括一人单独抽奖.两人同时抽奖.三人同时抽奖. 3. 一个人可以在不同的批次的抽奖中获取一.二.三等奖,但是不能在同一批次抽 ...
- Java Swing快速构建窗体应用程序
以前接触java感觉其在桌面开发上,总是不太方便,没有一个好的拖拽界面布局工具,可以快速构建窗体. 最近学习了一下NetBeans IDE 8.1,感觉其窗体设计工具还是很不错的 , 就尝试一下做了一 ...
- paip.web数据绑定 下拉框的api设计 选择框 uapi python .net java swing jsf总结
paip.web数据绑定 下拉框的api设计 选择框 uapi python .net java swing jsf总结 ====总结: 数据绑定下拉框,Uapi 1.最好的是默认绑定..Map(k ...
- Java Swing的进化
摘 要:Swing已是一个比较老的工具集了,在美观的用户界面出来之前需要开发很长时间.它缺少一些你在开发富UI时所需的组件.幸运地是,像 Substance,SwingX及Java Look-and_ ...
- Java Swing事件处理机制
Java Swing的事件处理机制 Swing GUI启动后,Java虚拟机就启动三个线程,分别为主线程,事件派发线程(也是事件处理线程)和系统工具包线程. 主线程 :负责创建并显示该程序的初始界面: ...
- Java Swing 快捷键
Java Swing 快捷键 给Java Swing 编程中按钮或者其他组件事件添加快捷键的方法: Component.setAccelerator(KeyStroke.getKeyStroke(‘ ...
随机推荐
- node.js学习(二)--Node.js控制台(REPL)&&Node.js的基础和语法
1.1.2 Node.js控制台(REPL) Node.js也有自己的虚拟的运行环境:REPL. 我们可以使用它来执行任何的Node.js或者javascript代码.还可以引入模块和使用文件系统. ...
- SignalR系列目录
[置顶]用SignalR 2.0开发客服系统[系列1:实现群发通讯] [置顶]用SignalR 2.0开发客服系统[系列2:实现聊天室] [置顶]用SignalR 2.0开发客服系统[系列3:实现点对 ...
- ABP项目中使用Swagger生成动态WebAPI
本文是根据角落的白板报的<使用ABP实现SwaggerUI,生成动态webapi>一文的学习总结,感谢原文作者角落的白板报. 1 安装Swashbuckle.core 1.1 选择WebA ...
- RabbitMQ + PHP (一)入门与安装
RabbitMQ: 1.是实现AMQP(高级消息队列协议)的消息中间件的一种. 2.主要是为了实现系统之间的双向解耦而实现的.当生产者大量产生数据时,消费者无法快速消费,那么需要一个中间层.保存这个数 ...
- JavaScript学习笔记(三)——this、原型、javascript面向对象
一.this 在JavaScript中this表示:谁调用它,this就是谁. JavaScript是由对象组成的,一切皆为对象,万物皆为对象.this是一个动态的对象,根据调用的对象不同而发生变化, ...
- 发布APP到app store
好久好久没写博客了,主要是 都在学习新东西,忙不赢啊. 近段时间在用AC平台学习开发移动APP, 今天开始发布应用. 在ac云控制台编译成ipa后,使用apple提供的Application Load ...
- Linux程序包管理之rpm
rpm简介 rpm( Red Hat Package Manager )是一个开放的软件包管理系统.它工作于Red Hat Linux及其他Linux系统,成为Linux中公认的软件包管理标准. rp ...
- Help Hanzo (素数筛+区间枚举)
Help Hanzo 题意:求a~b间素数个数(1 ≤ a ≤ b < 231, b - a ≤ 100000). (全题在文末) 题解: a~b枚举必定TLE,普通打表MLE,真是头疼 ...
- WPF - 属性系统 (2 of 4)
属性更改回调 前一章的示例中,对各个参数的设置都非常容易理解.如果我们仅仅需要创建一个独立的依赖项属性,那么上面所提到的创建依赖项属性的基础知识足以满足需求.但是事情往往并非如此完美.在一个系统中,很 ...
- Web网站中利用JavaScript中ActiveXObject对象获取硬件信息(显示器数量、分辨率)从而进行单双屏跳转
前言:最近这两天工作上,要实现一个功能,在好友阿聪的帮助下,算是比较好的解决了这个需求. B/S的Web网站,需要实现点击按钮时,根据客户端连接的显示屏(监视器)数量进行,单双屏跳转显示新页面. 由于 ...