Monday 17 July 2017

Thread in Java - core java notes ~ foundjava

TO SEE THE NOTES CLICK DOWNLOAD HERE LINK

NOTES DEKHNE KE LIYE DOWNLOD HERE LINK PAR CLICK KARE


DOWNLOAD HERE

Read More »

Synchronization in Java - core java notes ~ foundjava

TO SEE THE NOTES CLICK DOWNLOAD HERE LINK

NOTES DEKHNE KE LIYE DOWNLOD HERE LINK PAR CLICK KARE


DOWNLOAD HERE

Read More »

MySQL Database and Java Desktop GUI Part 1 - core java notes ~ foundjava

TO SEE THE NOTES CLICK DOWNLOAD HERE LINK

NOTES DEKHNE KE LIYE DOWNLOD HERE LINK PAR CLICK KARE


DOWNLOAD HERE

Read More »

Java StringBuffer class - core java notes ~ foundjava

TO SEE THE NOTES CLICK DOWNLOAD HERE LINK

NOTES DEKHNE KE LIYE DOWNLOD HERE LINK PAR CLICK KARE


DOWNLOAD HERE

Read More »

Java String - core java notes ~ foundjava

TO SEE THE NOTES CLICK DOWNLOAD HERE LINK

NOTES DEKHNE KE LIYE DOWNLOD HERE LINK PAR CLICK KARE


DOWNLOAD HERE

Read More »

Sunday 16 July 2017

Java nio Tutorial with Examples - core java notes ~ foundjava

TO SEE THE NOTES CLICK DOWNLOAD HERE LINK

NOTES DEKHNE KE LIYE DOWNLOD HERE LINK PAR CLICK KARE


DOWNLOAD HERE

Read More »

Java Command Line Arguments - core java notes ~ foundjava

TO SEE THE NOTES CLICK DOWNLOAD HERE LINK

NOTES DEKHNE KE LIYE DOWNLOD HERE LINK PAR CLICK KARE


DOWNLOAD HERE

Read More »

Java Collection Framework - core java notes ~ foundjava

TO SEE THE NOTES CLICK DOWNLOAD HERE LINK

NOTES DEKHNE KE LIYE DOWNLOD HERE LINK PAR CLICK KARE


DOWNLOAD HERE

Read More »

Input and Output in Java - core java notes ~ foundjava

TO SEE THE NOTES CLICK DOWNLOAD HERE LINK

NOTES DEKHNE KE LIYE DOWNLOD HERE LINK PAR CLICK KARE


DOWNLOAD HERE

Read More »

Final Keyword In Java - core java notes ~ foundjava

TO SEE THE NOTES CLICK DOWNLOAD HERE LINK

NOTES DEKHNE KE LIYE DOWNLOD HERE LINK PAR CLICK KARE


DOWNLOAD HERE

Read More »

Saturday 15 July 2017

Pointers as Value parameters code in java ~ java help

import java.awt.Rectangle;

public class ObjectVarsAsParameters
{ public static void main(String[] args)
 { go();
 }
 
 public static void go()
 { Rectangle r1 = new Rectangle(0,0,5,5);
  System.out.println("In method go. r1 " + r1 + "\n");
  // could have been 
  //System.out.prinltn("r1" + r1.toString());
  r1.setSize(10, 15);
  System.out.println("In method go. r1 " + r1 + "\n");
  alterPointee(r1);
  System.out.println("In method go. r1 " + r1 + "\n");
  
  alterPointer(r1);
  System.out.println("In method go. r1 " + r1 + "\n");
 }
 
 public static void alterPointee(Rectangle r)
 { System.out.println("In method alterPointee. r " + r + "\n");
  r.setSize(20, 30);
  System.out.println("In method alterPointee. r " + r + "\n");
 }
 
 public static void alterPointer(Rectangle r)
 { System.out.println("In method alterPointer. r " + r + "\n");
  r = new Rectangle(5, 10, 30, 35);
  System.out.println("In method alterPointer. r " + r + "\n");
 }
 
 
}
Read More »

Friday 14 July 2017

ScrollPaneLayout in java ~ java help

The layout manager used by JScrollPane. JScrollPaneLayout is responsible for nine components: a viewport, two scrollbars, a row header, a column header, and four "corner" components.

Nested Class

Modifier and TypeClassDescription
static classScrollPaneLayout.UIResourceIt is UI resource version of ScrollPaneLayout.

Field

Modifier and TypeFieldDescription
protected JViewportcolHeadIt is column header child.
protected JScrollBarhsbIt is scrollpane's horizontal scrollbar child.
protected inthsbPolicyIt displays policy for the horizontal scrollbar.
protected ComponentlowerLeftThis displays the lower left corner.
protected ComponentlowerRightThis displays in the lower right corner.
protected JViewportrowHeadIt is row header child.
protected ComponentupperLeftThis component displays in the upper left corner.
protected ComponentupperRightThis component displays in the upper right corner.
protected JViewportviewportIt is scrollpane's viewport child.
protected JScrollBarvsbIt is scrollpane's vertical scrollbar child.
protected intvsbPolicyIt is the display policy for the vertical scrollbar.

Useful methods

Modifier and TypeMethodDescription
voidaddLayoutComponent(String s, Component c)It adds the specified component to the layout.
protected ComponentaddSingletonComponent(Component oldC, Component newC)It removes an existing component.
JViewportgetColumnHeader()It returns the JViewport object that is the column header.
ComponentgetCorner(String key)It returns the Component at the specified corner.
JScrollBargetHorizontalScrollBar()It returns the JScrollBar object that handles horizontal scrolling.
intgetHorizontalScrollBarPolicy()It returns the horizontal scrollbar-display policy.
JViewportgetRowHeader()It returns the JViewport object that is the row header.
JScrollBargetVerticalScrollBar()It returns the JScrollBar object that handles vertical scrolling.
intgetVerticalScrollBarPolicy()It returns the vertical scrollbar-display policy.
JViewportgetViewport()It returns the JViewport object that displays the scrollable contents.

Example:

  1. import javax.swing.ImageIcon;  
  2. import javax.swing.JFrame;  
  3. import javax.swing.JLabel;  
  4. import javax.swing.JScrollPane;  
  5. public class ScrollPaneDemo extends JFrame  
  6. {  
  7. public ScrollPaneDemo() {  
  8. super("ScrollPane Demo");  
  9. ImageIcon img = new ImageIcon("child.png");  
  10.   
  11. JScrollPane png = new JScrollPane(new JLabel(img));  
  12.   
  13. getContentPane().add(png);  
  14. setSize(300,250);  
  15. setVisible(true);  
  16. }  
  17.   
  18. public static void main(String[] args) {  
  19. new ScrollPaneDemo();  
  20. }  
  21. }  
Output:
Java Scrollpanellayout 1

Read More »

SpringLayout in java ~ java help

Java SpringLayout

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 constrains are 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 new edge than the previous binding is discarded. SpringLayout doesn't automatically set the location of the components it manages.

Nested Classes

Modifier and TypeClassDescription
static classSpringLayout.ConstraintsIt is a Constraints object helps to govern component's size and position change in a container that is controlled by SpringLayout

Fields

Modifier and TypeFieldDescription
static StringBASELINEIt specifies the baseline of a component.
static StringEASTIt specifies the right edge of a component's bounding rectangle.
static StringHEIGHTIt specifies the height of a component's bounding rectangle.
static StringHORIZONTAL_CENTERIt specifies the horizontal center of a component's bounding rectangle.
static StringNORTHIt specifies the top edge of a component's bounding rectangle.
static StringSOUTHIt specifies the bottom edge of a component's bounding rectangle.
static StringVERTICAL_CENTERIt specifies the vertical center of a component's bounding rectangle.
static StringWESTIt specifies the left edge of a component's bounding rectangle.
static StringWIDTHIt specifies the width of a component's bounding rectangle.

Useful Methods

Modifier and TypeMethodDescription
voidaddLayoutComponent(Component component, Object constraints)If constraints is an instance of SpringLayout. Constraints, associates the constraints with the specified component.
voidaddLayoutComponent(String name, Component c)Has no effect, since this layout manager does not use a per-component string.
SpringgetConstraint(String edgeName, Component c)It returns the spring controlling the distance between the specified edge of the component and the top or left edge of its parent.
SpringLayout.ConstraintsgetConstraints(Component c)It returns the constraints for the specified component.
floatgetLayoutAlignmentX(Container p)It returns 0.5f (centered).
floatgetLayoutAlignmentY(Container p)It returns 0.5f (centered).
voidinvalidateLayout(Container p)It Invalidates the layout, indicating that if the layout manager has cached information it should be discarded.
voidlayoutContainer(Container parent)It lays out the specified container.
DimensionmaximumLayoutSize(Container parent)It is used to calculates the maximum size dimensions for the specified container, given the components it contains.
DimensionminimumLayoutSize(Container parent)It is used to calculates the minimum size dimensions for the specified container, given the components it contains.
DimensionpreferredLayoutSize(Container parent)It is used to calculates the preferred size dimensions for the specified container, given the components it contains.

Example

  1. import java.awt.Container;  
  2. import javax.swing.JFrame;  
  3. import javax.swing.JLabel;  
  4. import javax.swing.JTextField;  
  5. import javax.swing.SpringLayout;  
  6. public class MySpringDemo {  
  7.      private static void createAndShowGUI() {  
  8.             JFrame frame = new JFrame("MySpringDemp");  
  9.             frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);  
  10.   
  11.             Container contentPane = frame.getContentPane();  
  12.             SpringLayout layout = new SpringLayout();  
  13.             contentPane.setLayout(layout);  
  14.   
  15.             JLabel label = new JLabel("Label: ");  
  16.             JTextField textField = new JTextField("My Text Field"15);  
  17.             contentPane.add(label);  
  18.             contentPane.add(textField);  
  19.        
  20.             layout.putConstraint(SpringLayout.WEST, label,6,SpringLayout.WEST, contentPane);  
  21.             layout.putConstraint(SpringLayout.NORTH, label,6,SpringLayout.NORTH, contentPane);  
  22.             layout.putConstraint(SpringLayout.WEST, textField,6,SpringLayout.EAST, label);  
  23.             layout.putConstraint(SpringLayout.NORTH, textField,6,SpringLayout.NORTH, contentPane);  
  24.             layout.putConstraint(SpringLayout.EAST, contentPane,6,SpringLayout.EAST, textField);  
  25.             layout.putConstraint(SpringLayout.SOUTH, contentPane,6,SpringLayout.SOUTH, textField);  
  26.   
  27.             frame.pack();  
  28.             frame.setVisible(true);  
  29.         }  
  30.         public static void main(String[] args) {  
  31.             javax.swing.SwingUtilities.invokeLater(new Runnable() {  
  32.                 public void run() {  
  33.                     createAndShowGUI();  
  34.                 }  
  35.             });  
  36.         }  
  37.     }  
Output:
Java Springlayout 1

Read More »

GroupLayout in java ~ java help

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 where as 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 exists in both a horizontal and vertical group, otherwise an IllegalStateException is thrown during layout, or when the minimum, preferred or maximum size is requested.

Nested Classes

Modifier and TypeClassDescription
static classGroupLayout.AlignmentEnumeration of the possible ways ParallelGroup can align its children.
classGroupLayout.GroupGroup provides the basis for the two types of operations supported by GroupLayout: laying out components one after another (SequentialGroup) or aligned (ParallelGroup).
classGroupLayout.ParallelGroupIt is a Group that aligns and sizes it's children.
classGroupLayout.SequentialGroupIt is a Group that positions and sizes its elements sequentially, one after another.

Fields

Modifier and TypeFieldDescription
static intDEFAULT_SIZEIt indicates the size from the component or gap should be used for a particular range value.
static intPREFERRED_SIZEIt indicates the preferred size from the component or gap should be used for a particular range value.

Constructors

GroupLayout(Container host)It creates a GroupLayout for the specified Container.

Useful Methods

Modifier and TypeFieldDescription
voidaddLayoutComponent(Component component, Object constraints)It notify that a Component has been added to the parent container.
voidaddLayoutComponent(String name, Component component)It notify that a Component has been added to the parent container.
GroupLayout.ParallelGroupcreateBaselineGroup(boolean resizable, boolean anchorBaselineToTop)It creates and returns a ParallelGroup that aligns it's elements along the baseline.
GroupLayout.ParallelGroupcreateParallelGroup()It creates and returns a ParallelGroup with an alignment of Alignment.LEADING
GroupLayout.ParallelGroupcreateParallelGroup(GroupLayout.Alignment alignment)It creates and returns a ParallelGroup with the specified alignment.
GroupLayout.ParallelGroupcreateParallelGroup(GroupLayout.Alignment alignment, boolean resizable)It creates and returns a ParallelGroup with the specified alignment and resize behavior.
GroupLayout.SequentialGroupcreateSequentialGroup()It creates and returns a SequentialGroup.
booleangetAutoCreateContainerGaps()It returns true if gaps between the container and components that border the container are automatically created.
booleangetAutoCreateGaps()It returns true if gaps between components are automatically created.
booleangetHonorsVisibility()It returns whether component visiblity is considered when sizing and positioning components.
floatgetLayoutAlignmentX(Container parent)It returns the alignment along the x axis.
floatgetLayoutAlignmentY(Container parent)It returns the alignment along the y axis.
DimensionmaximumLayoutSize(Container parent)It returns the maximum size for the specified container.

Example

  1. public class GroupExample {  
  2.     public static void main(String[] args) {  
  3.         JFrame frame = new JFrame("GroupLayoutExample");  
  4.         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);  
  5.         Container contentPanel = frame.getContentPane();  
  6.         GroupLayout groupLayout = new GroupLayout(contentPanel);  
  7.   
  8.         contentPanel.setLayout(groupLayout);  
  9.   
  10.         JLabel clickMe = new JLabel("Click Here");  
  11.         JButton button = new JButton("This Button");  
  12.   
  13.         groupLayout.setHorizontalGroup(  
  14.                     groupLayout.createSequentialGroup()  
  15.                                 .addComponent(clickMe)  
  16.                                 .addGap(1020100)  
  17.                                 .addComponent(button));  
  18.         groupLayout.setVerticalGroup(  
  19.                      groupLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)  
  20.                                 .addComponent(clickMe)  
  21.                                 .addComponent(button));  
  22.         frame.pack();  
  23.         frame.setVisible(true);  
  24.     }  
  25. }  
Output:
Java Grouplayout 1

Example 2

  1. import java.awt.Container;  
  2. import javax.swing.GroupLayout;  
  3. import javax.swing.JButton;  
  4. import javax.swing.JFrame;  
  5. import static javax.swing.GroupLayout.Alignment.*;  
  6. public class GroupExample2 {  
  7.     public static void main(String[] args) {  
  8.         JFrame frame = new JFrame("GroupLayoutExample");  
  9.         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);  
  10.         Container myPanel = frame.getContentPane();  
  11.   
  12.         GroupLayout groupLayout = new GroupLayout(myPanel);  
  13.         groupLayout.setAutoCreateGaps(true);  
  14.         groupLayout.setAutoCreateContainerGaps(true);  
  15.         myPanel.setLayout(groupLayout);  
  16.   
  17.         JButton b1 = new JButton("Button One");  
  18.         JButton b2 = new JButton("Button Two");  
  19.         JButton b3 = new JButton("Button Three");  
  20.   
  21.         groupLayout.setHorizontalGroup(groupLayout.createSequentialGroup()  
  22.                 .addGroup(groupLayout.createParallelGroup(LEADING).addComponent(b1).addComponent(b3))  
  23.                 .addGroup(groupLayout.createParallelGroup(TRAILING).addComponent(b2)));  
  24.   
  25.         groupLayout.setVerticalGroup(groupLayout.createSequentialGroup()  
  26.                 .addGroup(groupLayout.createParallelGroup(BASELINE).addComponent(b1).addComponent(b2))  
  27.                 .addGroup(groupLayout.createParallelGroup(BASELINE).addComponent(b3)));  
  28.   
  29.         frame.pack();  
  30.         frame.setVisible(true);  
  31.     }  
  32. }  
Output:
Java Grouplayout 2
Read More »