Question
stringlengths 1
113
| Answer
stringlengths 22
6.98k
|
|---|---|
What is Java JRootPane?
|
RootPane is a lightweight container used behind the scenes by JFrame, JDialog, JWindow, JApplet, and JInternalFrame.
|
Can you provide an example of JRootPane?
|
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JRootPane;
public class JRootPaneExample {
public static void main(String[] args) {
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JRootPane root = f.getRootPane();
// Create a menu bar
JMenuBar bar = new JMenuBar();
JMenu menu = new JMenu("File");
bar.add(menu);
menu.add("Open");
menu.add("Close");
root.setJMenuBar(bar);
// Add a button to the content pane
root.getContentPane().add(new JButton("Press Me"));
// Display the UI
f.pack();
f.setVisible(true);
}
}
|
How to use ToolTip in Java Swing?
|
You can create a tool tip for any JComponent with setToolTipText() method. This method is used to set up a tool tip for the component.
For example, to add tool tip to PasswordField, you need to add only one line of code:
field.setToolTipText("Enter your Password");
|
Can you provide an example of Simple ToolTip?
|
import javax.swing.*;
public class ToolTipExample {
public static void main(String[] args) {
JFrame f=new JFrame("Password Field Example");
//Creating PasswordField and label
JPasswordField value = new JPasswordField();
value.setBounds(100,100,100,30);
value.setToolTipText("Enter your Password");
JLabel l1=new JLabel("Password:");
l1.setBounds(20,100, 80,30);
//Adding components to frame
f.add(value); f.add(l1);
f.setSize(300,300);
f.setLayout(null);
f.setVisible(true);
}
}
|
How to change TitleBar icon in Java AWT and Swing?
|
The setIconImage() method of Frame class is used to change the icon of Frame or Window. It changes the icon which is displayed at the left side of Frame or Window.
The Toolkit class is used to get instance of Image class in AWT and Swing.
Toolkit class is the abstract super class of every implementation in the Abstract Window Toolkit(AWT). Subclasses of Toolkit are used to bind various components. It inherits Object class.
|
Can you provide an Example to change TitleBar icon in Java AWT?
|
import java.awt.*;
class IconExample {
IconExample(){
Frame f=new Frame();
Image icon = Toolkit.getDefaultToolkit().getImage("D:\\icon.png");
f.setIconImage(icon);
f.setLayout(null);
f.setSize(400,400);
f.setVisible(true);
}
public static void main(String args[]){
new IconExample();
}
}
|
Can you provide an Example to change TitleBar icon in Java Swing?
|
import javax.swing.*;
import java.awt.*;
class IconExample {
IconExample(){
JFrame f=new JFrame();
Image icon = Toolkit.getDefaultToolkit().getImage("D:\\icon.png");
f.setIconImage(icon);
f.setLayout(null);
f.setSize(200,200);
f.setVisible(true);
}
public static void main(String args[]){
new ToolkitExample();
}
}
|
How to make an executable jar file in Java?
|
The jar (Java Archive) tool of JDK provides the facility to create the executable jar file. An executable jar file calls the main method of the class if you double click it.
To create the executable jar file, you need to create .mf file, also known as manifest file.
|
What is jar (Java Archive)?
|
The jar (Java Archive) tool of JDK provides the facility to create the executable jar file. An executable jar file calls the main method of the class if you double click it.
To create the executable jar file, you need to create .mf file, also known as manifest file.
|
What is Creating manifest file?
|
To create manifest file, you need to write Main-Class, then colon, then space, then classname then enter. For example:
myfile.mf
Main-Class: First
As you can see, the mf file starts with Main-Class colon space class name. Here, class name is First.
In mf file, new line is must after the class name.
|
What is Creating executable jar file using jar tool?
|
The jar tool provides many switches, some of them are as follows:
1-c creates new archive file
2-v generates verbose output. It displays the included or extracted resource on the standard output.
3-m includes manifest information from the given mf file.
4-f specifies the archive file name
5.-x extracts files from the archive file
Now, let's write the code to generated the executable jar using mf file.
You need to write jar then swiches then mf_file then jar_file then .classfile as given below:
jar -cvmf myfile.mf myjar.jar First.class
|
Can you provide an Example of digital clock in swing:?
|
import javax.swing.*;
import java.awt.*;
import java.text.*;
import java.util.*;
public class DigitalWatch implements Runnable{
JFrame f;
Thread t=null;
int hours=0, minutes=0, seconds=0;
String timeString = "";
JButton b;
DigitalWatch(){
f=new JFrame();
t = new Thread(this);
t.start();
b=new JButton();
b.setBounds(100,100,100,50);
f.add(b);
f.setSize(300,400);
f.setLayout(null);
f.setVisible(true);
}
public void run() {
try {
while (true) {
Calendar cal = Calendar.getInstance();
hours = cal.get( Calendar.HOUR_OF_DAY );
if ( hours > 12 ) hours -= 12;
minutes = cal.get( Calendar.MINUTE );
seconds = cal.get( Calendar.SECOND );
SimpleDateFormat formatter = new SimpleDateFormat("hh:mm:ss");
Date date = cal.getTime();
timeString = formatter.format( date );
printTime();
t.sleep( 1000 ); // interval given in milliseconds
}
}
catch (Exception e) { }
}
public void printTime(){
b.setText(timeString);
}
public static void main(String[] args) {
new DigitalWatch();
}
}
|
What is Displaying graphics in swing:?
|
java.awt.Graphics class provides many methods for graphics programming.
|
What is public abstract void drawString(String str, int x, int y)?
|
public abstract void drawString(String str, int x, int y): is used to draw the specified string.
|
What is public void drawRect(int x, int y, int width, int height)?
|
public void drawRect(int x, int y, int width, int height): draws a rectangle with the specified width and height.
|
What is public abstract void fillRect(int x, int y, int width, int height)?
|
public abstract void fillRect(int x, int y, int width, int height): is used to fill rectangle with the default color and specified width and height.
|
What is public abstract void drawOval(int x, int y, int width, int height)?
|
public abstract void drawOval(int x, int y, int width, int height): is used to draw oval with the specified width and height.
|
What is public abstract void fillOval(int x, int y, int width, int height)?
|
public abstract void fillOval(int x, int y, int width, int height): is used to fill oval with the default color and specified width and height.
|
What is public abstract void drawLine(int x1, int y1, int x2, int y2)?
|
public abstract void drawLine(int x1, int y1, int x2, int y2): is used to draw line between the points(x1, y1) and (x2, y2).
|
What is public abstract boolean drawImage(Image img, int x, int y, ImageObserver observer)?
|
public abstract boolean drawImage(Image img, int x, int y, ImageObserver observer): is used draw the specified image.
|
What is public abstract void drawArc(int x, int y, int width, int height, int startAngle, int arcAngle)?
|
public abstract void drawArc(int x, int y, int width, int height, int startAngle, int arcAngle): is used draw a circular or elliptical arc.
|
What is public abstract void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle)?
|
public abstract void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle): is used to fill a circular or elliptical arc.
|
What is public abstract void setColor(Color c)?
|
public abstract void setColor(Color c): is used to set the graphics current color to the specified color.
|
What is public abstract void setFont(Font font)?
|
public abstract void setFont(Font font): is used to set the graphics current font to the specified font.
|
Can you provide an Example of displaying graphics in swing?
|
import java.awt.*;
import javax.swing.JFrame;
public class DisplayGraphics extends Canvas{
public void paint(Graphics g) {
g.drawString("Hello",40,40);
setBackground(Color.WHITE);
g.fillRect(130, 30,100, 80);
g.drawOval(30,130,50, 60);
setForeground(Color.RED);
g.fillOval(130,130,50, 60);
g.drawArc(30, 200, 40,50,90,60);
g.fillArc(30, 130, 40,50,180,40);
}
public static void main(String[] args) {
DisplayGraphics m=new DisplayGraphics();
JFrame f=new JFrame();
f.add(m);
f.setSize(400,400);
//f.setLayout(null);
f.setVisible(true);
}
}
|
What is Displaying image in swing?
|
For displaying image, we can use the method drawImage() of Graphics class.
|
What is Syntax of drawImage() method?
|
public abstract boolean drawImage(Image img, int x, int y, ImageObserver observer): is used draw the specified image.
|
What is public abstract boolean drawImage(Image img, int x, int y, ImageObserver observer)?
|
public abstract boolean drawImage(Image img, int x, int y, ImageObserver observer): is used draw the specified image.
|
Can you provide an Example of displaying image in swing?
|
import java.awt.*;
import javax.swing.JFrame;
public class MyCanvas extends Canvas{
public void paint(Graphics g) {
Toolkit t=Toolkit.getDefaultToolkit();
Image i=t.getImage("p3.gif");
g.drawImage(i, 120,100,this);
}
public static void main(String[] args) {
MyCanvas m=new MyCanvas();
JFrame f=new JFrame();
f.add(m);
f.setSize(400,400);
f.setVisible(true);
}
}
|
What are the Java LayoutManagers?
|
The LayoutManagers are used to arrange components in a particular manner. The Java LayoutManagers facilitates us to control the positioning and size of the components in GUI forms. LayoutManager is an interface that is implemented by all the classes of layout managers. There are the following classes that represent the layout managers:
1.java.awt.BorderLayout
2.java.awt.FlowLayout
3.java.awt.GridLayout
4.java.awt.CardLayout
5.java.awt.GridBagLayout
6.javax.swing.BoxLayout
7.javax.swing.GroupLayout
8.javax.swing.ScrollPaneLayout
9.javax.swing.SpringLayout etc.
|
What are the Java BorderLayout?
|
The BorderLayout is used to arrange the components in five regions: north, south, east, west, and center. Each region (area) may contain one component only. It is the default layout of a frame or window. The BorderLayout provides five constants for each region:
1.public static final int NORTH
2.public static final int SOUTH
3.public static final int EAST
4.public static final int WEST
5.public static final int CENTER
|
What are the Constructors of BorderLayout class:?
|
-BorderLayout(): creates a border layout but with no gaps between the components.
-BorderLayout(int hgap, int vgap): creates a border layout with the given horizontal and vertical gaps between the components.
|
Can you provide an Example of BorderLayout class: Using BorderLayout() constructor?
|
FileName: Border.java
import java.awt.*;
import javax.swing.*;
public class Border
{
JFrame f;
Border()
{
f = new JFrame();
// creating buttons
JButton b1 = new JButton("NORTH");; // the button will be labeled as NORTH
JButton b2 = new JButton("SOUTH");; // the button will be labeled as SOUTH
JButton b3 = new JButton("EAST");; // the button will be labeled as EAST
JButton b4 = new JButton("WEST");; // the button will be labeled as WEST
JButton b5 = new JButton("CENTER");; // the button will be labeled as CENTER
f.add(b1, BorderLayout.NORTH); // b1 will be placed in the North Direction
f.add(b2, BorderLayout.SOUTH); // b2 will be placed in the South Direction
f.add(b3, BorderLayout.EAST); // b2 will be placed in the East Direction
f.add(b4, BorderLayout.WEST); // b2 will be placed in the West Direction
f.add(b5, BorderLayout.CENTER); // b2 will be placed in the Center
f.setSize(300, 300);
f.setVisible(true);
}
public static void main(String[] args) {
new Border();
}
}
|
What is Java GridLayout?
|
The Java GridLayout class is used to arrange the components in a rectangular grid. One component is displayed in each rectangle.
|
What are the Constructors of GridLayout class?
|
1.GridLayout(): creates a grid layout with one column per component in a row.
2.GridLayout(int rows, int columns): creates a grid layout with the given rows and columns but no gaps between the components.
3.GridLayout(int rows, int columns, int hgap, int vgap): creates a grid layout with the given rows and columns along with given horizontal and vertical gaps.
|
Can you provide an Example of GridLayout class: Using GridLayout() Constructor?
|
The GridLayout() constructor creates only one row. The following example shows the usage of the parameterless constructor.
FileName: GridLayoutExample.java
// import statements
import java.awt.*;
import javax.swing.*;
public class GridLayoutExample
{
JFrame frameObj;
// constructor
GridLayoutExample()
{
frameObj = new JFrame();
// creating 9 buttons
JButton btn1 = new JButton("1");
JButton btn2 = new JButton("2");
JButton btn3 = new JButton("3");
JButton btn4 = new JButton("4");
JButton btn5 = new JButton("5");
JButton btn6 = new JButton("6");
JButton btn7 = new JButton("7");
JButton btn8 = new JButton("8");
JButton btn9 = new JButton("9");
// adding buttons to the frame
// since, we are using the parameterless constructor, therfore;
// the number of columns is equal to the number of buttons we
// are adding to the frame. The row count remains one.
frameObj.add(btn1); frameObj.add(btn2); frameObj.add(btn3);
frameObj.add(btn4); frameObj.add(btn5); frameObj.add(btn6);
frameObj.add(btn7); frameObj.add(btn8); frameObj.add(btn9);
// setting the grid layout using the parameterless constructor
frameObj.setLayout(new GridLayout());
frameObj.setSize(300, 300);
frameObj.setVisible(true);
}
// main method
public static void main(String argvs[])
{
new GridLayoutExample();
}
} .
|
What is Java FlowLayout?
|
The Java FlowLayout class is used to arrange the components in a line, one after another (in a flow). It is the default layout of the applet or panel.
|
What are the Fields of FlowLayout class?
|
1.public static final int LEFT
2.public static final int RIGHT
3.public static final int CENTER
4.public static final int LEADING
5.public static final int TRAILING
|
What are the Constructors of FlowLayout class?
|
1.FlowLayout(): creates a flow layout with centered alignment and a default 5 unit horizontal and vertical gap.
2.FlowLayout(int align): creates a flow layout with the given alignment and a default 5 unit horizontal and vertical gap.
3.FlowLayout(int align, int hgap, int vgap): creates a flow layout with the given alignment and the given horizontal and vertical gap.
|
Can you provide an Example of FlowLayout class: Using FlowLayout() constructor?
|
FileName: FlowLayoutExample.java
// import statements
import java.awt.*;
import javax.swing.*;
public class FlowLayoutExample
{
JFrame frameObj;
// constructor
FlowLayoutExample()
{
// creating a frame object
frameObj = new JFrame();
// creating the buttons
JButton b1 = new JButton("1");
JButton b2 = new JButton("2");
JButton b3 = new JButton("3");
JButton b4 = new JButton("4");
JButton b5 = new JButton("5");
JButton b6 = new JButton("6");
JButton b7 = new JButton("7");
JButton b8 = new JButton("8");
JButton b9 = new JButton("9");
JButton b10 = new JButton("10");
// adding the buttons to frame
frameObj.add(b1); frameObj.add(b2); frameObj.add(b3); frameObj.add(b4);
frameObj.add(b5); frameObj.add(b6); frameObj.add(b7); frameObj.add(b8);
frameObj.add(b9); frameObj.add(b10);
// parameter less constructor is used
// therefore, alignment is center
// horizontal as well as the vertical gap is 5 units.
frameObj.setLayout(new FlowLayout());
frameObj.setSize(300, 300);
frameObj.setVisible(true);
}
// main method
public static void main(String argvs[])
{
new FlowLayoutExample();
}
}
|
What is Java BoxLayout?
|
The Java BoxLayout class is used to arrange the components either vertically or horizontally. For this purpose, the BoxLayout class provides four constants. They are as follows:
Note: The BoxLayout class is found in javax.swing package.
|
What are the Fields of BoxLayout Class?
|
1.public static final int X_AXIS: Alignment of the components are horizontal from left to right.
2.public static final int Y_AXIS: Alignment of the components are vertical from top to bottom.
3.public static final int LINE_AXIS: Alignment of the components is similar to the way words are aligned in a line, which is based on the ComponentOrientation property of the container. If the ComponentOrientation property of the container is horizontal, then the components are aligned horizontally; otherwise, the components are aligned vertically. For horizontal orientations, we have two cases: left to right, and right to left. If the value ComponentOrientation property of the container is from left to right, then the components are rendered from left to right, and for right to left, the rendering of components is also from right to left. In the case of vertical orientations, the components are always rendered from top to bottom.
4.public static final int PAGE_AXIS: Alignment of the components is similar to the way text lines are put on a page, which is based on the ComponentOrientation property of the container. If the ComponentOrientation property of the container is horizontal, then components are aligned vertically; otherwise, the components are aligned horizontally. For horizontal orientations, we have two cases: left to right, and right to left. If the value ComponentOrientation property of the container is also from left to right, then the components are rendered from left to right, and for right to left, the rendering of components is from right to left. In the case of vertical orientations, the components are always rendered from top to bottom.
|
What is Constructor of BoxLayout class?
|
BoxLayout(Container c, int axis): creates a box layout that arranges the components with the given axis.
|
Can you provide an Example of BoxLayout class with Y-AXIS:?
|
FileName: BoxLayoutExample1.java
import java.awt.*;
import javax.swing.*;
public class BoxLayoutExample1 extends Frame {
Button buttons[];
public BoxLayoutExample1 () {
buttons = new Button [5];
for (int i = 0;i<5;i++) {
buttons[i] = new Button ("Button " + (i + 1));
// adding the buttons so that it can be displayed
add (buttons[i]);
}
// the buttons will be placed horizontally
setLayout (new BoxLayout (this, BoxLayout.Y_AXIS));
setSize(400,400);
setVisible(true);
}
// main method
public static void main(String args[]){
BoxLayoutExample1 b=new BoxLayoutExample1();
}
}
|
Can you provide an Example of BoxLayout class with X-AXIS?
|
FileName: BoxLayoutExample2.java
import java.awt.*;
import javax.swing.*;
public class BoxLayoutExample2 extends Frame {
Button buttons[];
public BoxLayoutExample2() {
buttons = new Button [5];
for (int i = 0;i<5;i++) {
buttons[i] = new Button ("Button " + (i + 1));
// adding the buttons so that it can be displayed
add (buttons[i]);
}
// the buttons in the output will be aligned vertically
setLayout (new BoxLayout(this, BoxLayout.X_AXIS));
setSize(400,400);
setVisible(true);
}
// main method
public static void main(String args[]){
BoxLayoutExample2 b=new BoxLayoutExample2();
}
}
|
Can you provide an Example of BoxLayout Class with LINE_AXIS?
|
The following example shows the effect of setting the value of ComponentOrientation property of the container to RIGHT_TO_LEFT. If we do not set the value of ComponentOrientation property, then the components would be laid out from left to right. Comment line 11, and see it yourself.
FileName: BoxLayoutExample3.java
// import statements
import java.awt.*;
import javax.swing.*;
public class BoxLayoutExample3 extends Frame
{
Button buttons[];
// constructor of the class
public BoxLayoutExample3()
{
buttons = new Button[5];
setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT); // line 11
for (int i = 0; i < 5; i++)
{
buttons[i] = new Button ("Button " + (i + 1));
// adding the buttons so that it can be displayed
add (buttons[i]);
}
// the ComponentOrientation is set to RIGHT_TO_LEFT. Therefore,
// the added buttons will be rendered from right to left
setLayout (new BoxLayout(this, BoxLayout.LINE_AXIS));
setSize(400, 400);
setVisible(true);
}
// main method
public static void main(String argvs[])
{
// creating an object of the class BoxLayoutExample3
BoxLayoutExample3 obj = new BoxLayoutExample3();
}
}
|
Can you provide an Example of BoxLayout Class with PAGE_AXIS?
|
The following example shows how to use PAGE_AXIS.
FileName: BoxLayoutExample4.java
// import statements
import java.awt.*;
import javax.swing.*;
public class BoxLayoutExample4 extends Frame
{
Button buttons[];
// constructor of the class
public BoxLayoutExample4()
{
JFrame f = new JFrame();
JPanel pnl = new JPanel();
buttons = new Button[5];
GridBagConstraints constrntObj = new GridBagConstraints();
constrntObj.fill = GridBagConstraints.VERTICAL;
for (int i = 0; i < 5; i++)
{
buttons[i] = new Button ("Button " + (i + 1));
// adding the buttons so that it can be displayed
add(buttons[i]);
}
// the components will be displayed just like the line is present on a page
setLayout (new BoxLayout(this, BoxLayout.PAGE_AXIS));
setSize(400, 400);
setVisible(true);
}
// main method
public static void main(String argvs[])
{
// creating an object of the class BoxLayoutExample4
BoxLayoutExample4 obj = new BoxLayoutExample4();
}
}
|
What is Java CardLayout?
|
The Java CardLayout class manages the components in such a manner that only one component is visible at a time. It treats each component as a card that is why it is known as CardLayout.
|
What are the Constructors of CardLayout Class?
|
1.CardLayout(): creates a card layout with zero horizontal and vertical gap.
2.CardLayout(int hgap, int vgap): creates a card layout with the given horizontal and vertical gap.
|
What are the Commonly Used Methods of CardLayout Class?
|
-public void next(Container parent): is used to flip to the next card of the given container.
-public void previous(Container parent): is used to flip to the previous card of the given container.
-public void first(Container parent): is used to flip to the first card of the given container.
-public void last(Container parent): is used to flip to the last card of the given container.
-public void show(Container parent, String name): is used to flip to the specified card with the given name.
|
Can you provide an Example of CardLayout Class: Using Default Constructor
|
The following program uses the next() method to move to the next card of the container.
FileName: CardLayoutExample1.java
// import statements
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class CardLayoutExample1 extends JFrame implements ActionListener
{
CardLayout crd;
// button variables to hold the references of buttons
JButton btn1, btn2, btn3;
Container cPane;
// constructor of the class
CardLayoutExample1()
{
cPane = getContentPane();
//default constructor used
// therefore, components will
// cover the whole area
crd = new CardLayout();
cPane.setLayout(crd);
// creating the buttons
btn1 = new JButton("Apple");
btn2 = new JButton("Boy");
btn3 = new JButton("Cat");
// adding listeners to it
btn1.addActionListener(this);
btn2.addActionListener(this);
btn3.addActionListener(this);
cPane.add("a", btn1); // first card is the button btn1
cPane.add("b", btn2); // first card is the button btn2
cPane.add("c", btn3); // first card is the button btn3
}
public void actionPerformed(ActionEvent e)
{
// Upon clicking the button, the next card of the container is shown
// after the last card, again, the first card of the container is shown upon clicking
crd.next(cPane);
}
// main method
public static void main(String argvs[])
{
// creating an object of the class CardLayoutExample1
CardLayoutExample1 crdl = new CardLayoutExample1();
// size is 300 * 300
crdl.setSize(300, 300);
crdl.setVisible(true);
crdl.setDefaultCloseOperation(EXIT_ON_CLOSE);
}
}
|
What is Java GridBagLayout?
|
The Java GridBagLayout class is used to align components vertically, horizontally or along their baseline.
The components may not be of the same size. Each GridBagLayout object maintains a dynamic, rectangular grid of cells. Each component occupies one or more cells known as its display area. Each component associates an instance of GridBagConstraints. With the help of the constraints object, we arrange the component's display area on the grid. The GridBagLayout manages each component's minimum and preferred sizes in order to determine the component's size. GridBagLayout components are also arranged in the rectangular grid but can have many different sizes and can occupy multiple rows or columns.
|
What is GridBagLayout Fields?
|
Modifier and Type: double[]
Field: columnWeights
Description: It is used to hold the overrides to the column weights.
Modifier and Type: int[]
Field: columnWidths
Description: It is used to hold the overrides to the column minimum width.
Modifier and Type: protected Hashtable<Component,GridBagConstraints>
Field: comptable
Description: It is used to maintains the association between a component and its gridbag constraints.
Modifier and Type: protected GridBagConstraints
Field: defaultConstraints
Description: It is used to hold a gridbag constraints instance containing the default values.
Modifier and Type: protected GridBagLayoutInfo
Field: layoutInfo
Description: It is used to hold the layout information for the gridbag.
Modifier and Type: protected static int
Field: MAXGRIDSIZE
Description: No longer in use just for backward compatibility
Modifier and Type: protected static int
Field: MINSIZE
Description: It is smallest grid that can be laid out by the grid bag layout.
Modifier and Type: protected static int
Field: PREFERREDSIZE
Description: It is preferred grid size that can be laid out by the grid bag layout.
Modifier and Type: int[]
Field: rowHeights
Description: It is used to hold the overrides to the row minimum heights.
Modifier and Type: double[]
Field: rowWeights
Description: It is used to hold the overrides to the row weights.
|
Can you give me GridBagLayout Methods?
|
Modifier and Type: void
Method: addLayoutComponent(Component comp, Object constraints)
Description: It adds specified component to the layout, using the specified constraints object.
Modifier and Type: void
Method: addLayoutComponent(String name, Component comp)
Description: It has no effect, since this layout manager does not use a per-component string.
Modifier and Type: protected void
Method: adjustForGravity(GridBagConstraints constraints, Rectangle r)
Description: It adjusts the x, y, width, and height fields to the correct values depending on the constraint geometry and pads.
Modifier and Type: protected void
Method: AdjustForGravity(GridBagConstraints constraints, Rectangle r)
Description: This method is for backwards compatibility only
Modifier and Type: protected void
Method: arrangeGrid(Container parent)
Description: Lays out the grid.
Modifier and Type: protected void
Method: ArrangeGrid(Container parent)
Description: This method is obsolete and supplied for backwards compatibility
Modifier and Type: GridBagConstraints
Method: getConstraints(Component comp)
Description: It is for getting the constraints for the specified component.
Modifier and Type: float
Method: getLayoutAlignmentX(Container parent)
Description: It returns the alignment along the x axis.
Modifier and Type: float
Method: getLayoutAlignmentY(Container parent)
Description: It returns the alignment along the y axis.
Modifier and Type: int[][]
Method: getLayoutDimensions()
Description: It determines column widths and row heights for the layout grid.
Modifier and Type: protected GridBagLayoutInfo
Method: getLayoutInfo(Container parent, int sizeflag)
Description: This method is obsolete and supplied for backwards compatibility.
Modifier and Type: protected GridBagLayoutInfo
Method: GetLayoutInfo(Container parent, int sizeflag)
Description: This method is obsolete and supplied for backwards compatibility.
Modifier and Type: Point
Method: getLayoutOrigin()
Description: It determines the origin of the layout area, in the graphics coordinate space of the target container.
Modifier and Type: double[][]
Method: getLayoutWeights()
Description: It determines the weights of the layout grid's columns and rows.
Modifier and Type: protected Dimension
Method: getMinSize(Container parent, GridBagLayoutInfo info)
Description: It figures out the minimum size of the master based on the information from getLayoutInfo.
Modifier and Type: protected Dimension
Method: GetMinSize(Container parent, GridBagLayoutInfo info)
Description: This method is obsolete and supplied for backwards compatibility only
|
What is GroupLayout?
|
GroupLayout groups its components and places them in a Container hierarchically. The grouping is done by instances of the Group class.
Group is an abstract class, and two concrete classes which implement this Group class are SequentialGroup and ParallelGroup.
SequentialGroup positions its child sequentially one after another whereas ParallelGroup aligns its child on top of each other.
The GroupLayout class provides methods such as createParallelGroup() and createSequentialGroup() to create groups.
GroupLayout treats each axis independently. That is, there is a group representing the horizontal axis, and a group representing the vertical axis. Each component must exist in both a horizontal and vertical group, otherwise an IllegalStateException is thrown during layout or when the minimum, preferred, or maximum size is requested.
|
What is Java SpringLayout?
|
A SpringLayout arranges the children of its associated container according to a set of constraints. Constraints are nothing but horizontal and vertical distance between two-component edges. Every constraint is represented by a SpringLayout.Constraint object.
Each child of a SpringLayout container, as well as the container itself, has exactly one set of constraints associated with them.
Each edge position is dependent on the position of the other edge. If a constraint is added to create a new edge, than the previous binding is discarded. SpringLayout doesn't automatically set the location of the components it manages.
|
What is pringLayout Fields?
|
Modifier and Type: static String
Field: BASELINE
Description: It specifies the baseline of a component.
Modifier and Type: static String
Field: EAST
Description: It specifies the right edge of a component's bounding rectangle.
Modifier and Type: static String
Field: HEIGHT
Description: It specifies the height of a component's bounding rectangle.
Modifier and Type: static String
Field: HORIZONTAL_CENTER
Description: It specifies the horizontal center of a component's bounding rectangle.
Modifier and Type: static String
Field: NORTH
Description: It specifies the top edge of a component's bounding rectangle.
Modifier and Type: static String
Field: SOUTH
Description: It specifies the bottom edge of a component's bounding rectangle.
Modifier and Type: static String
Field: VERTICAL_CENTER
Description: It specifies the vertical center of a component's bounding rectangle.
Modifier and Type: static String
Field: WEST
Description: It specifies the left edge of a component's bounding rectangle.
Modifier and Type: static String
Field: WIDTH
Description: It specifies the width of a component's bounding rectangle.
|
Can you give SpringLayout Methods?
|
SpringLayout Methods
Modifier and Type: void
Method: addLayoutComponent(Component component, Object constraints)
Description: If constraints is an instance of SpringLayout. Constraints, associates the constraints with the specified component.
Modifier and Type: void
Method: addLayoutComponent(String name, Component c)
Description: Has no effect, since this layout manager does not use a per-component string.
Modifier and Type: Spring
Method: getConstraint(String edgeName, Component c)
Description: It returns the spring controlling the distance between the specified edge of the component and the top or left edge of its parent.
Modifier and Type: SpringLayout.Constraints
Method: getConstraints(Component c)
Description:
It returns the constraints for the specified component.
Modifier and Type: float
Method: getLayoutAlignmentX(Container p)
Description: It returns 0.5f (centered).
Modifier and Type: float
Method: getLayoutAlignmentY(Container p)
Description: It returns 0.5f (centered).
Modifier and Type: void
Method: invalidateLayout(Container p)
Description: It Invalidates the layout, indicating that if the layout manager has cached information it should be discarded.
Modifier and Type: void
Method: layoutContainer(Container parent)
Description: It lays out the specified container.
Modifier and Type: Dimension
Method: maximumLayoutSize(Container parent)
Description: It is used to calculates the maximum size dimensions for the specified container, given the components it contains.
Modifier and Type: Dimension
Method: minimumLayoutSize(Container parent)
Description: It is used to calculates the minimum size dimensions for the specified container, given the components it contains.
Modifier and Type: Dimension
Method: preferredLayoutSize(Container parent)
Description: It is used to calculates the preferred size dimensions for the specified container, given the components it contains.
|
What is ScrollPaneLayout?
|
The layout manager is used by JScrollPane. JScrollPaneLayout is responsible for nine components: a viewport, two scrollbars, a row header, a column header, and four "corner" components.
|
FieldScrollPanelLayout Field
|
Modifier and Type: protected JViewport
Field: colHead
Description: It is column header child.
Modifier and Type: protected JScrollBar
Field: hsb
Description: It is scrollpane's horizontal scrollbar child.
Modifier and Type: protected int
Field: hsbPolicy
Description: It displays policy for the horizontal scrollbar.
Modifier and Type: protected Component
Field: lowerLeft
Description: This displays the lower left corner.
Modifier and Type: protected Component
Field: lowerRight
Description: This displays in the lower right corner.
Modifier and Type: protected JViewport
Field: rowHead
Description: It is row header child.
Modifier and Type: protected Component
Field: upperLeft
Description: This component displays in the upper left corner.
Modifier and Type: protected Component
Field: upperRight
Description: This component displays in the upper right corner.
Modifier and Type: protected JViewport
Field: viewport
Description: It is scrollpane's viewport child.
Modifier and Type: protected JScrollBar
Field: vsb
Description: It is scrollpane's vertical scrollbar child.
Modifier and Type: protected int
Field: vsbPolicy
Description: It is the display policy for the vertical scrollbar.
|
Can you give me ScrollPanelLayout Methods?
|
ScrollPanelLayout Methods
Modifier and Type: void
Method: addLayoutComponent(String s, Component c)
Description: It adds the specified component to the layout.
Modifier and Type: protected Component
Method: addSingletonComponent(Component oldC, Component newC)
Description: It removes an existing component.
Modifier and Type: JViewport
Method: getColumnHeader()
Description: It returns the JViewport object that is the column header.
Modifier and Type: Component
Method: getCorner(String key)
Description: It returns the Component at the specified corner.
Modifier and Type: JScrollBar
Method: getHorizontalScrollBar()
Description: It returns the JScrollBar object that handles horizontal scrolling.
Modifier and Type: int
Method: getHorizontalScrollBarPolicy()
Description: It returns the horizontal scrollbar-display policy.
Modifier and Type: JViewport
Method: getRowHeader()
Description: It returns the JViewport object that is the row header.
Modifier and Type: JScrollBar
Method: getVerticalScrollBar()
Description: It returns the JScrollBar object that handles vertical scrolling.
Modifier and Type: int
Method: getVerticalScrollBarPolicy()
Description: It returns the vertical scrollbar-display policy.
Modifier and Type: JViewport
Method: getViewport()
Description: It returns the JViewport object that displays the scrollable contents.
|
What is Java Applet?
|
Applet is a special type of program that is embedded in the webpage to generate the dynamic content. It runs inside the browser and works at client side.
|
What is the Advantage of Applet?
|
There are many advantages of applet. They are as follows:
-It works at client side so less response time.
-Secured
-It can be executed by browsers running under many plateforms, including Linux, Windows, Mac Os etc.
|
What is Drawback of Applet?
|
Plugin is required at client browser to execute applet.
|
What is Lifecycle of Java Applet?
|
1.Applet is initialized.
2.Applet is started.
3.Applet is painted.
4.Applet is stopped.
5.Applet is destroyed.
|
What is Lifecycle methods for Applet?
|
The java.applet.Applet class 4 life cycle methods and java.awt.Component class provides 1 life cycle methods for an applet.
|
What is java.applet.Applet class?
|
For creating any applet java.applet.Applet class must be inherited. It provides 4 life cycle methods of applet.
1.public void init(): is used to initialized the Applet. It is invoked only once.
2.public void start(): is invoked after the init() method or browser is maximized. It is used to start the Applet.
3.public void stop(): is used to stop the Applet. It is invoked when Applet is stop or browser is minimized.
4.public void destroy(): is used to destroy the Applet. It is invoked only once.
|
What is java.awt.Component class?
|
The Component class provides 1 life cycle method of applet.
1.public void paint(Graphics g): is used to paint the Applet. It provides Graphics class object that can be used for drawing oval, rectangle, arc etc.
|
Who is responsible to manage the life cycle of an applet?
|
Java Plug-in software.
|
How to run an Applet?
|
There are two ways to run an applet
1.By html file.
2.By appletViewer tool (for testing purpose).
|
Can you provide an Simple example of Applet by html file
|
To execute the applet by html file, create an applet and compile it. After that create an html file and place the applet code in html file. Now click the html file.
//First.java
import java.applet.Applet;
import java.awt.Graphics;
public class First extends Applet{
public void paint(Graphics g){
g.drawString("welcome",150,150);
}
}
Note: class must be public because its object is created by Java Plugin software that resides on the browser.
myapplet.html
<html>
<body>
<applet code="First.class" width="300" height="300">
</applet>
</body>
</html>
|
What is Displaying Graphics in Applet?
|
java.awt.Graphics class provides many methods for graphics programming.
Commonly used methods of Graphics class:
|
What is Commonly used methods of Graphics class?
|
1.public abstract void drawString(String str, int x, int y): is used to draw the specified string.
2.public void drawRect(int x, int y, int width, int height): draws a rectangle with the specified width and height.
3.public abstract void fillRect(int x, int y, int width, int height): is used to fill rectangle with the default color and specified width and height.
4.public abstract void drawOval(int x, int y, int width, int height): is used to draw oval with the specified width and height.
5.public abstract void fillOval(int x, int y, int width, int height): is used to fill oval with the default color and specified width and height.
6.public abstract void drawLine(int x1, int y1, int x2, int y2): is used to draw line between the points(x1, y1) and (x2, y2).
7.public abstract boolean drawImage(Image img, int x, int y, ImageObserver observer): is used draw the specified image.
8.public abstract void drawArc(int x, int y, int width, int height, int startAngle, int arcAngle): is used draw a circular or elliptical arc.
9.public abstract void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle): is used to fill a circular or elliptical arc.
10.public abstract void setColor(Color c): is used to set the graphics current color to the specified color.
11.public abstract void setFont(Font font): is used to set the graphics current font to the specified font.
|
Can you provide an Example of Graphics in applet?
|
import java.applet.Applet;
import java.awt.*;
public class GraphicsDemo extends Applet{
public void paint(Graphics g){
g.setColor(Color.red);
g.drawString("Welcome",50, 50);
g.drawLine(20,30,20,300);
g.drawRect(70,100,30,30);
g.fillRect(170,100,30,30);
g.drawOval(70,200,30,30);
g.setColor(Color.pink);
g.fillOval(170,200,30,30);
g.drawArc(90,150,30,30,30,270);
g.fillArc(270,150,30,30,0,180);
}
}
myapplet.html
<html>
<body>
<applet code="GraphicsDemo.class" width="300" height="300">
</applet>
</body>
</html>
|
What is Displaying Image in Applet?
|
Applet is mostly used in games and animation. For this purpose image is required to be displayed. The java.awt.Graphics class provide a method drawImage() to display the image.
|
Can you give me Syntax of drawImage() method?
|
public abstract boolean drawImage(Image img, int x, int y, ImageObserver observer): is used draw the specified image.
|
How to get the object of Image?
|
The java.applet.Applet class provides getImage() method that returns the object of Image. Syntax:
public Image getImage(URL u, String image){}
|
Can you give me Other required methods of Applet class to display image?
|
1.public URL getDocumentBase(): is used to return the URL of the document in which applet is embedded.
2.public URL getCodeBase(): is used to return the base URL.
|
Can you provide an Example of displaying image in applet?
|
import java.awt.*;
import java.applet.*;
public class DisplayImage extends Applet {
Image picture;
public void init() {
picture = getImage(getDocumentBase(),"sonoo.jpg");
}
public void paint(Graphics g) {
g.drawImage(picture, 30,30, this);
}
}
In the above example, drawImage() method of Graphics class is used to display the image. The 4th argument of drawImage() method of is ImageObserver object. The Component class implements ImageObserver interface. So current class object would also be treated as ImageObserver because Applet class indirectly extends the Component class.
myapplet.html
<html>
<body>
<applet code="DisplayImage.class" width="300" height="300">
</applet>
</body>
</html>
|
What is Animation in Applet?
|
Applet is mostly used in games and animation. For this purpose image is required to be moved.
|
Can you provide an Example of animation in applet?
|
import java.awt.*;
import java.applet.*;
public class AnimationExample extends Applet {
Image picture;
public void init() {
picture =getImage(getDocumentBase(),"bike_1.gif");
}
public void paint(Graphics g) {
for(int i=0;i<500;i++){
g.drawImage(picture, i,30, this);
try{Thread.sleep(100);}catch(Exception e){}
}
}
}
In the above example, drawImage() method of Graphics class is used to display the image. The 4th argument of drawImage() method of is ImageObserver object. The Component class implements ImageObserver interface. So current class object would also be treated as ImageObserver because Applet class indirectly extends the Component class.
myapplet.html
<html>
<body>
<applet code="DisplayImage.class" width="300" height="300">
</applet>
</body>
</html>
|
What is EventHandling in Applet?
|
As we perform event handling in AWT or Swing, we can perform it in applet also. Let's see the simple example of event handling in applet that prints a message by click on the button.
|
Can you provide an Example of EventHandling in applet?
|
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class EventApplet extends Applet implements ActionListener{
Button b;
TextField tf;
public void init(){
tf=new TextField();
tf.setBounds(30,40,150,20);
b=new Button("Click");
b.setBounds(80,150,60,50);
add(b);add(tf);
b.addActionListener(this);
setLayout(null);
}
public void actionPerformed(ActionEvent e){
tf.setText("Welcome");
}
}
In the above example, we have created all the controls in init() method because it is invoked only once.
myapplet.html
<html>
<body>
<applet code="EventApplet.class" width="300" height="300">
</applet>
</body>
</html>
|
What is JApplet class in Applet?
|
As we prefer Swing to AWT. Now we can use JApplet that can have all the controls of swing. The JApplet class extends the Applet class.
|
Example of EventHandling in JApplet
|
import java.applet.*;
import javax.swing.*;
import java.awt.event.*;
public class EventJApplet extends JApplet implements ActionListener{
JButton b;
JTextField tf;
public void init(){
tf=new JTextField();
tf.setBounds(30,40,150,20);
b=new JButton("Click");
b.setBounds(80,150,70,40);
add(b);add(tf);
b.addActionListener(this);
setLayout(null);
}
public void actionPerformed(ActionEvent e){
tf.setText("Welcome");
}
}
In the above example, we have created all the controls in init() method because it is invoked only once.
myapplet.html
<html>
<body>
<applet code="EventJApplet.class" width="300" height="300">
</applet>
</body>
</html>
|
Painting in Applet
|
We can perform painting operation in applet by the mouseDragged() method of MouseMotionListener.
|
Can you provide an Example of Painting in Applet?
|
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class MouseDrag extends Applet implements MouseMotionListener{
public void init(){
addMouseMotionListener(this);
setBackground(Color.red);
}
public void mouseDragged(MouseEvent me){
Graphics g=getGraphics();
g.setColor(Color.white);
g.fillOval(me.getX(),me.getY(),5,5);
}
public void mouseMoved(MouseEvent me){}
}
In the above example, getX() and getY() method of MouseEvent is used to get the current x-axis and y-axis. The getGraphics() method of Component class returns the object of Graphics.
myapplet.html
<html>
<body>
<applet code="MouseDrag.class" width="300" height="300">
</applet>
</body>
</html>
|
What is Digital clock in Applet?
|
Digital clock can be created by using the Calendar and SimpleDateFormat class. Let's see the simple example:
|
Can you provide an Example of Digital clock in Applet?
|
import java.applet.*;
import java.awt.*;
import java.util.*;
import java.text.*;
public class DigitalClock extends Applet implements Runnable {
Thread t = null;
int hours=0, minutes=0, seconds=0;
String timeString = "";
public void init() {
setBackground( Color.green);
}
public void start() {
t = new Thread( this );
t.start();
}
public void run() {
try {
while (true) {
Calendar cal = Calendar.getInstance();
hours = cal.get( Calendar.HOUR_OF_DAY );
if ( hours > 12 ) hours -= 12;
minutes = cal.get( Calendar.MINUTE );
seconds = cal.get( Calendar.SECOND );
SimpleDateFormat formatter = new SimpleDateFormat("hh:mm:ss");
Date date = cal.getTime();
timeString = formatter.format( date );
repaint();
t.sleep( 1000 ); // interval given in milliseconds
}
}
catch (Exception e) { }
}
public void paint( Graphics g ) {
g.setColor( Color.blue );
g.drawString( timeString, 50, 50 );
}
}
In the above example, getX() and getY() method of MouseEvent is used to get the current x-axis and y-axis. The getGraphics() method of Component class returns the object of Graphics.
myapplet.html
<html>
<body>
<applet code="DigitalClock.class" width="300" height="300">
</applet>
</body>
</html>
|
What is Analog clock in Applet?
|
Analog clock can be created by using the Math class. Let's see the simple example:
|
Can you provide an Example of Analog clock in Applet?
|
import java.applet.*;
import java.awt.*;
import java.util.*;
import java.text.*;
public class MyClock extends Applet implements Runnable {
int width, height;
Thread t = null;
boolean threadSuspended;
int hours=0, minutes=0, seconds=0;
String timeString = "";
public void init() {
width = getSize().width;
height = getSize().height;
setBackground( Color.black );
}
public void start() {
if ( t == null ) {
t = new Thread( this );
t.setPriority( Thread.MIN_PRIORITY );
threadSuspended = false;
t.start();
}
else {
if ( threadSuspended ) {
threadSuspended = false;
synchronized( this ) {
notify();
}
}
}
}
public void stop() {
threadSuspended = true;
}
public void run() {
try {
while (true) {
Calendar cal = Calendar.getInstance();
hours = cal.get( Calendar.HOUR_OF_DAY );
if ( hours > 12 ) hours -= 12;
minutes = cal.get( Calendar.MINUTE );
seconds = cal.get( Calendar.SECOND );
SimpleDateFormat formatter
= new SimpleDateFormat( "hh:mm:ss", Locale.getDefault() );
Date date = cal.getTime();
timeString = formatter.format( date );
// Now the thread checks to see if it should suspend itself
if ( threadSuspended ) {
synchronized( this ) {
while ( threadSuspended ) {
wait();
}
}
}
repaint();
t.sleep( 1000 ); // interval specified in milliseconds
}
}
catch (Exception e) { }
}
void drawHand( double angle, int radius, Graphics g ) {
angle -= 0.5 * Math.PI;
int x = (int)( radius*Math.cos(angle) );
int y = (int)( radius*Math.sin(angle) );
g.drawLine( width/2, height/2, width/2 + x, height/2 + y );
}
void drawWedge( double angle, int radius, Graphics g ) {
angle -= 0.5 * Math.PI;
int x = (int)( radius*Math.cos(angle) );
int y = (int)( radius*Math.sin(angle) );
angle += 2*Math.PI/3;
int x2 = (int)( 5*Math.cos(angle) );
int y2 = (int)( 5*Math.sin(angle) );
angle += 2*Math.PI/3;
int x3 = (int)( 5*Math.cos(angle) );
int y3 = (int)( 5*Math.sin(angle) );
g.drawLine( width/2+x2, height/2+y2, width/2 + x, height/2 + y );
g.drawLine( width/2+x3, height/2+y3, width/2 + x, height/2 + y );
g.drawLine( width/2+x2, height/2+y2, width/2 + x3, height/2 + y3 );
}
public void paint( Graphics g ) {
g.setColor( Color.gray );
drawWedge( 2*Math.PI * hours / 12, width/5, g );
drawWedge( 2*Math.PI * minutes / 60, width/3, g );
drawHand( 2*Math.PI * seconds / 60, width/2, g );
g.setColor( Color.white );
g.drawString( timeString, 10, height-10 );
}
}
myapplet.html
<html>
<body>
<applet code="MyClock.class" width="300" height="300">
</applet>
</body>
</html>
|
What is Parameter in Applet?
|
We can get any information from the HTML file as a parameter. For this purpose, Applet class provides a method named getParameter(). Syntax:
public String getParameter(String parameterName)
|
Can you provide an Example of using parameter in Applet?
|
import java.applet.Applet;
import java.awt.Graphics;
public class UseParam extends Applet{
public void paint(Graphics g){
String str=getParameter("msg");
g.drawString(str,50, 50);
}
}
myapplet.html
<html>
<body>
<applet code="UseParam.class" width="300" height="300">
<param name="msg" value="Welcome to applet">
</applet>
</body>
</html>
|
What is Applet Communication?
|
java.applet.AppletContext class provides the facility of communication between applets. We provide the name of applet through the HTML file. It provides getApplet() method that returns the object of Applet. Syntax:
public Applet getApplet(String name){}
|
Can you provide an Example of Applet Communication?
|
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class ContextApplet extends Applet implements ActionListener{
Button b;
public void init(){
b=new Button("Click");
b.setBounds(50,50,60,50);
add(b);
b.addActionListener(this);
}
public void actionPerformed(ActionEvent e){
AppletContext ctx=getAppletContext();
Applet a=ctx.getApplet("app2");
a.setBackground(Color.yellow);
}
}
myapplet.html
<html>
<body>
<applet code="ContextApplet.class" width="150" height="150" name="app1">
</applet>
<applet code="First.class" width="150" height="150" name="app2">
</applet>
</body>
</html>
|
What is Java Reflection API?
|
Java Reflection is a process of examining or modifying the run time behavior of a class at run time.
The java.lang.Class class provides many methods that can be used to get metadata, examine and change the run time behavior of a class.
The java.lang and java.lang.reflect packages provide classes for java reflection.
|
What is java.lang.Class class?
|
The java.lang.Class class performs mainly two tasks:
provides methods to get the metadata of a class at run time.
provides methods to examine and change the run time behavior of a class.
|
Can you give me Commonly used methods of Class class?
|
Commonly used methods of Class class:
Method: public String getName()
Description: returns the class name
Method: public static Class forName(String className)throws ClassNotFoundException
Description: loads the class and returns the reference of Class class.
Method: public Object newInstance()throws InstantiationException,IllegalAccessException
Description: creates new instance.
Method: public boolean isInterface()
Description: checks if it is interface.
Method: public boolean isArray()
Description: checks if it is array.
Method: public boolean isPrimitive()
Description: checks if it is primitive.
Method: public Class getSuperclass()
Description: returns the superclass class reference.
Method: public Field[] getDeclaredFields()throws SecurityException
Description: returns the total number of fields of this class.
Method: public Method[] getDeclaredMethods()throws SecurityException
Description: returns the total number of methods of this class.
Method: public Constructor[] getDeclaredConstructors()throws SecurityException
Description: returns the total number of constructors of this class.
Method: public Method getDeclaredMethod(String name,Class[] parameterTypes)throws NoSuchMethodException,SecurityException
Description: returns the method class instance.
|
How to get the object of Class class?
|
There are 3 ways to get the instance of Class class. They are as follows:
-forName() method of Class class
-getClass() method of Object class
-the .class syntax
|
What is Determining the class object?
|
The following methods of Class class are used to determine the class object:
1) public boolean isInterface(): determines if the specified Class object represents an interface type.
2) public boolean isArray(): determines if this Class object represents an array class.
3) public boolean isPrimitive(): determines if the specified Class object represents a primitive type.
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.