Showing posts with label Swing Hacks. Show all posts
Showing posts with label Swing Hacks. Show all posts

Spring Framework Draw Table on Swing Tooltip

Let us draw a table on Swing tooltip. The coding is very easy all you need to do is to just go through this easy and small program.

What's here?

In this post, i will be drawing a table of 3 columns and 5 rows on a Swing tooltip along with a <h2> heading with a white background. When it comes to the program, a short logic is written to draw the table on swing tooltip. While this logic is not needed, it is written instead for the sake of brevity. We will be using no classes outside the Swing and will be using no event handling in the program.

Shall we draw? Yes!


import javax.swing.*;

import java.awt.*;

class TableTooltip extends JFrame

{

private JButton b;



public TableTooltip()

{

createAndShowGUI();

}



private void createAndShowGUI()

{

setTitle("Table on a Tooltip");

setLayout(new FlowLayout());

setDefaultCloseOperation(EXIT_ON_CLOSE);

setSize(400,400);

setVisible(true);



b=new JButton("Button");

add(b);



String text="<html><body bgcolor=white><h2 align=center>This is a Table</h2><br/><table border=1>";

for(int i=0;i<5;i++)

{

text+="<tr>";

for(int j=0;j<3;j++)

{

text+="<td>[Row "+i+", Column "+j+"]</td>";

}

text+="</tr>";

}



text+="</table></body></html>";



b.setToolTipText(text);

}



public static void main(String args[])

{

new TableTooltip();

}



}

Output of the TableTooltip program

How to draw table on Swing Tooltip
Drawing table on Swing tooltip

Explaining the table drawing

Here i have used HTML with Swing in order to draw the table on the tooltip. HTML contains a tag called the <table> which is used to draw a table and border attribute sets the border thickness which is 1 here.

<body> tag represents the body of the page.
bgcolor is an attribute which points to the background of body. white is the value for the bgcolor attribute.
<h2> tag represents the second heading which is smaller than the 1st and bigger than 3,4,5 and 6.
align is an attribute which defines the alignment of the text. center is the value for the attribute align.
<tr> represents a table row and <td> represents a table data. A <tr> usually contains <td>.

for(int i=0;i<5;i++) Loop till 5 times starting from 0 as i value. This outer loop is written for table row.

text+="<tr>"; This creates a new table row each time the outer loop executes.

for(int j=0;j<3;j++) Loop till 3 times starting from 0 as j value. This inner loop is written for table data (a table cell).

text+="<td>[Row "+i+", Column "+j+"]</td>"; Open the <td> tag and write into the cell. The row and column number.

text+="</tr>"; Close the table row once after the inner loop has finished.

b.setToolTipText(text); Put the tool tip text for the JButton.

Spring Hibernate Setting Background Image in JFrame - Swing

Here is sample tutorial, a simple trick that enables you to set background image for JFrame.



import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class BackgroundImageJFrame extends JFrame
{
JButton b1;
JLabel l1;
public BackgroundImageJFrame()
{
setTitle("Background Color for JFrame");
setSize(400,400);
setLocationRelativeTo(null);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);
/*
One way
-----------------
setLayout(new BorderLayout());
JLabel background=new JLabel(new ImageIcon("C:\\Users\\Computer\\Downloads\\colorful design.png"));
add(background);
background.setLayout(new FlowLayout());
l1=new JLabel("Here is a button");
b1=new JButton("I am a button");
background.add(l1);
background.add(b1);
*/
// Another way
setLayout(new BorderLayout());
setContentPane(new JLabel(new ImageIcon("C:\\Users\\Computer\\Downloads\\colorful design.png")));
setLayout(new FlowLayout());
l1=new JLabel("Here is a button");
b1=new JButton("I am a button");
add(l1);
add(b1);
// Just for refresh :) Not optional!
setSize(399,399);
setSize(400,400);
}
public static void main(String args[])
{
new BackgroundImageJFrame();
}
}
 Notes: 

The first way: Here i have taken a JLabel named background and an image icon to it and then set the layout of the frame as BorderLayout so that it appears whole window.And then, i have added the label background to the frame. Next, some components are added to the label background instead of the frame and the layout for the background label is set as FlowLayout so that the components come side by side from the starting of the frame.

The second way: Here i used the setContentPane(Container c) method, which means to set the container (the one that contains the components) to the frame. As JLabel being one of the sub-classes of the Container, i have used it, added an image icon to it. You could also note, the BorderLayout which is set in order to make the image spread on the whole frame Next, as usual i have changed the layout for the frame and then added components to it.

The Refresh: This is essential because, the background image will not visible when the frame is opened. So, we will need to refresh it. So, i have called the setSize(int w,int h) twice which resizes (i.e. refreshes) the frame so that the background image will be visible.

Spring Hibernate Using JButton - Minimize/Maximize/Close JFrame

You can use a JButton to perform the actions on the JFrame. This is also a tutorial for JButton with ActionListener.

Use JButton to Maximize/Minimize/Close JFrame


import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
class JButtonWindowActions extends JFrame
{
JButton button1,button2,button3;
public JButtonWindowActions()
{
setTitle("JButtonWindowActions Demo");
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setLayout(new FlowLayout());
setOpacity(0.7f);
button1=new JButton("Maximize/Restore");
button1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae)
{
if(getExtendedState()==NORMAL)
setExtendedState(MAXIMIZED_BOTH);
else
setExtendedState(NORMAL);
}
});
button2=new JButton("Minimize");
button2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae)
{
setState(ICONIFIED);
}
});
button3=new JButton("Close");
button3.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae)
{
dispose();
}
});
// add buttons to frame
add(button1);
add(button2);
add(button3);
// pack the frame
pack();
}
public static void main(String args[])
{
new JButtonWindowActions();
}
}
setOpacity(0.7f): To just set the Opacity of the frame. It is optional.
NORMAL: Set the frame to the normal state i.e. it's original state.
MAXIMIZED_BOTH: Make the frame maximized i.e. spread it to the full screen.
ICONIFIED: Make the frame be at the task bar.
dispose(): Dispose the frame.

Spring Hibernate Animating JFrame with Random Colors

Animating a JFrame, make it randomly colored!


Previously we've seen, animating a JFrame with a fixed background and moving on the screen. Now let's change the background of the color and that too randomly! The same concept comes, here but just a very few lines of code will be added. In this example too, i've used Threading as said earlier you can also use javax.swing.Timer class to achieve this! The following example may not be useful, but it's just art. it's just fun. it's just Swing!



Go Color it Random!


import javax.swing.*;
import java.awt.geom.*;
import java.awt.*;
import java.util.*;
class AnimatedColoredJFrame extends JFrame implements Runnable
{
Thread t;
Random r;
public AnimatedColoredJFrame()
{
// Set frame properties
setTitle("Animated JFrame");
setSize(500,500);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setUndecorated(true);

// Set some shape, i want a circle
setShape(new Ellipse2D.Double(0,0,500,500));

// Set background for the frame's content pane
getContentPane().setBackground(Color.white);

// Set opacity, don't make it opaque, that's my wish!
setOpacity(0.5f);

setVisible(true);

// Create java.util.Random object
r=new Random();

// Create a new thread, run() is written in this class (Runnable implemented)
t=new Thread(this);

// Start the thread
t.start();

}

public void run()
       {
try
{
// Get the width of the screen, so that the frame has to go till end!
int width=Toolkit.getDefaultToolkit().getScreenSize().width;

// Start the loop
for(int i=0;i<=width;i++)
{

// If i value equals width (i.e. reaches end of screen), start from starting of the screen (i.e. i=0) so looped forever
if(i==width) i=0;

// Set location, x-coordinate changes but y-coordinate is constant
setLocation(i,55);

// Set background randomly each time!
getContentPane().setBackground(new Color(r.nextInt(255),r.nextInt(255),r.nextInt(255)));

// Get the effect!
Thread.sleep(1);

}
}catch(Exception e){}

}

public static void main(String args[])
{
new AnimatedColoredJFrame();
}

}

Also see other swing hacks

The moving random colored transparent circular JFrame in action!



Spring Hibernate Create a moving JFrame in Swing

How to move a JFrame?


Now, let's create a JFrame that moves along the screen acting like a screensaver. All we need to do is to make a moving effect, for this we can either use the javax.swing.Timer class or Threading concept . However we use threading here. Just look at it!


Get ready to move!


import javax.swing.*;
import java.awt.geom.*;
import java.awt.*;
class AnimatedJFrame extends JFrame implements Runnable
{
Thread t;
public AnimatedJFrame()
{

// Set frame properties
setTitle("Animated JFrame");
setSize(500,500);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setUndecorated(true);

// Set some shape, i want a circle
setShape(new Ellipse2D.Double(0,0,500,500));

// Set background for the frame's content pane
getContentPane().setBackground(Color.white);

// Set opacity, don't make it opaque, that's my wish!
setOpacity(0.5f);

setVisible(true);

// Create a new thread, run() is written in this class (Runnable implemented)
t=new Thread(this);

// Start the thread
t.start();
}

public void run()
{
try
{

// Get the width of the screen, so that the frame has to go till end!
int width=Toolkit.getDefaultToolkit().getScreenSize().width;

// Start the loop
for(int i=0;i<=width;i++)
{

// If i value equals width (i.e. reaches end of screen), start from starting of the screen (i.e. i=0) so looped forever
if(i==width) i=0;

// Set location, x-coordinate changes but y-coordinate is constant
setLocation(i,55);

// Get the effect!
Thread.sleep(1);

}

}catch(Exception e){}

}

public static void main(String args[])
{
new AnimatedJFrame();
}

}

Everything explained there, just go through other swing hacks.

Watch it! The example in real!


Spring Hibernate Create Shaped Transparent JFrames in Java Swing

Here is a sample tutorial making fun with JFrame, giving it all the shapes that you can to a frame. Make a frame look circular, ellipse, curve, rounded rectanble, some other different shape that cannot be defined and may not be seen. Here i will show how you can customize your JFrame as you wish.

Circular Shape

Cubic Curve Shape

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
class ShapedJFrame extends JFrame
{
JButton b1;
public ShapedJFrame()
{
setTitle("Transparent JFrame Demo");
setLayout(new GridBagLayout());
setDefaultCloseOperation(EXIT_ON_CLOSE);
setUndecorated(true);
setVisible(true);
setOpacity(0.4f);

// Try different shapes

// Normal rounded rectangle
//setShape(new RoundRectangle2D.Double(0,0,getWidth(),getHeight(),20,40));

//Ellipse shape
//setShape(new Ellipse2D.Double(0,0,400,400));

// Quad Curve
//setShape(new QuadCurve2D.Double(0,0,400,50,400,400));

// Cubic Curve. Looks funny:)
//setShape(new CubicCurve2D.Double(0,0,500,5,200,0,500,500));

// For three-fourth circle
//setShape(new Arc2D.Double(new Rectangle2D.Double(0,0,500,500),90,270,Arc2D.PIE));

// For round circle shape
setShape(new Arc2D.Double(new Rectangle2D.Double(0,0,500,500),90,360,Arc2D.PIE));

b1=new JButton("I am a button!");
add(b1);

setSize(500,500);
setLocationRelativeTo(null);
}
public static void main(String args[])
{
new ShapedJFrame();
}
}
Round Rectangle:  Mostly found. A Rectangle with rounded corners. Double is a static class in the RoundRectangle2D class located in the java.awt.geom package.
new RoundRectangle2D.Double(double x, double y, double width, double height,double cornerwidth,double cornerheight)
QuadCurve.Double(double x1,double y1,double ctrlx,double ctrly,double x2,double y2):  Another shape.

CubicCurve2D.Double(double x1,double y1, double ctrlx1,double ctrly1,double ctrlx2,double ctrly2,double x2,double y2): The cubic curve shape. Define it yourself seeing what shape you get :)

Arc2D.Double(Rectangle2D rd,double start,double end, int type): Rectangle2D is an abstract class therefore, we use Rectangle2D.Double class which is static inner class. In this we specify, the x,y coordinates and width and height. Next the type of the arc. Possible types are Arc2D.CHORD, Arc2D.PIE, Arc2D.OPEN.

Spring Hibernate How-To: Create a Transparent JFrame in Java Swing

Here is a sample tutorial, can be a swing hack to optimize your JFrame to give it a better look through transparency.



import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class TransparentJFrame extends JFrame
{
JButton b1;
public TransparentJFrame()
{
setTitle("Transparent JFrame Demo");
setSize(400,400);
setLayout(new GridBagLayout());
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);
//For Java 1.7 or above
setOpacity(0.4f);
//For lower java versions
//com.sun.awt.AWTUtilities.setWindowOpacity(this,0.4f);
b1=new JButton("I am a button!");
add(b1);
}
public static void main(String args[])
{
new TransparentJFrame();
}
}
GridBagLayout: To make the JButton come to center. You can use your own layout depending upon your wish.

Spring Hibernate Creating Menu Like Buttons in Swing

Buttons acting like menus in Java. It's just like what you have seen in Windows 7 and in most software. It is like Menus without a MenuBar. It is dead simple.



import javax.swing.*;
import java.awt.*;
class MenuButton extends JFrame
{
JMenuBar menuBar;
JMenu menu;
JMenuItem newFile,open,save,saveas,exit;

    public MenuButton()   
    {
    setTitle("Menu Button");
    setVisible(true);
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    setLayout(new FlowLayout());
   
    // Set a background for menubutton to have a visible look
    getContentPane().setBackground(Color.darkGray);

    menuBar=new JMenuBar();
    menuBar.setBorderPainted(false);
   
    menu=new JMenu("File");

    // It's my style!
    menu.setBorderPainted(false);

    newFile=new JMenuItem("New");
    open=new JMenuItem("Open");
    save=new JMenuItem("Save");
    saveas=new JMenuItem("Save As");
    exit=new JMenuItem("Exit");

    menu.add(newFile);
    menu.add(open);
    menu.add(save);
    menu.add(saveas);
    menu.add(exit);
   
    // Add menu to menubar
    menuBar.add(menu);

    // Add(don't set) menubar to frame
    add(menuBar);

    // Make frame maximized for a good look
        //setExtendedState(MAXIMIZED_BOTH);

    // or pack
    pack();   
    }
    public static void main(String args[])
    {
    new MenuButton();
    }

}
javax.swing.*: Contains JFrame, JMenuBar, JMenu, JMenuItem.
java.awt.*: Contains the layout classes. FlowLayout here.
borderPainted(): Make the border painted false. It is your wish!




Spring Hibernate Load Text in JTextArea with Random Speed

Load Text in JTextArea Randomly


Previously, we've seen how to load text slowly, now let us see randomly, the only one that variate this post and the previous post of Slowly Loading Text in JTextArea is the thread's sleep time, in that post, 200 a fixed int was given, but now it's random.



Let's go random!


import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.io.*;
import java.util.*;
class RandomLoadText extends JFrame
{
// Declare JTextArea reference variable
JTextArea jt;
// Create an int variable named k. Default value of k=0, because java doesn't support garbage values.
int k;
public RandomLoadText()
{
// Set frame properties
setTitle("Random Loading Speed");
setLayout(new BorderLayout());
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);

// Create JTextArea jt
jt=new JTextArea();

// Create JScrollPane for jt
JScrollPane js=new JScrollPane(jt);

// Set margin, so that text will not stick to borders
jt.setMargin(new Insets(10,10,10,10));

// Set a bigger font, for better appearance
jt.setFont(new Font("Times New Roman",Font.BOLD,22));

// Add JScrollPane to frame
add(js);

// Create a new thread
new Thread(new Runnable(){

// What to be done?
public void run()
{

// The main code!
try
{

// Create FileInputStream fin pointing this file
FileInputStream fin=new FileInputStream("RandomLoadText.java");

// Read each char & store it in k. Do this till end of file.
while((k=fin.read())!=-1)
{

// Append each char to JTextArea, "" is attached as append() takes String not char!
jt.append((char)k+"");

// Set caret position to last, this makes sense.
jt.setCaretPosition(jt.getText().length());

// Give the random effect, sleep the thread randomly each time with a value that is <200
Thread.sleep(new Random().nextInt(200));

}
}catch(Exception e){}
}

// Start the thread (start writing)
}).start();

// Make the frame wide spread over the screen.
setExtendedState(MAXIMIZED_BOTH);
}

public static void main(String args[])
{
new RandomLoadText();
}
}

 That's it, as usual everything explained above, take time to see other posts in Swing Hacks category.

Spring Hibernate Slowly Load Text in JTextArea

Have you ever thought of loading text in JTextArea as if a person types. Fine. Let us see this example that demonstrates this.



Start slow!


import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
class SlowLoadText extends JFrame
{
JTextArea jt;
FileInputStream fin;
int k;
public SlowLoadText()
{
// Set frame properties
setTitle("Slow Load Text");
setLayout(new BorderLayout());
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);

// Create JTextArea
jt=new JTextArea(400,400);

// Set font to JTextArea jt
jt.setFont(new Font("Times New Roman",Font.BOLD,22));

// Set margin to JTextArea jt, so that it does not appear sticked to the border.
jt.setMargin(new Insets(10,10,10,10));

try
{

// Create FileInputStream pointing this file.
fin=new FileInputStream("SlowLoadText.java");

// Create a new thread
new Thread(new Runnable(){
public void run()
{
try
{
// Read and store every byte in k till end of file
while((k=fin.read())!=-1)
{
try
{

// Append a char, string is needed so "" is attached
jt.append(""+(char)k);

// Set caret position to last for the effect
jt.setCaretPosition(jt.getText().length());

// Sleep for sometime for slow effect
Thread.sleep(200);

// read() and Thread.sleep() throws checked exceptions, so that's why..
}catch(Exception e){}
}
}catch(Exception e){}
}

// Start the thread
}).start();

// fin=new FileInputStream("SlowLoadText.java") throws checked exceptions
}catch(Exception e){}

// Create scrollpane for JTextArea jt
JScrollPane js=new JScrollPane(jt);

// Add JScrollPane js to JFrame
add(js);

// Make the frame maximized
 setExtendedState(MAXIMIZED_BOTH);
}
public static void main(String args[])
{
new SlowLoadText();
}
}

Watch it!


Spring Hibernate Combining JMenu with JList - MenuList

JMenu and JList Combined together!


Let us now combine JMenu with JList and name it MenuList. As you've seen in my previous post, Combining JMenu with Again, i'm using my own MenuButton to create MenuList instead of menu bar for  more space and ease access.


Let's combine!


Combining JMenu with JList - MenuList

import javax.swing.*;
import java.awt.*;
import java.util.Vector;
import java.awt.event.*;
class MenuList extends JFrame
{
JMenuBar mbar;
JMenu menu;
JList<String> jl;
public MenuList()
{
// Set frame properties
setTitle("Menu List");
setSize(400,400);
setVisible(true);
setLayout(new FlowLayout());
setDefaultCloseOperation(EXIT_ON_CLOSE);

// Create menubar
mbar=new JMenuBar();

// Create menu
menu=new JMenu("List");

// Add menu to menubar
mbar.add(menu);

// Create a vector that stores String objects
Vector<String> v=new Vector<String>();

// Add items to vector
v.add("Item 1");
v.add("Item 2");
v.add("Item 3");
v.add("Item 4");
v.add("Item 5");
v.add("Item 6");

// Create a JList with the above vector
jl=new JList<String>(v);

// Set foreground color for selected item
jl.setSelectionForeground(Color.white);

// Set background color for selected item
jl.setSelectionBackground(new Color(0,153,255));

// Set a preferred size to jlist, so that it appears quite fat
jl.setPreferredSize(new Dimension(200,200));

// Create a JScrollPane for JList jl
JScrollPane js=new JScrollPane(jl);

// Add JScrollPane to menu
menu.add(js);

// Add menubar to frame. Don't set.
add(mbar);

// Make the frame maximized
setExtendedState(MAXIMIZED_BOTH);
}
public static void main(String args[])
{
new MenuList();
}
}

That's it everything is explained within the program itself and nothing is there to say except that it is a swing hack. However, you've came till here, so take time to look at other swing hacks. 

Spring Hibernate Combining JMenu with JPanel - MenuPanel

Fine, now. Till now we've seen,

1. Create Menu Buttons in Swing
2. Combinig JSlider with JMenu to create Volume component

Now, let us combine JMenu and JPanel, so that it let us combine JMenu with various components. Again, in this below example, i've used my MenuButton instead of Menu because it occupies less space and gets mixed up with other components in the JFrame.


Combine now!


import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class MenuPanel extends JFrame
{
JMenuBar mbar;
JMenu menu;
JPanel jp;
JTextField jc;
JButton jb;
public MenuPanel()
{
setTitle("Menu Panel");
setSize(400,400);
setLayout(new FlowLayout());
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);

 // Create menubar
mbar=new JMenuBar();

 // Create menu
menu=new JMenu("Menu");

 // Create JPanel
jp=new JPanel();

 // Create JTextField with capacity of 20 chars to show
jc=new JTextField(20);

 // Create JButton with text Set
jb=new JButton("Set");

 // Add JTextField jc to JPanel
jp.add(jc);

 // Add JButton jb to JPanel
jp.add(jb);

 // Add JPanel jp to JMenu
menu.add(jp);

 // Add menu to menu bar
mbar.add(menu);

 // Add JMenuBar mbar to JFrame
add(mbar);

 // Add KeyListener to JTextField jc
jc.addKeyListener(new KeyAdapter(){

  // Do things when key is pressed
public void keyPressed(KeyEvent ke)
{
if((ke.getKeyCode()==KeyEvent.VK_BACK_SPACE)||(ke.getKeyCode()==KeyEvent.VK_DELETE))
{

// Control enters this if() when user presses either backspace or Delete because these 2 actions could only modify the text.
if(jc.getText().length()>0)
// Set JButton jb enabled. It will be disabled when user clicks on it and enabled when he modifies text.
jb.setEnabled(true);
}
}
});

// Add ActionListener to JButton jb
jb.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae)
{
   // Check if text in JTextField length is >0, you can alternatively call isEmpty()
if(jc.getText().length()>0)
{
   // Set text in JTextArea jc as title of the frame. Title is not set, if jc has no text.
setTitle(jc.getText());
   // Set JButton jb disabled, so that user may not click on it until the text is modified.
jb.setEnabled(false);
}
}
});
}

public static void main(String args[])
{
new MenuPanel();
}
}

I've explained all the important steps above, and there is nothing more to say and it is just simply a swing hack. Hope you understand, if you don't feel free to drop a comment. I'll definitely respond to it if it is not a spam.

See more under Swing Hacks category.

Spring Hibernate Combining JSlider with JMenu - Volume Component

JMenu and JSlider Coded Together


Let us code two JMenu and JSlider together to make a volume component in swing. That's dead simple. Here is a program demonstrating it.

As said in the post Creating MenuButtons in Swing this example is much related to it.



Example

MenuSlider Volume

/*
* MenuSlider.java - Swing JSlider in JMenu - Coded together.
* Copyright (C) 2012  Gowtham Gutha. All Rights Reserved.
* Website: http://java-demos.blogspot.com
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class MenuSlider extends JFrame
{
JMenuBar mbar;
JMenu menu;
JSlider js;
public MenuSlider()
{
setTitle("Menu Slider");
setLayout(new FlowLayout());
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);

js=new JSlider();
mbar=new JMenuBar();
menu=new JMenu("Volume");
menu.add(js);
mbar.add(menu);
add(mbar);
setExtendedState(MAXIMIZED_BOTH);
}

public static void main(String args[])
{
new MenuSlider();
}
}


Explanation


js=new JSlider(): Create a new JSlider using the first constructor.

mbar=new JMenuBar(): Create a JMenuBar.

menu=new JMenu("Volume"): Create a JMenu menu with text Volume

menu.add(js): Add JSlider to the JMenu.

mbar.add(menu): Add JMenu (menu) to JMenuBar.

add(mbar): Add JMenuBar to frame. Don't set it. If you do, the menubar appears from starting to end of the frame. It spreads over. That may not be good. However, for a Volume like component it the adding looks better. If you wish to, it's your wish. You can change it. Note that, the license is about not to change & publish it on other sites, it doesn't restrict you to change and use it in your application.


You can download the entire source code(.java) file from Google Code here.

Other swing examples can be found at code.google.com/p/swing-examples/

Spring Hibernate Creating Authentication Window in Swing

Create Login Window in Swing


Creating a login page, if login is successful, then proceed to the next frame. This is the most given homework i think so, because many people have been asking this since time. Fine, now i've done it. This program that i've written don't just look big and not just limited to the specified homework (authentication), instead there are many things to learn from it.



What else is coded? What still can i know?


1. Using HTML tags in Swing, here i've used the <a> tag.
2. The next one was adding components (other than menus) to JMenuBar.
3. Sharing a common adapter class among the components
4. Catching an enter key and doing the action (what the users do most without clicking on the button to login).
5. Disposing a frame, instead of making it invisible or terminating the entire program.

Begin the code!

UserLogin

Welcome Frame


import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

class UserLogin extends JFrame
{
JButton login,cancel;
JTextField uname;
JPasswordField pass;
JLabel u,p;
public UserLogin()
{
setTitle("Login");
setLayout(new GridLayout(3,2));
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);

u=new JLabel("Username");
p=new JLabel("Password");

uname=new JTextField(20);
pass=new JPasswordField(20);

login=new JButton("Login");
cancel=new JButton("Cancel");

add(u);
add(uname);

add(p);
add(pass);

add(login);
add(cancel);

uname.requestFocus();

cancel.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae)
{
System.exit(0);
}
});

login.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae)
{
String un=uname.getText();
String pa=new String(pass.getPassword());

if((un.equals("myuser"))&&(pa.equals("mypass")))
{
dispose();
new WelcomeFrame();
}
}
});

KeyAdapter k=new KeyAdapter(){
public void keyPressed(KeyEvent ke)
{
if(ke.getKeyCode()==KeyEvent.VK_ENTER)
login.doClick();
}
};

pass.addKeyListener(k);
uname.addKeyListener(k);

pack();
setLocationRelativeTo(null);
}

class WelcomeFrame extends JFrame
{
JLabel exit;
JMenuBar mbar;
JLabel label;

public WelcomeFrame()
{
setTitle("Welcome");
setSize(400,400);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);

mbar=new JMenuBar();
mbar.setLayout(new FlowLayout());

label=new JLabel("You are logged in.");
mbar.add(label);
exit=new JLabel("<html><a href=''>Exit</a></html>");
exit.setCursor(new Cursor(Cursor.HAND_CURSOR));
exit.setFont(new Font("Tahoma",Font.PLAIN,13));

exit.addMouseListener(new MouseAdapter(){
public void mouseClicked(MouseEvent ae)
{
System.exit(0);
}
});

mbar.add(exit);

setJMenuBar(mbar);

setExtendedState(MAXIMIZED_BOTH);
}
}

public static void main(String args[])
{
new UserLogin();
}

}

Explanation


javax.swing.*: JFrame, JLabel, JTextField, JPasswordField, JMenuBar, JButton used here.

java.awt.*: GridLayout, FlowLayout, Cursor, Font used here.

java.awt.event.*: ActionEvent, ActionListener, KeyListener, KeyEvent used here.

uname.requestFocus(): This method makes the component uname (here) focused when the frame appears.

cancel.addActionListener(....){System.exit(0);}: When cancel is clicked exit the program.

un=uname.getText(): Get what the user types in the field uname

pa=new String(pass.getPassword()): getPassword() in JPasswordField returns char[] so using the constructor of the java.lang.String class String(char[] c), i've used it.

equals(): Compares strings whether they are equal or not. Here, un, pa are compared with myuser, mypass respectively.

dispose(): If they (username,password) become true, dispose the UserLogin frame.

new WelcomeFrame(): Create WelcomeFrame object.

What if user presses enter?


k=new KeyAdapter(){}: Provide the body for the interface by providing body for the method(s) in it. Here only keyPressed(KeyEvent) is used since this is an adapter class and not directly listener interface, so it's anonymous inner class is written and it's reference is stored in k

ke.getKeyCode(): Returns the code of what key user presses.

KeyEvent.VK_ENTER: This is a static int variable containing the code for ENTER

login.doClick(): Does a click on the button login therefore, it's action event is generated and things will be done.


pack(): Pack everything. Show only the components and not the extra space.


setLocationRelativeTo(null): Center the JFrame.


WelcomeFrame


If you want to use HTML in Swing, you must use it in the form of text. As in the above example,

exit=new JLabel("<html><a href=''>Exit</a></html>"): This code creates a new label with text Exit which looks like an <a> (anchor link in your browser). Note that, the href attribute, that doesn't work here, it is of no use here, instead it is kept to appear Exit as an anchor link.

setCursor(new Cursor(Cursor.HAND_CURSOR)): This method sets the cursor for a particular component on which it is called. This method takes java.awt.Cursor as parameter. This class consists of some predefined int constants which represent several cursors. In order to create a Cursor object we need to call it's constructor by specifying the int value which represents the type of the cursor for which the Cursor object has to be created.

exit.addMouseListener(){System.exit(0);}: Exit the program when mouse is clicked on Exit (exit).

mbar.add(exit): mbar was a JMenuBar object. It was previously created but was not explained, it is undetsood and you might have seen in many programs, here i am adding exit to menubar instead of JFrame. This mbar has FlowLayout.

Spring Framework Set Background Image to JMenuBar

This illustrates setting background image to JMenuBar. For this we need to paint an background image on JMenuBar. 1 main step is far from background image.






import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

class MenuBarBackground extends JFrame

{

JMenuBar mbar;

JMenu menu;

public MenuBarBackground()

{

setTitle("MenuBar Background");

setDefaultCloseOperation(EXIT_ON_CLOSE);

setVisible(true);



mbar=new JMenuBar(){

public void paintComponent(Graphics g)

{

g.drawImage(Toolkit.getDefaultToolkit().getImage("F:/Wallpapers/violetpink.png"),0,0,this);

}

};



menu=new JMenu("Menu");

menu.setForeground(Color.white);

for(int i=1;i<=5;i++)

menu.add(new JMenuItem("MenuItem "+i));



mbar.add(menu);

setJMenuBar(mbar);

setSize(400,400);

}

public static void main(String args[])

{

new MenuBarBackground();

}

}

Output

Background Image for JMenuBar
Look at menubar background image

paintComponent(Graphics g): Takes java.awt.Graphics as parameter. This contains drawImage() method which takes java.awt.Image object, x,y axes and ImageObserver object. paint() is not used here because, if we use this, i could not see the Menu.

g.drawImage(Toolkit.getDefaultToolkit().getImage("F:/Wallpapers/violetpink.png"),0,0,this): Method of java.awt.Graphics class. java.awt.Toolkit is a class containing a static method getDefaultToolkit() which returns the object of that class only (java.awt.Toolkit). This class contains getImage() method which takes the path of the image file and returns the java.awt.Image object. My background image is located in F:\Wallpapers. You can notice / instead of \ this is because / is equal to \\ in Windows and similar operating systems. Next, 0,0 are the x,y co ordinates respectively. Try changing them, you'll notice the change. this represents current object which acts as ImageObserver.

In this way, we can set background image to JMenuBar easily in single step.

Spring Framework Create Relatively moving JFrames in Swing

Let us create jframes that moves relatively. That is of one frame moves, the other frame's position does not change. This is seen in ImgBurn, the log window and the main window moves relatively. This is a simple Swing hack. Here we go.





import javax.swing.*;

import java.awt.event.*;

class StickedFrames

{

public static void main(String args[])

{

final JFrame f=new JFrame("Frame 1");

f.setVisible(true);

f.setSize(400,400);

f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);



final JFrame f1=new JFrame("Frame 2");

f1.setVisible(true);

f1.setSize(400,150);

f1.setLocation(f.getX()+f.getHeight(),f.getY()+f.getWidth());

f1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);



f.addComponentListener(new ComponentAdapter()

{

public void componentMoved(ComponentEvent ce)

{

//f1.setLocation(f.getX()+f.getWidth(),f.getY());

f1.setLocation(f.getX(),f.getY()+f.getWidth());

}

});





}

}

Output

Relatively move JFrames in Swing
Sticked JFrames

For this, i am adding a ComponentListener to the JFrame. Here if f moves then f1 moves but vice versa simultaneously is not possible. I've tried repeating the same code for moving jframes relatively and some more different code must be written. Let me explain the first commented lines.

f1.setLocation(f.getX()+f.getWidth(),f.getY()): The location of the down frame. Here the frame appears side by side. Here the top-left corner of the down frame (in the image) is set side of the top-right corner of the first frame. And y-axis of both the frames are same.

f1.setLocation(f.getX(),f.getY()+f.getHeight()): The location of the down frame. For the second frame to locate down, this statement is used. Here, the x-axis of both the frames are same, the y-axis is what that differs. The top-left corner of the second frame is set along the y-axis of the first frame, but down to the first frame. So for this, the getHeight() method in the first frame is called which gets height of the first frame.

In this way, you can relatively move JFrames in swing. Drop a comment.

Spring Framework How to close JDialog on Escape

I am frustrated when i wanted to close JDialog on Escape method. Now finally i got it. I encountered a method which will do the thing. I think you might be enthusiastic to know that method. Let me show how to do this and how the method works.
Let me first explain the prototype of the method registerKeyboardAction()


registerKeyboardAction(ActionListener a, KeyStroke s, int aCondition) In this the ActionListener contains the method actionPerformed() which contains the code that escapes the dialog (here). The KeyStroke object which can be obtained by the getKeyStroke() static method in KeyStroke is used to specify the key along with the modifier if we wish to. The aCondition is the condition when to fire this event. In this example i'll be using the condition when the component is in a focused window.


import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

class EscapeJDialog extends JFrame

{

private JButton jb;

private JFrame thisFrame;

public EscapeJDialog()

{



/* this cannot be used directly to represent

* this object when in anonymous inner class

*/



thisFrame=this;



// Call the method

createAndShowGUI();

}



private void createAndShowGUI()

{

// set frame properties

setTitle("Escape JDialog");

setSize(400,400);

setLayout(new FlowLayout());

setVisible(true);

setDefaultCloseOperation(EXIT_ON_CLOSE);



jb=new JButton("Open JDialog");

jb.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent ae)

{

// Parent is this frame

final JDialog jd=new JDialog(thisFrame);

jd.setTitle("Escape JDialog");

jd.setLayout(new FlowLayout());

jd.setVisible(true);



// add some sample components

jd.add(new JTextField(10));

jd.add(new JButton("Button!"));



// pack it up

jd.pack();



// create ActionListener

ActionListener a=new ActionListener(){

public void actionPerformed(ActionEvent ae)

{

jd.dispose();

}

};



/*

* Register the actionlistener which should

* be fired on ESCAPE when the rootpane is

* in focused window

*/



jd.getRootPane().registerKeyboardAction(a,KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE,0),JComponent.WHEN_IN_FOCUSED_WINDOW);

}

});



add(jb);

}



public static void main(String args[])

{

new EscapeJDialog();

}

}

Output of the program

Closing JDialog on escape using ActionListener


In this way we can close JDialog on Escape. Simple is that.

Labels

.equals = operator abstract class abstract method abstract window toolkit Access Modifiers accessing java beans accessing javabeans action events actionperformed active addition Advanced Advanced Overloading AdvJavaBooks Agile development ajax alive AMQP and Android anonymous class anonymous inner class Ant ant tutorials anti patterns antipatterns Apache Camel api for jsp api for servlet api for servlets api jsp application context application scope application session Apps Architecture are you eligible for the ocmjd certificaiton are you eligible for the scjd certification arithmetic operator arpanet array construction array declaration array initialization array list array to list conversion arraylist arraylist of strings arraylist of types arraylist questions arraylists Arrays arrays in java ask for help assert assert in java assertions assertions in java assignment assignment operator Atlassian attribute visibility authentication authorization autoboxing autounboxing awt AWT Event Handling awt interview questions AWT Layouts awt questions awt questions and answers backed collection backed collections Basic Basics of event handling bean attributes bean properties bean scope Beginner best practices BigData blocked books boxing buffer size bufferedreader bufferedwriter business delegate business delegate pattern calendar case statement casting in java casting interview questions chapter review choosing a java locking mechanism choosing a locking mechanism choosing a thread locking mechanism class inside a method class questions class with no name class without a name classes interview questions Clipboard closing jsp tags code snap coding cohesion collection generics collection interview questions collection methods collection of types collection questions collection searching collection types Collections Collections Framework collections interview questions collections sorting colors in java swings colors in swing command line arguments communication between threads comparable comparator comparison operators compiling java classes computers concurrency example and tutorial config Configuration ConnectionPooling constructor creation constructor interview questions constructor overloading constructors in java containers contents of deployment descriptor contents of web.xml context context scope converting array to list converting list to array core java core java interview core java interview question core java interview questions core java questions core java; core java; object oriented programming CoreJava CoreJavaBooks CORS coupling create threads creating 2 dimensional shapes creating 2D shapes creating a frame creating a jframe creating a thread creating an arraylist creating an inner class creating an interface creating java beans creating java threads creating javabeans creating threads creating threads in java CSS cURL currency current thread determination custom tag library custom taglib custom taglibs custom tags CVS dao dao design pattern dao factory pattern dao pattern data access object data access object pattern data structure and algorithm database date and time tutorial date format dateformat dates deadlock deadlocks debugging Declarations decorator pattern decrement default deleting sessions deploy web app deployment deployment descriptor deployment descriptor contents deployment of web application deserialization deserialize design pattern design pattern interview questions design patterns Designpatterns destory method destroy destroying sessions determining current thread determining the current thread Developer Differences different types of collections display stuff in a frame displaying images displaying images in java swings displaying images in swings displaying text in a component division do while loop doget dohead dopost doput DOS Downloads drawing a line drawing an ellipse drawing circles drawing ellipses drawing lines Drools tutorial eBooks Eclipse Eclipse Tutorial Encapsulation encapsulation in java enhanced for loop entity facade pattern enumerations enumerations in java enums equal to equals equals comparison error and exception error codes error handling in servlets error page event handling in swings event listeners exam prep tips example servlet Examples exception exception handling exception handling in servlets exception handling interview questions exception handling questions Exceptions exceptions in java exceptions in web applications explicit locking explicit locking of objects file file navigation filereader filewriter final class final method FireBug first servlet FIX protocol FIX Protocol interview questions FIX protocol tutorial font fonts for each loop for loop form parameters form values formatting forwarding requests frame frame creation frame positioning frame swings front controller front controller design pattern front controller pattern fundamental.Java FXML Games garbage collection garbage collection interview questions garbage collection questions garbage collector gc gc questions general generic Generics generics collections Geo get get set methods getattribute getting bean property getting form values getting form values in servlet getting scwcd certified getting servlet initialization parameters getting sun certified Google Graphics2D gregorian calendar handling strings in java hash hash map hash table hashcode hashmap hashset hashtable head head request HeadFirst heap heaps hibernate hibernate interview questions hibernate interview questions and answers hibernate questions hibernate questions and answers Hibernate Tutorial HibernateBooks homework How To HTML HTML and JavaScript html form http request http request handling http request header http request methods http request servlet http request type http session httprequest httprequest methods httpservlet httpservlet interview questions httpservlet interview questions with answers httpsession httpsession interview questions httpsession questions HttpSessionActivationListener HttpSessionAttributeListener HttpSessionBindingListener if if else if else block if else statement Image IO implementing an interface Implicit objects increment info inheritance inheritance in java init init method Initialization Blocks inner class inner class inside a method inner classes innerclass installation instanceof instanceof operator IntelliJ interaction between threads interface interface interview interface questions interfaces interfaces in java interfaces interview questions internet history interrupting a thread interrupting threads Interview interview questions interview questions on design patterns interview questions on exception handling interview questions on java collections interview questions on serialization introduction to java threads introduction to jsps introduction to threading introduction to threads invalidating session Investment Banking IO Package iscurrentthread iterator J2EE j2ee api j2ee design pattern j2ee design pattern interview questions j2ee design patterns j2ee hibernate interview questions j2ee history j2ee interview j2ee interview questions j2ee mvc j2ee mvc pattern j2ee programmer j2ee questions j2ee servlet api j2ee session j2ee struts interview questions java java 5 tutorial Java 8 java arrays java assertions java assignments java awt questions java bean java bean scope java beans java beginners tutorial Java career java certification Java Class java collection interview questions and answers java collection tutorial java collections java collections interview questions java constructors java currency Java CV java data base connectivity java database connectivity java database connectivity interview questions and answers java dates java design pattern java design patterns java developer certification Java EE java encapsulation java enums java event listeners java exceptions java formatting java garbage collection java garbage collector java gc java heap Java I/O java inheritance java input output Java Interface Java Interview Java Interview Answers Java Interview Questions Java Introduction java io java IO tutorial java iterator java jdbc Java JSON tutorial Java Key Areas java lists java literals java locks nested Java Media Framework java methods java multithreading Java multithreading Tutorials java nested locks java networking tutorial java numbers Java Objects java operators java overloading java parsing Java Programming Tutorials java race conditions java regex java regular expressions Java resume java scjp java searching java serialization java server pages java server pages api java server pages questions java spring interview questions. j2ee spring interview questions java stack java strings java swing java swing event listeners java swing frame java swing images java swings java swings images java thread explicit locking java thread lock scope java thread locking java thread locking mechanism java thread locking objects java threads java threads race condition java tips java tokenizing Java Tools Java Tutorial java ui questions Java Utilities java variables java wrappers Java xml tutorial java.lang java8 javabean javabean accessing javabean scope JavaBeans javac JavaEE JavaFX JavaFX 3D JavaFX 8 JavaOne JavaScript JavaTips JDBC jdbc driver jdbc example jdbc interview questions jdbc interview questions and answers jdbc interview questions with answers jdbc sample code JDBC Tutorial jdbc type 1 driver jdbc type 2 driver jdbc type 3 driver jdbc type 4 driver Jdeveloper JDK JDK8 JEE Tutorial jframe jframe creation jframe position jframe positioning JIRA JMeter JMS JMX join() joining threads JPA JQuery JS JSF JSF Tutorial JSONP JSP jsp and java beans jsp and servlets jsp and xml jsp api jsp code jsp compilation jsp conversion jsp directives jsp error page jsp error page directive jsp implicit objects jsp interview jsp interview questions jsp introduction jsp intvw questions jsp life jsp life cycle jsp life-cycle jsp lifecycle jsp page directive jsp questions jsp sample jsp scripting jsp scriptlets jsp servlets jsp summary jsp synopsis jsp tag libraries jsp tag library jsp taglib jsp tags jsp technology jsp to servlet jsp to servlet conversion jsp translation jsp usage jsp usebean jsp xml tags jsp xml tags usage jsp-servlet jsp:getProperty jsp:setProperty jsp:usebean jsps JSTL JUnit testing keyword synchronized keyword volatile Keywords Lambda Expressions Learning libraries life cycle life cycle of a jsp life cycle of a servlet life cycle of a thread life cycle of jsp life cycle of threads lifecycle of a thread linked list linkedhashmap linkedhashset linkedlist linux List listeners lists Literals locale lock manager pattern lock scope locking objects using threads log Logging logging errors logical and logical operators logical or loops loosely coupled making an arraylist making threads sleep making threads sleep for time MapReduce maps maps usage Maven Maven Tutorial max priority member access method arguments method local inner class method overloading method overriding method return types methods creating classes min priority Miscellaneous mobile mock exam model view controller model view controller design pattern model view controller pattern Multi Threading Multi-threading multiple threads multiplication multithreading multithreading in java multithreading interview questions multithreading questions mvc mvc design pattern mvc pattern MyEclipse mysql nested java lock nested java locks nested java thread locks nested locks nested thread locks NetBeans Networking new news nio NonAccess Modifiers norm priority normal inner class Normalization not equal to Notepad notify notifyall number format numberformat numbers object comparison object notify object orientation object oriented object oriented programming Object Oriented Programming in java objects interview questions ocmjd certification ocmjd certification eligibility OO OO Java oops OpenCSV OpenCV opening jsp tags OpenJDK OpenJFX Operators or Oracle Oracle ADF Mobile Oracle Certified Exams oracle certified master java developer oracle database ORM other topics out overloading overloading constructors overloading in java overriding page page directive page scope parsing passing variables passing variables to methods performance Platform Playing with Numbers points to remember polymorphism positioning a frame post practice exam Primitive Casting primitive variables printwriter priority queue priority queues priorityqueue priorityqueues private processing form values Products programming Projects protected public put questions questions on garbage collection questions on java strings queue quick recap quick review race conditions read objects from stream reading http request header RealTime_Tips redirecting to another servlet redirection reference reference variable casting reference variables Refreshing Java regex Regular Expressions regular inner class relational operators reminder request request dispatcher request forwarding request header request object. httpservletrequest request scope requestdispatcher response RESTClient RESTful retrieving values from session return error codes return types returning values runnable runnable interface running running java programs RUP sample jsp sample questions sample questions scwcd sample servlet scanner Scene Builder scjd certification scjd certification eligibility requirements scjp SCJP Certification scjp exam scjp exam questions scjp exam sample questions scjp questions scjp test scjp test questions scope scope of java locks scope of java thread locks scope of locks scripting in jsp scriptlet tags scriptlets scriptlets in jsp pages scwcd scwcd certification scwcd certification practice exam scwcd exam scwcd exam questions scwcd jsp summary scwcd mock exam scwcd mock exam answers scwcd practice exam scwcd practice test scwcd questions scwcd test SDLC searching searching arrays searching collections searching in java searching treemap searching treesets security self assement self assement scwcd self assessment scjp self test self test scjp self test scwcd send error method senderror method sending error code to browser serialization serialization in java serialization interview questions Serialization on Swing serialization questions service service method servlet servlet and forms servlet and jsp servlet api servlet attributes servlet code servlet container servlet context servlet error handling servlet exception handling servlet handling http request servlet initialization servlet initialization parameters servlet interview servlet interview questions servlet interview questions with answers servlet intvw questions servlet life cycle servlet lifecycle servlet questions servlet questions with answers servlet request servlet request dispatcher servlet request type servlet skeleton servletcontext servletcontextevent servletrequest Servlets servlets and jsps servlets api servlets details servlets request handling session session clean up session event listeners session facade pattern session interview questions session invalidation session listeners session management session questions session scope session timeout session tracking through url rewriting set collections set status method setattribute sets setstatus method setting bean property setting request type short circuit operators Singleton sleep sleeping threads soapUI Software Installation sorting sorting arraylist sorting arrays sorting collections special collections special inner classes split spring spring and hibernate interview questions spring batch Spring Core Spring Framework Spring Integration spring interview questions Spring JDBC Spring MVC Spring security Spring tutorial SQL SQL and database tutorial examples SQL Tutorial SSL stack stacks stacks and heaps static static class static declaration static imports static inner static inner class static method Static variable stopped stopping a thread stopping thread stopping threads Stored Procedure storing values in session Streams strictfp StrictMath string string buffer string builder string class string formatting String Handling string interview questions string manupulation string questions string tokenizer stringbuffer stringbuffer questions stringbuilder Strings strings in java struts Struts 1 Struts 1.2 Struts 2 struts framework interview questions struts interview questions struts interview questions with answers struts mvc interview questions struts questions Struts2 StrutsBooks submitting request subtraction Sun Certification sun certified java developer Sun Certified Java Programmer swing swing action performed swing and colors Swing Components swing event handling swing event listeners swing events Swing Hacks swing images Swing Look And Feels swings swings frame switch block switch case block switch case statement Sybase Sybase and SQL Server synchronization synchronized code synchronized keyword synchronized method System Properties tag lib tag library tag-lib taglibs tags TDD Technical Blogging ternary operator Test Driven Development test scjp Testing the context the session the volatile keyword thread thread class thread deadlocks thread interaction thread interruption thread life cycle thread lifecycle thread lock scope thread locks thread notify thread priorities thread race conditions race conditions in threads thread sleep thread states thread stoppage thread stopping thread synchronization thread syncing thread yield Threads threads in java threads interview questions threads life cycle threads questions tibco tightly coupled tips tips and tricks tips.FXML tokenizing Tomcat Tools toString transitions treemap treeset tricks Tricks Bag try catch try catch finally. finally block Tutorial type casting in java ui programming with java swings UML unboxing unit testing unix url rewriting use bean usebean using a arraylist using collections using colors using colours using command line arguments using different fonts using expressions using font using fonts using fonts in swings using hashmap using http session using httpsession using iterator using java beans in jsp using javabean in jsp using javabeans in jsp using javac using lists using maps using request dispatcher using scriptlets using session persistense using sets using special fonts using system properties using the jsp use bean using treeset using use bean Using Variables using volatile Using Wrappers using xml in jsp Util pack value object value object design pattern value object pattern var-args varargs Variable Arguments Variables vector vector questions vectors visibility vo pattern volatile volatile keyword volatile variables wait method waiting web app exception handling web app interview web application deployment web application exceptions web application scope web application security web component developer web component developer certification web context web context interfaces web context listeners web interview questions web security web server web servers Web services web.xml web.xml deployment webapp log weblogic website hacking website security what are threads what is a java thread what is a thread what is thread while loop windows windows 8 wrapper classes wrappers write objects to stream WSAD xml xml and jsp xml tags xslt yield()