Message box appear in JFrame

Complete source code below will show you, how to make message box appear in a container.

**********************************************************************
COMPLETE SOURCE CODE FOR : MessageBoxAppearInJFrame.java
**********************************************************************


import javax.swing.JOptionPane;

import javax.swing.JFrame;

public class MessageBoxAppearInJFrame
{
public static void main(String[]args)
{
//Create a window using JFrame with title ( Message box appear in JFrame )
JFrame frame=new JFrame("Message box appear in JFrame");

//Set default close operation for JFrame
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

//Set JFrame size
frame.setSize(400,400);

//Make JFrame locate at center on screen
frame.setLocationRelativeTo(null);

//Make JFrame visible
frame.setVisible(true);


//Pop up a message box with text ( I am a message dialog ) in created JFrame
JOptionPane.showMessageDialog(frame,"I am a message dialog");
}
}


**********************************************************************
JUST COMPILE AND EXECUTE IT
**********************************************************************

Create message box in java

Complete source code below will show you, how to create message box in java. We will use JOptionPane class to create message box. If you want your message box appear in a container, you can change null in source code below to target container.You can see example by click here.

************************************************************************
COMPLETE SOURCE CODE FOR : JavaMessageDialog.java
************************************************************************


import javax.swing.JOptionPane;

public class JavaMessageDialog
{
public static void main(String[]args)
{
//Pop up a message box with text ( I am a message dialog )
JOptionPane.showMessageDialog(null,"I am a message dialog");
}
}


************************************************************************
JUST COMPILE AND EXECUTE IT
************************************************************************

Read floating point number user input in java

Complete source code below, will show you how to wait and read floating point number user input in command prompt.

********************************************************************
COMPLETE SOURCE CODE FOR : ReadFloatingPointNumberUserInput.java
********************************************************************


import java.util.Scanner;

public class ReadFloatingPointNumberUserInput
{
public static void main(String[]args)
{
try
{
//Create a scanner object
//Scanner is a predefined class in java that will be use to scan text
//System.in is mean, we will receive input from standard input stream
Scanner readUserInput=new Scanner(System.in);

//Print into command prompt(Put a floating point number : )
System.out.print("Put a floating point number : ");

//Wait and READ FLOATING POINT NUMBER from user input after user hit 'Enter'
float myPointNumber=readUserInput.nextFloat();

//Print what store in myPointNumber
System.out.println("My floating point number is : "+myPointNumber);
}
catch(Exception exception)
{
//Error that will be print if user put other than floating point number
System.out.println("Hey !!! Don't put other than floating point number");
}
}
}


********************************************************************
JUST COMPILE AND EXECUTE IT
********************************************************************

Read integer user input in java

Complete source code below, will show you how to wait and read integer user input in command prompt.

**********************************************************************
COMPLETE SOURCE CODE FOR : ReadIntegerUserInput.java
**********************************************************************


import java.util.Scanner;

public class ReadIntegerUserInput
{
public static void main(String[]args)
{
try
{
//Create a scanner object
//Scanner is a predefined class in java that will be use to scan text
//System.in is mean, we will receive input from standard input stream
Scanner readUserInput=new Scanner(System.in);

//Print into command prompt(What is your age ?)
System.out.println("What is your age ?");

//Wait and READ INTEGER INPUT from user after user hit 'Enter'
int myAge=readUserInput.nextInt();

//Print what store in myAge
System.out.println("Your age is : "+myAge);
}
catch(Exception exception)
{
//Error that will be print if user put other than number include
//point number
System.out.println("Hey !!! Don't put other than number");
}
}
}


**********************************************************************
JUST COMPILE AND EXECUTE IT
**********************************************************************

Read a word user input in java

Complete source code below, will show you how to wait and read only a word from user input in command prompt.

*****************************************************************
COMPLETE SOURCE CODE FOR : ReadOneWordUserInput.java
*****************************************************************


import java.util.Scanner;

public class ReadOneWordUserInput
{
public static void main(String[]args)
{
//Create a scanner object
//Scanner is a predefined class in java that will be use to scan text
//System.in is mean, we will receive input from standard input stream
Scanner readUserInput=new Scanner(System.in);

//Print into command prompt(What is your gender ?)
//Print into command prompt(Female/Male)
System.out.println("What is your gender ?\nFemale/Male");

//Wait and READ A WORD from user input after user hit 'Enter'
//Method next() in class scanner will read only first word in user input
//So, second word that seperate by space will be ignore.
String myGender=readUserInput.next();

//Print what store in myGender
System.out.println(myGender);
}
}


*****************************************************************
JUST COMPILE AND EXECUTE IT
*****************************************************************

Read text user input in java

Complete source code below, will show you how to wait and read text user input in command prompt.

********************************************************************
COMPLETE SOURCE CODE FOR : ReadTextUserInput.java
********************************************************************


import java.util.Scanner;

public class ReadTextUserInput
{
public static void main(String[]args)
{
//Create a scanner object
//Scanner is a predefined class in java that will be use to scan text
//System.in is mean, we will receive input from standard input stream
Scanner readUserInput=new Scanner(System.in);

//Print into command prompt(What is your name ?)
System.out.println("What is your name ?");

//Wait and READ TEXT INPUT from user after user hit 'Enter'
String myName=readUserInput.nextLine();

//Print what store in myName
System.out.println(myName);
}
}


********************************************************************
JUST COMPILE AND EXECUTE IT
********************************************************************

Wait user input in java

Complete source code below will show you, how to wait for user input in command prompt.
Input is a line of text.

**********************************************************************
COMPLETE SOURCE CODE FOR : WaitUserInput.java
**********************************************************************


import java.util.Scanner;

public class WaitUserInput
{
public static void main(String[]args)
{
//Create a scanner object
//Scanner is a predefined class in java that will be use to scan text
//System.in is mean, we will receive input from standard input stream
Scanner readUserInput=new Scanner(System.in);

//Print into command prompt(What is your name ?)
System.out.println("What is your name ?");

//WAIT FOR USER INPUT
//After user put it's name, he or she must press 'Enter'
//After user press 'Enter', all the input contents will read into 'myName'
String myName=readUserInput.nextLine();

//Print what it store in myName
System.out.println(myName);
}
}


**********************************************************************
JUST COMPILE AND EXECUTE IT
**********************************************************************

User input in java

Ok, now i share with you how you can handle user input in java.

>>Receive user input from command line


>>Receive user input from input box


>>Receive user input from text field

>>Receive user input from text area

Tip for BoxLayout

BoxLayout enable we arrange components into two direction. Firstly is horizontal and secondly is vertical.

Example source code for set layout using BoxLayout

Set JPanel layout using BoxLayout

Complete source code below will show you how to set JPanel layout using BoxLayout

*******************************************************************
COMPLETE SOURCE CODE FOR : SetJPanelLayoutUsingBoxLayout.java
*******************************************************************


import javax.swing.*;

import java.awt.*;

public class SetJPanelLayoutUsingBoxLayout
{
public static void main(String[]args)
{
//Create a window using JFrame with title ( Set JPanel layout using BoxLayout )
JFrame frame=new JFrame("Set JPanel layout using BoxLayout");

//Create a panel using JPanel
JPanel panel=new JPanel();

//Set JPanel layout using BoxLayout with vertical lay out
//You can try change to BoxLayout.X_AXIS to make components lay out in horizontal
panel.setLayout(new BoxLayout(panel,BoxLayout.Y_AXIS));

//Create a button with text ( First button )
JButton button=new JButton("First button");

//Create a button with text ( Second button )
JButton button2=new JButton("Second button");

//Create a button with text ( Third button )
JButton button3=new JButton("Third button");

//Create a dimension with :
//Width : 10 pixels
//Height : 10 pixels
Dimension dim=new Dimension(10,10);

//Create an invisible box with dimension size and add into created panel
//You can try eliminate this and see what happen
panel.add(Box.createRigidArea(dim));

//Add button into panel
panel.add(button);

//Create an invisible box with dimension size and add into created panel
//You can try eliminate this and see what happen
panel.add(Box.createRigidArea(dim));

//Add button2 into panel
panel.add(button2);

//Create an invisible box with dimension size and add into created panel
//You can try eliminate this and see what happen
panel.add(Box.createRigidArea(dim));

//Add button3 into panel
panel.add(button3);

//Create an invisible box with dimension size and add into created panel
//You can try eliminate this and see what happen
panel.add(Box.createRigidArea(dim));

//add panel into created JFrame
frame.add(panel);

//Set default close operation for JFrame
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

//Set JFrame size
frame.setSize(500,200);

//Make JFrame locate at center of screen
frame.setLocationRelativeTo(null);

//Make JFrame visible
frame.setVisible(true);
}
}


*******************************************************************
JUST COMPILE AND EXECUTE IT
*******************************************************************

RELAXING NATURE VIDEO