SlideShare a Scribd company logo
1 of 9
QUESTION BANK
UNIT –II
Q.1 How to divide the jFrame intotwo parts? Explainwith code specification?
Ans: A JSplitPanedisplaystwo components,eithersideby side or oneon top of the other.By dragging thedividerthat
appearsbetween thecomponents,theusercan specify how much of the split pane'stotal area goesto each
component.You can dividescreen spaceamong threeor morecomponentsby putting splitpanesinside of split
panes.
Example:
importjava.awt.BorderLayout;
importjavax.swing.JFrame;
importjavax.swing.JSplitPane;
publicclassSwingSplitSample{
publicstaticvoidmain(String args[]) {
JFrameframe= new JFrame("JSplitPaneSample");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JSplitPanesplitPane= new JSplitPane();
splitPane.setOrientation(JSplitPane.HORIZONTAL_SPLIT);
frame.getContentPane().add(splitPane, BorderLayout.CENTER);
frame.setSize(300, 200);
frame.setVisible(true);
}
}
Q.2 Explainthe new featuresofJFC(Explainthe featuresof Swings) ?
Ans: The Java Foundation Classes(JFC) /Swings area comprehensivesetof GUIcomponentsand serviceswhich
dramatically simplify the developmentof desktop applications
1. Truly cross-platform:Being partof the Java Platform,allJFC componentsand servicesaredesigned to work
everywhere.Forexample,Drag and Drop services within JFC workthe samebetween the Java Platformand
all operating systems.
2. Fullycustomizable:Developerscan easily extend thesecomponentsto createothermore customized
components.In addition,even thelookand feel of these componentscan bechangeby eitherdevelopersor
usersthrough thePluggableLookand Feel architecturein JFC.
3. JavaBeanscomponents:All JFCcomponentsareJavaBeanscomponents.JFCcomponentshaveallthe
benefitsthatJavaBeanscomponentsoffer -- reusability,interoperability,and portability.
4. There is noframework lock-in:Developerscan easily bring in otherthird-party JavaBeanscomponentsto
enhancetheir applicationswritten using JFC.JFCoffersan open architecture.
Q.3 How can the userbe made aware of the software loadingprocess? Whichcomponenetisfacilitatingthe same?
Explainwith code specification
Ans:
importjava.awt.BorderLayout;
importjava.awt.Container;
importjavax.swing.BorderFactory;
importjavax.swing.JFrame;
importjavax.swing.JProgressBar;
importjavax.swing.border.Border;
publicclassProgressSample{
publicstaticvoidmain(String args[]) {
JFramef = new JFrame("JProgressBarSample");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Containercontent= f.getContentPane();
JProgressBarprogressBar=new JProgressBar();
progressBar.setValue(25);
progressBar.setStringPainted(true);
Border border= BorderFactory.createTitledBorder("Reading...");
progressBar.setBorder(border);
content.add(progressBar, BorderLayout.NORTH);
f.setSize(300, 100);
f.setVisible(true);
}
}
Q.4 Write a java swing program that createsthe hierarchical tree data structure?
Ans:
Treeexample.java
importjavax.swing.JFrame;
importjavax.swing.JTree;
importjavax.swing.SwingUtilities;
importjavax.swing.tree.DefaultMutableTreeNode;
public class TreeExampleextendsJFrame
{
private JTree tree;
public TreeExample()
{
//createthe rootnode
DefaultMutableTreeNoderoot=newDefaultMutableTreeNode("Root");
//createthe child nodes
DefaultMutableTreeNodevegetableNode=new DefaultMutableTreeNode("Vegetables")
vegetableNode.add(new DefaultMutableTreeNode("Capsicum"));
vegetableNode.add(new DefaultMutableTreeNode("Carrot"));
vegetableNode.add(new DefaultMutableTreeNode("Tomato"));
vegetableNode.add(new DefaultMutableTreeNode("Potato"));
DefaultMutableTreeNodefruitNode=new DefaultMutableTreeNode("Fruits");
fruitNode.add(newDefaultMutableTreeNode("Banana"));
fruitNode.add(newDefaultMutableTreeNode("Mango"));
fruitNode.add(newDefaultMutableTreeNode("Apple"));
fruitNode.add(newDefaultMutableTreeNode("Grapes"));
fruitNode.add(newDefaultMutableTreeNode("Orange"));
//add thechild nodesto the rootnode
root.add(vegetableNode);
root.add(fruitNode);
//create thetree by passing in theroot node
tree = new JTree(root);
add(tree);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setTitle("JTreeExample");
this.pack();
this.setVisible(true);
}
public static void main(String[] args)
{
SwingUtilities.invokeLater(newRunnable() {
@Override
public void run() {
newTreeExample();
}
});
}
}
Q.5 Write a java program usingsplitpane to demonstrate that a screendividedintwo parts. One part contains the
examinationseat numberof students.Whenuser selectsthe examseat number, photo ofthe studentshould get
displayedinanother pane.
Ans: Sameas yourjournalplanetprogram
Q.6 Explainthe use ofprogress bar control withsuitable example.
Ans:
importjava.awt.BorderLayout;
importjava.awt.Container;
importjavax.swing.BorderFactory;
importjavax.swing.JFrame;
importjavax.swing.JProgressBar;
importjavax.swing.border.Border;
publicclassProgressSample{
publicstaticvoidmain(String args[]) {
JFramef = new JFrame("JProgressBarSample");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Containercontent= f.getContentPane();
JProgressBarprogressBar=new JProgressBar();
progressBar.setValue(25);
progressBar.setStringPainted(true);
Border border= BorderFactory.createTitledBorder("Reading...");
progressBar.setBorder(border);
content.add(progressBar, BorderLayout.NORTH);
f.setSize(300, 100);
f.setVisible(true);
}
}
Q.7. Withthe helpof an example explainjColorChoosercomponent.
Ans: The class JColorChooserprovidesa paneof controlsdesigned to allow a user to manipulateand selecta color.
Example:
importjava.awt.Color;
importjavax.swing.JColorChooser;
publicclassMain {
publicstaticvoidmain(String[] argv) {
Color initialColor = Color.red;
Color newColor= JColorChooser.showDialog(null, "Dialog Title", initialColor);
}
}
Q.8. Compare and contrast AWTand SWING.
Ans:
Swing AWT
Swing is also called as JFC’s(Java Foundation
classes).
AWT standsforAbstractwindows toolkit.
Swingsare called light weightcomponent
becauseswing componentssitson thetop of
AWT componentsand do thework.
AWT componentsarecalled Heavyweight
component.
Swing componentsrequirejavax.swing
package.
AWT componentsrequirejava.awtpackage.
Swing componentsaremadein purely java
and they are platformindependent.
AWT componentsareplatformdependent.
We can havedifferentlookand feel in Swing. This featureis not supported in AWT.
Swing hasmany advanced featureslike
JTabel, Jtabbed panewhich is notavailable in
AWT. Also.Swing componentsarecalled
"lightweight"becausethey do not requirea
nativeOS objectto implement their
functionality.JDialog and JFrameare
heavyweight,becausethey do havea peer.So
componentslikeJButton,JTextArea,etc.,are
lightweightbecausethey do not havean OS
peer.
These featureis notavailablein AWT.
Swing hasthembuilt in. Using AWT, you haveto implement a lot of
thingsyourself.
Q.9 ExplainjScrollPane with example
Ans: A JScrollPaneprovidesa scrollable view of a component.When screen real estateis limited, usea scroll paneto
display a componentthatislarge or onewhose size can changedynamically.
Example:
importjava.awt.BorderLayout;
importjavax.swing.Icon;
importjavax.swing.ImageIcon;
importjavax.swing.JFrame;
importjavax.swing.JLabel;
importjavax.swing.JScrollPane;
publicclassScrollSample{
publicstaticvoidmain(String args[]) {
String title = (args.length ==0 ? "JScrollPaneSample": args[0]);
JFrameframe= new JFrame(title);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Icon icon = new ImageIcon("dog.jpg");
JLabel dogLabel= new JLabel(icon);
JScrollPanescrollPane= new JScrollPane();
scrollPane.setViewportView(dogLabel);
// scrollPane.getViewport().setView(dogLabel);
frame.getContentPane().add(scrollPane, BorderLayout.CENTER);
frame.setSize(300, 200);
frame.setVisible(true);
}
}
Q.10 How are menuscreatedin java ? what are the classesused for creating menus?Explainwith example
Ans: Performthefollowing stepsfordesigning the JFRAMEformwith a menu:
 Right click on the projectand create a new JFrameform
 Drag a menubarfromtheswing Menusonto theform
 Right click on the menubaradd menu
 Right click on the menu and add menuitem
 Doubleclick on theexit meni item and write thefollowing code
Example:
importjava.awt.Toolkit;
importjava.awt.event.WindowEvent;
importjavax.swing.JOptionPane;
public class Menueg extendsjavax.swing.JFrame{
public Menueg() {
initComponents();
}
// performthefollowing action on Exit button click
privatevoid jMenuItem6ActionPerformed(java.awt.event.ActionEventevt) {
int p=JOptionPane.showConfirmDialog(null,"Areu Sureto Close");
if(p==0){
WindowEventwinclose=newWindowEvent(this,WindowEvent.WINDOW_CLOSING);
Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(winclose);}
}
Q.11 Explainwith suitable example how siblingsandchild node are added in a tree
Ans:
Treeexample.java
importjavax.swing.JFrame;
importjavax.swing.JTree;
importjavax.swing.SwingUtilities;
importjavax.swing.tree.DefaultMutableTreeNode;
public class TreeExampleextendsJFrame
{
private JTree tree;
public TreeExample()
{
//createthe rootnode
DefaultMutableTreeNoderoot=newDefaultMutableTreeNode("Root");
//createthe child nodes
DefaultMutableTreeNodevegetableNode=new DefaultMutableTreeNode("Vegetables")
vegetableNode.add(new DefaultMutableTreeNode("Capsicum"));
vegetableNode.add(new DefaultMutableTreeNode("Carrot"));
vegetableNode.add(new DefaultMutableTreeNode("Tomato"));
vegetableNode.add(new DefaultMutableTreeNode("Potato"));
DefaultMutableTreeNodefruitNode=new DefaultMutableTreeNode("Fruits");
fruitNode.add(newDefaultMutableTreeNode("Banana"));
fruitNode.add(newDefaultMutableTreeNode("Mango"));
fruitNode.add(newDefaultMutableTreeNode("Apple"));
fruitNode.add(newDefaultMutableTreeNode("Grapes"));
fruitNode.add(newDefaultMutableTreeNode("Orange"));
//add thechild nodesto the rootnode
root.add(vegetableNode);
root.add(fruitNode);
//create thetree by passing in theroot node
tree = new JTree(root);
add(tree);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setTitle("JTreeExample");
this.pack();
this.setVisible(true);
}
public static void main(String[] args)
{
SwingUtilities.invokeLater(newRunnable() {
@Override
public void run() {
newTreeExample();
}
});
}
}
Q.12 Explainwith suitable example the needof a table model
Ans: The DefaultTableModelclassis a subclass of the AbstractTableModel.Asthenamesuggestsitis the tablemodel
thatis used by a JTable when no table modelis specifically defined by the programmer.TheDefaultTableModel
storesthe dataforthe JTable in a Vectorof Vectors.
The advantageofusingtheDefaultTableModel over a customAbstractTableModel is
 you don'thaveto codethe methodslike add,insertor delete rowsand columns.
 They already existto changethedata held in the VectorofVectors.
 This makesit a quick and easy table modelto implement.
Q.13 List and explainthe layout orientationsusedfor jList. Give a suitable example
Ans: The class JList is a component which displays a list of objects and allows the user to select one or more items. A
separatemodel,ListModel, maintainsthecontentsof the list.
Followingarethe differentlayoutorientationused for javax.swing.JListclass:
1. static intHORIZONTAL_WRAP --Indicatesa "newspaperstyle"layoutwith cells flowing
horizontally then vertically.
2. static intVERTICAL -- Indicatesa vertical layoutof cells, in a singlecolumn;the default
layout.
3. static intVERTICAL_WRAP -- Indicatesa "newspaperstyle"layoutwith cells flowing
4. vertically then horizontally.
Example:
importjava.awt.*;
importjava.awt.event.*;
importjavax.swing.*;
class ListExampleextendsJFrame
{ // Instanceattributesused in this example
private JPanel topPanel;
private JList listbox;
publicListExample()
{
// Set theframecharacteristics
setTitle( "Simple ListBox Application");
setSize( 300, 100 );
setBackground(Color.gray );
// Createa panelto hold all othercomponents
topPanel= newJPanel();
topPanel.setLayout(newBorderLayout());
getContentPane().add(topPanel);
// Createsomeitems to add to the list
String listData[] =
{ "Item1",
"Item2",
"Item3",
"Item4" };
// Createa newlistbox control
listbox = newJList( listData);
topPanel.add( listbox,BorderLayout.CENTER);
}
// Main entry point forthis example
public static void main( String args[] )
{
// Createan instanceof the test application
ListExamplemainFrame= new ListExample();
mainFrame.setVisible( true);
}
}
Q.14 What is the purpose oftabbed panes?Explain with suitable examples.
Ans:  A tabbed panescomponentletsthe user switch between a group of componentsby clicking on a tab with a
given title and/oricon.
 The user chooseswhich componentto view by selecting the tab corresponding to thedesired component.
 Tabs/componentsareadded to a TabbedPaneobjectby using theaddTab and insertTab methods.
 A tab is represented by an index corresponding to theposition it was added in,wherethe first tab hasan
index equalto 0 and the last tab hasan index equalto thetab countminus1.
 The TabbedPaneusesa SingleSelectionModelto representtheset of tab indices and the currently selected
index.If the tab countis greaterthan 0, then there will alwaysbea selected index,which by defaultwill be
initialized to the first tab.If the tab countis 0, then theselected index will be -1.
JTabbedPaneConstructor
1. JTabbedPane()
Createsan emptyTabbedPanewith a defaulttab placementof JTabbedPane.TOP.
2. JTabbedPane(inttabPlacement)
Createsan emptyTabbedPanewith thespecified tab placementof either: JTabbedPane.TOP,
JTabbedPane.BOTTOM,JTabbedPane.LEFT,orJTabbedPane.RIGHT.
3. JTabbedPane(inttabPlacement,inttabLayoutPolicy)
Createsan emptyTabbedPanewith thespecified tab placementand tab layoutpolicy.
Example:
JTabbedPanetabbedPane=newJTabbedPane();
ImageIcon icon = createImageIcon("images/middle.gif");
JComponentpanel1=makeTextPanel("Panel#1");
tabbedPane.addTab("Tab1",icon,panel1,
"Doesnothing");
tabbedPane.setMnemonicAt(0,KeyEvent.VK_1);
JComponentpanel2=makeTextPanel("Panel#2");
tabbedPane.addTab("Tab2",icon,panel2,
"Doestwice asmuch nothing");
tabbedPane.setMnemonicAt(1,KeyEvent.VK_2);
JComponentpanel3=makeTextPanel("Panel#3");
tabbedPane.addTab("Tab3",icon,panel3,
"Still doesnothing");
tabbedPane.setMnemonicAt(2,KeyEvent.VK_3);

More Related Content

What's hot

Volley lab btc_bbit
Volley lab btc_bbitVolley lab btc_bbit
Volley lab btc_bbitCarWash1
 
Introduction to Drools
Introduction to DroolsIntroduction to Drools
Introduction to Droolsgiurca
 
Advanced Dagger talk from 360andev
Advanced Dagger talk from 360andevAdvanced Dagger talk from 360andev
Advanced Dagger talk from 360andevMike Nakhimovich
 
How and why I turned my old Java projects into a first-class serverless compo...
How and why I turned my old Java projects into a first-class serverless compo...How and why I turned my old Java projects into a first-class serverless compo...
How and why I turned my old Java projects into a first-class serverless compo...Mario Fusco
 
Executing Sql Commands
Executing Sql CommandsExecuting Sql Commands
Executing Sql Commandsleminhvuong
 
JBoss Drools - Pure Java Rule Engine
JBoss Drools - Pure Java Rule EngineJBoss Drools - Pure Java Rule Engine
JBoss Drools - Pure Java Rule EngineAnil Allewar
 
Entity Persistence with JPA
Entity Persistence with JPAEntity Persistence with JPA
Entity Persistence with JPASubin Sugunan
 
Drools & jBPM Info Sheet
Drools & jBPM Info SheetDrools & jBPM Info Sheet
Drools & jBPM Info SheetMark Proctor
 
Vaadin JPAContainer
Vaadin JPAContainerVaadin JPAContainer
Vaadin JPAContainercmkandemir
 
What is the difference between struts 1 vs struts 2
What is the difference between struts 1 vs struts 2What is the difference between struts 1 vs struts 2
What is the difference between struts 1 vs struts 2Santosh Singh Paliwal
 
Modularization Strategies - Fixing Class and Package Tangles
Modularization Strategies - Fixing Class and Package TanglesModularization Strategies - Fixing Class and Package Tangles
Modularization Strategies - Fixing Class and Package TanglesCodeOps Technologies LLP
 
JDBC (JAVA Database Connectivity)
JDBC (JAVA Database Connectivity)JDBC (JAVA Database Connectivity)
JDBC (JAVA Database Connectivity)HimanshiSingh71
 
Command and Adapter Pattern
Command and Adapter PatternCommand and Adapter Pattern
Command and Adapter PatternJonathan Simon
 

What's hot (20)

Volley lab btc_bbit
Volley lab btc_bbitVolley lab btc_bbit
Volley lab btc_bbit
 
Ecom lec4 fall16_jpa
Ecom lec4 fall16_jpaEcom lec4 fall16_jpa
Ecom lec4 fall16_jpa
 
Introduction to Drools
Introduction to DroolsIntroduction to Drools
Introduction to Drools
 
Exercises
ExercisesExercises
Exercises
 
JPA Best Practices
JPA Best PracticesJPA Best Practices
JPA Best Practices
 
Advanced Dagger talk from 360andev
Advanced Dagger talk from 360andevAdvanced Dagger talk from 360andev
Advanced Dagger talk from 360andev
 
Java
JavaJava
Java
 
Jstl 8
Jstl 8Jstl 8
Jstl 8
 
How and why I turned my old Java projects into a first-class serverless compo...
How and why I turned my old Java projects into a first-class serverless compo...How and why I turned my old Java projects into a first-class serverless compo...
How and why I turned my old Java projects into a first-class serverless compo...
 
Call Back
Call BackCall Back
Call Back
 
Executing Sql Commands
Executing Sql CommandsExecuting Sql Commands
Executing Sql Commands
 
JBoss Drools - Pure Java Rule Engine
JBoss Drools - Pure Java Rule EngineJBoss Drools - Pure Java Rule Engine
JBoss Drools - Pure Java Rule Engine
 
Entity Persistence with JPA
Entity Persistence with JPAEntity Persistence with JPA
Entity Persistence with JPA
 
Drools & jBPM Info Sheet
Drools & jBPM Info SheetDrools & jBPM Info Sheet
Drools & jBPM Info Sheet
 
Vaadin JPAContainer
Vaadin JPAContainerVaadin JPAContainer
Vaadin JPAContainer
 
What is the difference between struts 1 vs struts 2
What is the difference between struts 1 vs struts 2What is the difference between struts 1 vs struts 2
What is the difference between struts 1 vs struts 2
 
Modularization Strategies - Fixing Class and Package Tangles
Modularization Strategies - Fixing Class and Package TanglesModularization Strategies - Fixing Class and Package Tangles
Modularization Strategies - Fixing Class and Package Tangles
 
G pars
G parsG pars
G pars
 
JDBC (JAVA Database Connectivity)
JDBC (JAVA Database Connectivity)JDBC (JAVA Database Connectivity)
JDBC (JAVA Database Connectivity)
 
Command and Adapter Pattern
Command and Adapter PatternCommand and Adapter Pattern
Command and Adapter Pattern
 

Similar to TY.BSc.IT Java QB U2

Improving android experience for both users and developers
Improving android experience for both users and developersImproving android experience for both users and developers
Improving android experience for both users and developersPavel Lahoda
 
Droidcon2013 android experience lahoda
Droidcon2013 android experience lahodaDroidcon2013 android experience lahoda
Droidcon2013 android experience lahodaDroidcon Berlin
 
import java.awt.Color;import java.awt.Insets;import java.awt.Con.pdf
import java.awt.Color;import java.awt.Insets;import java.awt.Con.pdfimport java.awt.Color;import java.awt.Insets;import java.awt.Con.pdf
import java.awt.Color;import java.awt.Insets;import java.awt.Con.pdfvenkt12345
 
Android Best Practices
Android Best PracticesAndroid Best Practices
Android Best PracticesYekmer Simsek
 
JavaFX in Action (devoxx'16)
JavaFX in Action (devoxx'16)JavaFX in Action (devoxx'16)
JavaFX in Action (devoxx'16)Alexander Casall
 
In Java Write a GUI application to simulate writing out a check. The.pdf
In Java Write a GUI application to simulate writing out a check. The.pdfIn Java Write a GUI application to simulate writing out a check. The.pdf
In Java Write a GUI application to simulate writing out a check. The.pdfflashfashioncasualwe
 
Advance Java Programs skeleton
Advance Java Programs skeletonAdvance Java Programs skeleton
Advance Java Programs skeletonIram Ramrajkar
 
Write a GUI application to simulate writing out a check. The value o.pdf
Write a GUI application to simulate writing out a check. The value o.pdfWrite a GUI application to simulate writing out a check. The value o.pdf
Write a GUI application to simulate writing out a check. The value o.pdffathimaoptical
 
Construire une application JavaFX 8 avec gradle
Construire une application JavaFX 8 avec gradleConstruire une application JavaFX 8 avec gradle
Construire une application JavaFX 8 avec gradleThierry Wasylczenko
 
Test Infected Presentation
Test Infected PresentationTest Infected Presentation
Test Infected Presentationwillmation
 
20-Arid-850 Ali Haider Cheema BSSE(5A) Evening MPL Assignement 08.docx
20-Arid-850 Ali Haider Cheema BSSE(5A) Evening MPL Assignement 08.docx20-Arid-850 Ali Haider Cheema BSSE(5A) Evening MPL Assignement 08.docx
20-Arid-850 Ali Haider Cheema BSSE(5A) Evening MPL Assignement 08.docxAliHaiderCheema2
 
Simplified Android Development with Simple-Stack
Simplified Android Development with Simple-StackSimplified Android Development with Simple-Stack
Simplified Android Development with Simple-StackGabor Varadi
 

Similar to TY.BSc.IT Java QB U2 (20)

Improving android experience for both users and developers
Improving android experience for both users and developersImproving android experience for both users and developers
Improving android experience for both users and developers
 
Droidcon2013 android experience lahoda
Droidcon2013 android experience lahodaDroidcon2013 android experience lahoda
Droidcon2013 android experience lahoda
 
Scrollable Demo App
Scrollable Demo AppScrollable Demo App
Scrollable Demo App
 
From Swing to JavaFX
From Swing to JavaFXFrom Swing to JavaFX
From Swing to JavaFX
 
Griffon @ Svwjug
Griffon @ SvwjugGriffon @ Svwjug
Griffon @ Svwjug
 
TY.BSc.IT Java QB U1
TY.BSc.IT Java QB U1TY.BSc.IT Java QB U1
TY.BSc.IT Java QB U1
 
import java.awt.Color;import java.awt.Insets;import java.awt.Con.pdf
import java.awt.Color;import java.awt.Insets;import java.awt.Con.pdfimport java.awt.Color;import java.awt.Insets;import java.awt.Con.pdf
import java.awt.Color;import java.awt.Insets;import java.awt.Con.pdf
 
Android Best Practices
Android Best PracticesAndroid Best Practices
Android Best Practices
 
JavaFX in Action (devoxx'16)
JavaFX in Action (devoxx'16)JavaFX in Action (devoxx'16)
JavaFX in Action (devoxx'16)
 
In Java Write a GUI application to simulate writing out a check. The.pdf
In Java Write a GUI application to simulate writing out a check. The.pdfIn Java Write a GUI application to simulate writing out a check. The.pdf
In Java Write a GUI application to simulate writing out a check. The.pdf
 
Java awt
Java awtJava awt
Java awt
 
Chap1 1.4
Chap1 1.4Chap1 1.4
Chap1 1.4
 
Advance Java Programs skeleton
Advance Java Programs skeletonAdvance Java Programs skeleton
Advance Java Programs skeleton
 
Swing
SwingSwing
Swing
 
Write a GUI application to simulate writing out a check. The value o.pdf
Write a GUI application to simulate writing out a check. The value o.pdfWrite a GUI application to simulate writing out a check. The value o.pdf
Write a GUI application to simulate writing out a check. The value o.pdf
 
Construire une application JavaFX 8 avec gradle
Construire une application JavaFX 8 avec gradleConstruire une application JavaFX 8 avec gradle
Construire une application JavaFX 8 avec gradle
 
DBTool
DBToolDBTool
DBTool
 
Test Infected Presentation
Test Infected PresentationTest Infected Presentation
Test Infected Presentation
 
20-Arid-850 Ali Haider Cheema BSSE(5A) Evening MPL Assignement 08.docx
20-Arid-850 Ali Haider Cheema BSSE(5A) Evening MPL Assignement 08.docx20-Arid-850 Ali Haider Cheema BSSE(5A) Evening MPL Assignement 08.docx
20-Arid-850 Ali Haider Cheema BSSE(5A) Evening MPL Assignement 08.docx
 
Simplified Android Development with Simple-Stack
Simplified Android Development with Simple-StackSimplified Android Development with Simple-Stack
Simplified Android Development with Simple-Stack
 

More from Lokesh Singrol

TY.BSc.IT Java QB U5&6
TY.BSc.IT Java QB U5&6TY.BSc.IT Java QB U5&6
TY.BSc.IT Java QB U5&6Lokesh Singrol
 
Project black book TYIT
Project black book TYITProject black book TYIT
Project black book TYITLokesh Singrol
 
Computer institute website(TYIT project)
Computer institute website(TYIT project)Computer institute website(TYIT project)
Computer institute website(TYIT project)Lokesh Singrol
 
Top Technology product failure
Top Technology product failureTop Technology product failure
Top Technology product failureLokesh Singrol
 
HP Software Testing project (Advanced)
HP Software Testing project (Advanced)HP Software Testing project (Advanced)
HP Software Testing project (Advanced)Lokesh Singrol
 
Testing project (basic)
Testing project (basic)Testing project (basic)
Testing project (basic)Lokesh Singrol
 
Computer institute Website(TYIT project)
Computer institute Website(TYIT project)Computer institute Website(TYIT project)
Computer institute Website(TYIT project)Lokesh Singrol
 
behavioral model (DFD & state diagram)
behavioral model (DFD & state diagram)behavioral model (DFD & state diagram)
behavioral model (DFD & state diagram)Lokesh Singrol
 
Desktop system,clustered system,Handheld system
Desktop system,clustered system,Handheld systemDesktop system,clustered system,Handheld system
Desktop system,clustered system,Handheld systemLokesh Singrol
 

More from Lokesh Singrol (19)

MCLS 45 Lab Manual
MCLS 45 Lab ManualMCLS 45 Lab Manual
MCLS 45 Lab Manual
 
MCSL 036 (Jan 2018)
MCSL 036 (Jan 2018)MCSL 036 (Jan 2018)
MCSL 036 (Jan 2018)
 
TY.BSc.IT Java QB U6
TY.BSc.IT Java QB U6TY.BSc.IT Java QB U6
TY.BSc.IT Java QB U6
 
TY.BSc.IT Java QB U5
TY.BSc.IT Java QB U5TY.BSc.IT Java QB U5
TY.BSc.IT Java QB U5
 
TY.BSc.IT Java QB U5&6
TY.BSc.IT Java QB U5&6TY.BSc.IT Java QB U5&6
TY.BSc.IT Java QB U5&6
 
TY.BSc.IT Java QB U4
TY.BSc.IT Java QB U4TY.BSc.IT Java QB U4
TY.BSc.IT Java QB U4
 
TY.BSc.IT Java QB U3
TY.BSc.IT Java QB U3TY.BSc.IT Java QB U3
TY.BSc.IT Java QB U3
 
Project black book TYIT
Project black book TYITProject black book TYIT
Project black book TYIT
 
Computer institute website(TYIT project)
Computer institute website(TYIT project)Computer institute website(TYIT project)
Computer institute website(TYIT project)
 
Internet of Things
Internet of ThingsInternet of Things
Internet of Things
 
Top Technology product failure
Top Technology product failureTop Technology product failure
Top Technology product failure
 
HP Software Testing project (Advanced)
HP Software Testing project (Advanced)HP Software Testing project (Advanced)
HP Software Testing project (Advanced)
 
Testing project (basic)
Testing project (basic)Testing project (basic)
Testing project (basic)
 
Computer institute Website(TYIT project)
Computer institute Website(TYIT project)Computer institute Website(TYIT project)
Computer institute Website(TYIT project)
 
Trees and graphs
Trees and graphsTrees and graphs
Trees and graphs
 
behavioral model (DFD & state diagram)
behavioral model (DFD & state diagram)behavioral model (DFD & state diagram)
behavioral model (DFD & state diagram)
 
Desktop system,clustered system,Handheld system
Desktop system,clustered system,Handheld systemDesktop system,clustered system,Handheld system
Desktop system,clustered system,Handheld system
 
Raster Scan display
Raster Scan displayRaster Scan display
Raster Scan display
 
Flash memory
Flash memoryFlash memory
Flash memory
 

Recently uploaded

Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfSpandanaRallapalli
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
Planning a health career 4th Quarter.pptx
Planning a health career 4th Quarter.pptxPlanning a health career 4th Quarter.pptx
Planning a health career 4th Quarter.pptxLigayaBacuel1
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfMr Bounab Samir
 
Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........LeaCamillePacle
 
Romantic Opera MUSIC FOR GRADE NINE pptx
Romantic Opera MUSIC FOR GRADE NINE pptxRomantic Opera MUSIC FOR GRADE NINE pptx
Romantic Opera MUSIC FOR GRADE NINE pptxsqpmdrvczh
 

Recently uploaded (20)

Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Rapple "Scholarly Communications and the Sustainable Development Goals"
Rapple "Scholarly Communications and the Sustainable Development Goals"Rapple "Scholarly Communications and the Sustainable Development Goals"
Rapple "Scholarly Communications and the Sustainable Development Goals"
 
Raw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptxRaw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptx
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdf
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
Planning a health career 4th Quarter.pptx
Planning a health career 4th Quarter.pptxPlanning a health career 4th Quarter.pptx
Planning a health career 4th Quarter.pptx
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
 
Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........
 
Romantic Opera MUSIC FOR GRADE NINE pptx
Romantic Opera MUSIC FOR GRADE NINE pptxRomantic Opera MUSIC FOR GRADE NINE pptx
Romantic Opera MUSIC FOR GRADE NINE pptx
 

TY.BSc.IT Java QB U2

  • 1. QUESTION BANK UNIT –II Q.1 How to divide the jFrame intotwo parts? Explainwith code specification? Ans: A JSplitPanedisplaystwo components,eithersideby side or oneon top of the other.By dragging thedividerthat appearsbetween thecomponents,theusercan specify how much of the split pane'stotal area goesto each component.You can dividescreen spaceamong threeor morecomponentsby putting splitpanesinside of split panes. Example: importjava.awt.BorderLayout; importjavax.swing.JFrame; importjavax.swing.JSplitPane; publicclassSwingSplitSample{ publicstaticvoidmain(String args[]) { JFrameframe= new JFrame("JSplitPaneSample"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JSplitPanesplitPane= new JSplitPane(); splitPane.setOrientation(JSplitPane.HORIZONTAL_SPLIT); frame.getContentPane().add(splitPane, BorderLayout.CENTER); frame.setSize(300, 200); frame.setVisible(true); } } Q.2 Explainthe new featuresofJFC(Explainthe featuresof Swings) ? Ans: The Java Foundation Classes(JFC) /Swings area comprehensivesetof GUIcomponentsand serviceswhich dramatically simplify the developmentof desktop applications 1. Truly cross-platform:Being partof the Java Platform,allJFC componentsand servicesaredesigned to work everywhere.Forexample,Drag and Drop services within JFC workthe samebetween the Java Platformand all operating systems. 2. Fullycustomizable:Developerscan easily extend thesecomponentsto createothermore customized components.In addition,even thelookand feel of these componentscan bechangeby eitherdevelopersor usersthrough thePluggableLookand Feel architecturein JFC. 3. JavaBeanscomponents:All JFCcomponentsareJavaBeanscomponents.JFCcomponentshaveallthe benefitsthatJavaBeanscomponentsoffer -- reusability,interoperability,and portability. 4. There is noframework lock-in:Developerscan easily bring in otherthird-party JavaBeanscomponentsto enhancetheir applicationswritten using JFC.JFCoffersan open architecture. Q.3 How can the userbe made aware of the software loadingprocess? Whichcomponenetisfacilitatingthe same?
  • 2. Explainwith code specification Ans: importjava.awt.BorderLayout; importjava.awt.Container; importjavax.swing.BorderFactory; importjavax.swing.JFrame; importjavax.swing.JProgressBar; importjavax.swing.border.Border; publicclassProgressSample{ publicstaticvoidmain(String args[]) { JFramef = new JFrame("JProgressBarSample"); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Containercontent= f.getContentPane(); JProgressBarprogressBar=new JProgressBar(); progressBar.setValue(25); progressBar.setStringPainted(true); Border border= BorderFactory.createTitledBorder("Reading..."); progressBar.setBorder(border); content.add(progressBar, BorderLayout.NORTH); f.setSize(300, 100); f.setVisible(true); } } Q.4 Write a java swing program that createsthe hierarchical tree data structure? Ans: Treeexample.java importjavax.swing.JFrame; importjavax.swing.JTree; importjavax.swing.SwingUtilities; importjavax.swing.tree.DefaultMutableTreeNode; public class TreeExampleextendsJFrame { private JTree tree; public TreeExample() { //createthe rootnode DefaultMutableTreeNoderoot=newDefaultMutableTreeNode("Root"); //createthe child nodes DefaultMutableTreeNodevegetableNode=new DefaultMutableTreeNode("Vegetables")
  • 3. vegetableNode.add(new DefaultMutableTreeNode("Capsicum")); vegetableNode.add(new DefaultMutableTreeNode("Carrot")); vegetableNode.add(new DefaultMutableTreeNode("Tomato")); vegetableNode.add(new DefaultMutableTreeNode("Potato")); DefaultMutableTreeNodefruitNode=new DefaultMutableTreeNode("Fruits"); fruitNode.add(newDefaultMutableTreeNode("Banana")); fruitNode.add(newDefaultMutableTreeNode("Mango")); fruitNode.add(newDefaultMutableTreeNode("Apple")); fruitNode.add(newDefaultMutableTreeNode("Grapes")); fruitNode.add(newDefaultMutableTreeNode("Orange")); //add thechild nodesto the rootnode root.add(vegetableNode); root.add(fruitNode); //create thetree by passing in theroot node tree = new JTree(root); add(tree); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setTitle("JTreeExample"); this.pack(); this.setVisible(true); } public static void main(String[] args) { SwingUtilities.invokeLater(newRunnable() { @Override public void run() { newTreeExample(); } }); } } Q.5 Write a java program usingsplitpane to demonstrate that a screendividedintwo parts. One part contains the examinationseat numberof students.Whenuser selectsthe examseat number, photo ofthe studentshould get displayedinanother pane. Ans: Sameas yourjournalplanetprogram Q.6 Explainthe use ofprogress bar control withsuitable example. Ans:
  • 4. importjava.awt.BorderLayout; importjava.awt.Container; importjavax.swing.BorderFactory; importjavax.swing.JFrame; importjavax.swing.JProgressBar; importjavax.swing.border.Border; publicclassProgressSample{ publicstaticvoidmain(String args[]) { JFramef = new JFrame("JProgressBarSample"); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Containercontent= f.getContentPane(); JProgressBarprogressBar=new JProgressBar(); progressBar.setValue(25); progressBar.setStringPainted(true); Border border= BorderFactory.createTitledBorder("Reading..."); progressBar.setBorder(border); content.add(progressBar, BorderLayout.NORTH); f.setSize(300, 100); f.setVisible(true); } } Q.7. Withthe helpof an example explainjColorChoosercomponent. Ans: The class JColorChooserprovidesa paneof controlsdesigned to allow a user to manipulateand selecta color. Example: importjava.awt.Color; importjavax.swing.JColorChooser; publicclassMain { publicstaticvoidmain(String[] argv) { Color initialColor = Color.red; Color newColor= JColorChooser.showDialog(null, "Dialog Title", initialColor); } } Q.8. Compare and contrast AWTand SWING. Ans: Swing AWT Swing is also called as JFC’s(Java Foundation classes). AWT standsforAbstractwindows toolkit. Swingsare called light weightcomponent becauseswing componentssitson thetop of AWT componentsand do thework. AWT componentsarecalled Heavyweight component.
  • 5. Swing componentsrequirejavax.swing package. AWT componentsrequirejava.awtpackage. Swing componentsaremadein purely java and they are platformindependent. AWT componentsareplatformdependent. We can havedifferentlookand feel in Swing. This featureis not supported in AWT. Swing hasmany advanced featureslike JTabel, Jtabbed panewhich is notavailable in AWT. Also.Swing componentsarecalled "lightweight"becausethey do not requirea nativeOS objectto implement their functionality.JDialog and JFrameare heavyweight,becausethey do havea peer.So componentslikeJButton,JTextArea,etc.,are lightweightbecausethey do not havean OS peer. These featureis notavailablein AWT. Swing hasthembuilt in. Using AWT, you haveto implement a lot of thingsyourself. Q.9 ExplainjScrollPane with example Ans: A JScrollPaneprovidesa scrollable view of a component.When screen real estateis limited, usea scroll paneto display a componentthatislarge or onewhose size can changedynamically. Example: importjava.awt.BorderLayout; importjavax.swing.Icon; importjavax.swing.ImageIcon; importjavax.swing.JFrame; importjavax.swing.JLabel; importjavax.swing.JScrollPane; publicclassScrollSample{ publicstaticvoidmain(String args[]) { String title = (args.length ==0 ? "JScrollPaneSample": args[0]); JFrameframe= new JFrame(title); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Icon icon = new ImageIcon("dog.jpg"); JLabel dogLabel= new JLabel(icon); JScrollPanescrollPane= new JScrollPane(); scrollPane.setViewportView(dogLabel); // scrollPane.getViewport().setView(dogLabel); frame.getContentPane().add(scrollPane, BorderLayout.CENTER); frame.setSize(300, 200); frame.setVisible(true); } } Q.10 How are menuscreatedin java ? what are the classesused for creating menus?Explainwith example
  • 6. Ans: Performthefollowing stepsfordesigning the JFRAMEformwith a menu:  Right click on the projectand create a new JFrameform  Drag a menubarfromtheswing Menusonto theform  Right click on the menubaradd menu  Right click on the menu and add menuitem  Doubleclick on theexit meni item and write thefollowing code Example: importjava.awt.Toolkit; importjava.awt.event.WindowEvent; importjavax.swing.JOptionPane; public class Menueg extendsjavax.swing.JFrame{ public Menueg() { initComponents(); } // performthefollowing action on Exit button click privatevoid jMenuItem6ActionPerformed(java.awt.event.ActionEventevt) { int p=JOptionPane.showConfirmDialog(null,"Areu Sureto Close"); if(p==0){ WindowEventwinclose=newWindowEvent(this,WindowEvent.WINDOW_CLOSING); Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(winclose);} } Q.11 Explainwith suitable example how siblingsandchild node are added in a tree Ans: Treeexample.java importjavax.swing.JFrame; importjavax.swing.JTree; importjavax.swing.SwingUtilities; importjavax.swing.tree.DefaultMutableTreeNode; public class TreeExampleextendsJFrame { private JTree tree; public TreeExample() { //createthe rootnode DefaultMutableTreeNoderoot=newDefaultMutableTreeNode("Root"); //createthe child nodes DefaultMutableTreeNodevegetableNode=new DefaultMutableTreeNode("Vegetables")
  • 7. vegetableNode.add(new DefaultMutableTreeNode("Capsicum")); vegetableNode.add(new DefaultMutableTreeNode("Carrot")); vegetableNode.add(new DefaultMutableTreeNode("Tomato")); vegetableNode.add(new DefaultMutableTreeNode("Potato")); DefaultMutableTreeNodefruitNode=new DefaultMutableTreeNode("Fruits"); fruitNode.add(newDefaultMutableTreeNode("Banana")); fruitNode.add(newDefaultMutableTreeNode("Mango")); fruitNode.add(newDefaultMutableTreeNode("Apple")); fruitNode.add(newDefaultMutableTreeNode("Grapes")); fruitNode.add(newDefaultMutableTreeNode("Orange")); //add thechild nodesto the rootnode root.add(vegetableNode); root.add(fruitNode); //create thetree by passing in theroot node tree = new JTree(root); add(tree); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setTitle("JTreeExample"); this.pack(); this.setVisible(true); } public static void main(String[] args) { SwingUtilities.invokeLater(newRunnable() { @Override public void run() { newTreeExample(); } }); } } Q.12 Explainwith suitable example the needof a table model Ans: The DefaultTableModelclassis a subclass of the AbstractTableModel.Asthenamesuggestsitis the tablemodel thatis used by a JTable when no table modelis specifically defined by the programmer.TheDefaultTableModel storesthe dataforthe JTable in a Vectorof Vectors. The advantageofusingtheDefaultTableModel over a customAbstractTableModel is  you don'thaveto codethe methodslike add,insertor delete rowsand columns.  They already existto changethedata held in the VectorofVectors.
  • 8.  This makesit a quick and easy table modelto implement. Q.13 List and explainthe layout orientationsusedfor jList. Give a suitable example Ans: The class JList is a component which displays a list of objects and allows the user to select one or more items. A separatemodel,ListModel, maintainsthecontentsof the list. Followingarethe differentlayoutorientationused for javax.swing.JListclass: 1. static intHORIZONTAL_WRAP --Indicatesa "newspaperstyle"layoutwith cells flowing horizontally then vertically. 2. static intVERTICAL -- Indicatesa vertical layoutof cells, in a singlecolumn;the default layout. 3. static intVERTICAL_WRAP -- Indicatesa "newspaperstyle"layoutwith cells flowing 4. vertically then horizontally. Example: importjava.awt.*; importjava.awt.event.*; importjavax.swing.*; class ListExampleextendsJFrame { // Instanceattributesused in this example private JPanel topPanel; private JList listbox; publicListExample() { // Set theframecharacteristics setTitle( "Simple ListBox Application"); setSize( 300, 100 ); setBackground(Color.gray ); // Createa panelto hold all othercomponents topPanel= newJPanel(); topPanel.setLayout(newBorderLayout()); getContentPane().add(topPanel); // Createsomeitems to add to the list String listData[] = { "Item1", "Item2", "Item3", "Item4" }; // Createa newlistbox control listbox = newJList( listData); topPanel.add( listbox,BorderLayout.CENTER); } // Main entry point forthis example public static void main( String args[] ) {
  • 9. // Createan instanceof the test application ListExamplemainFrame= new ListExample(); mainFrame.setVisible( true); } } Q.14 What is the purpose oftabbed panes?Explain with suitable examples. Ans:  A tabbed panescomponentletsthe user switch between a group of componentsby clicking on a tab with a given title and/oricon.  The user chooseswhich componentto view by selecting the tab corresponding to thedesired component.  Tabs/componentsareadded to a TabbedPaneobjectby using theaddTab and insertTab methods.  A tab is represented by an index corresponding to theposition it was added in,wherethe first tab hasan index equalto 0 and the last tab hasan index equalto thetab countminus1.  The TabbedPaneusesa SingleSelectionModelto representtheset of tab indices and the currently selected index.If the tab countis greaterthan 0, then there will alwaysbea selected index,which by defaultwill be initialized to the first tab.If the tab countis 0, then theselected index will be -1. JTabbedPaneConstructor 1. JTabbedPane() Createsan emptyTabbedPanewith a defaulttab placementof JTabbedPane.TOP. 2. JTabbedPane(inttabPlacement) Createsan emptyTabbedPanewith thespecified tab placementof either: JTabbedPane.TOP, JTabbedPane.BOTTOM,JTabbedPane.LEFT,orJTabbedPane.RIGHT. 3. JTabbedPane(inttabPlacement,inttabLayoutPolicy) Createsan emptyTabbedPanewith thespecified tab placementand tab layoutpolicy. Example: JTabbedPanetabbedPane=newJTabbedPane(); ImageIcon icon = createImageIcon("images/middle.gif"); JComponentpanel1=makeTextPanel("Panel#1"); tabbedPane.addTab("Tab1",icon,panel1, "Doesnothing"); tabbedPane.setMnemonicAt(0,KeyEvent.VK_1); JComponentpanel2=makeTextPanel("Panel#2"); tabbedPane.addTab("Tab2",icon,panel2, "Doestwice asmuch nothing"); tabbedPane.setMnemonicAt(1,KeyEvent.VK_2); JComponentpanel3=makeTextPanel("Panel#3"); tabbedPane.addTab("Tab3",icon,panel3, "Still doesnothing"); tabbedPane.setMnemonicAt(2,KeyEvent.VK_3);