What are advanced swing components? Explain each of theses components with example.

 Using Split Panes

A JSplitPane displays two components, either side by side or one on top of the other. By dragging the divider that appears between the components, the user can specify how much of the split pane's total area goes to each component. We can divide screen space among three or more components by putting split panes inside of split panes. Instead of adding the components of interest directly to a split pane, we often put each component into a scroll We then put the scroll panes into the split pane. This allows the user to view any part of a component of interest, without requiring the component to take up a lot of screen space or adapt to displaying itself in varying amounts of screen space. We can create split panes by using any one of the following constructors: pane

JSplit Pane()

JSplit Pane(int orientation)

JSplit Pane(int orientation, boolean repaint)

JSplit Pane(int orientation, Component fist, Component second) Split Pane(int orientation, boolean repaint, Component fist, Component second)

Example

import javax.swing.*;

import java.awt.";

class SPDemo extends JFrame

{

SplitPane sp;

JTextField tb;

JLabel lb;

SPDemo ()

{

setSize(400, 300);

setDefault LookAndFeelDecorated (true);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

set Layout (new BorderLayout());

JPanel p1=new JPanel();

JPanel p2=new JPanel();

JPanel p3=new JPanel();

pl.setLayout (new Border Layout());

p2.setLayout (new FlowLayout()); 

pl.setPreferredSize(new Dimension (50,50));

ImageIcon ic-new ImageIcon("us.jpg");

 p1.add(new JLabel(ic), BorderLayout .CENTER); 

lb-new JLabel("Email"); 

tb-new JTextField(10); 

p2.add(tb);

p2.add(lb);

p3.setBackground (Color.CYAN);

sp= new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, p1,p2); 

add (sp, BorderLayout.CENTER); 

add (p3, BorderLayout.SOUTH);

 setVisible (true);

}

public static void main(String args[])

{

SPDemo frame=new SPDemo();

}

}


2.  Using Tabbed Panes
With the TabbedPane class, we can have several components that share the same space. The user chooses which component to view by selecting the tab corresponding to the desired component To create a tabbed pane, instantiate JTabbedPane, create the components you wish it to display, and then add the components to the tabbed pane using the addTab() method. The default tab placement is set to the TOP location. we can change the tab placement to LEFT, RIGHT, TOP or BOTTOM by using the setTabPlacement method. We can create tabbed pane by using any one of following constructor: 
JTabbed Pane() 
JTabbedPane(int tab_location)
JTabbed Pane(int tab_location, int layout Policy)

Example
import javax.swing.*;
public class TabbedPane extends JFrame
{
public Tabbed Pane ()
{
setTitle("Tabbed Pane");
add(jtp);
JPanel jp1 = new JPanel();
JTabbedPane jtp= new JTabbedPane(); JLabel label2 = new JLabel(); label2.setText("You are in area of Tab2");
JPanel jp2= new JPanel(); JLabel label1 = new JLabel();
label1.setText("You are in area of Tab1");
jp1.add(label1);
jp2.add(label2); 
jtp.addTab("Tab1", jp1);
jtp.addTab("Tab2", jp2);
}
public static void main(String[] args)
{
Tabbed Pane tp = new TabbedPane(); tp.setDefaultCloseOperation ( JFrame.EXIT_ON_CLOSE);
tp.setSize(400, 300); 
tp.setVisible(true);
}
}

JTree, JTable and JProgressBar Components
JTree is a control that displays a set of hierarchical data as an outline. A JTree object does not actually contain your data; it simply provides a view of the data. We can create tree nodes by creating instance of DefaultMutable TreeNode class. Once the node is created, we can add nodes to other node by using addNode() method. We can create trees by using any one of following constructors:
JTree()
JTree(rootnode)
Tree(Object[] node_data)

With the Table class we can display tables of data, optionally allowing the user to edit the data. JTable does not contain or cache data; it is simply a view of our data. JTables are typically placed inside of a JScrollPane. By default, a JTable will adjust its width such that a horizontal scrollbar is unnecessary. To allow for a horizontal scrollbar, invoke setAutoResizeMode(int) with AUTO_RESIZE OFF. We can create JTable by using any one of following constructors:
JTable()
JTable(int rows, int cols)
JTable(object[] data, Object col_names)

ProgressBar is a component that visually displays the progress of some task. As the task progresses towards completion, the progress bar displays the task's percentage of completion. This percentage is typically represented visually by a rectangle that starts out empty and gradually becomes filled in as the task progresses. By default, the minimum and maximum value of the progress bar is 0 and 100 and the orientation is horizontal. But we can change the minimum and maximum value either by specifying it in constructor or by using methods setMinimum() & setMaximum(. We can also change the orientation of progress bars. Orientation can be either HORIZONTAL or VERTICAL. We can use the following constructor to create progress bars.
ProgressBar()
ProgressBar(minvalue,maxvalue)
ProgressBar(orientation)
JProgressBarforientation, minvalue,maxvalue)

Example
import javax.swing.*;
import javax.swing.border.*;
import javax.swing.tree.*;
import java.awt.";
class ASComp extends JFrame
{
JList list;
Tree tree;
JTable table;
JProgressBar pb;
JScrollPane sp;
ASComp()
{
setSize(400, 300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setDefault LookAndFeelDecorated (true); setTitle("Adavanced Swing Components"); set Layout (new FlowLayout (20, 10, FlowLayout.CENTER));
//creating list
String items []={"Apple","Banana", "Mango", "Orange", "Papayya"};
list-new JList(items);
list.setBorder (Border Factory.createLineBorder (Color.blue)); add (list);
//creating trees
DefaultMutableTreeNode root = new DefaultMutable TreeNode ("Root");
DefaultMutableTreeNode vegetableNode =
new DefaultMutableTreeNode ("Vegetables");
DefaultMutableTreeNode fruitNode =
new DefaultMutable TreeNode ("Fruits");
root.add(vegetableNode);
root.add(fruitNode); add (tree);
tree new JTree(root);
//creating table
String[] cn={"Title", "Artist", "Album");
String[][] data={{"a1", "Aani","x1"), {"a2", "Suren","x2"}}; table=new JTable (data,cn); sp=new JScrollPane (table); add (sp);
//creating progressbar pb.setValue (30);
pb=new JProgressBar();
add (pb);
setVisible (true);
} public static void main(String args[]) {
ASComp frame=new ASComp();
}
}






Comments

Popular posts from this blog

Suppose that a data warehouse for Big-University consists of the following four dimensions: student, course, semester, and instructor, and two measures count and avg_grade. When at the lowest conceptual level (e.g., for a given student, course, semester, and instructor combination), the avg_grade measure stores the actual course grade of the student. At higher conceptual levels, avg_grade stores the average grade for the given combination. a) Draw a snowflake schema diagram for the data warehouse. b) Starting with the base cuboid [student, course, semester, instructor], what specific OLAP operations (e.g., roll-up from semester to year) should one perform in order to list the average grade of CS courses for each BigUniversity student. c) If each dimension has five levels (including all), such as “student < major < status < university < all”, how many cuboids will this cube contain (including the base and apex cuboids)?

Short note on E-Government Architecture

Discuss classification or taxonomy of virtualization at different levels.