Set JOptionPane warning icon

Complete source code below will show you, how to set warning icon in JOptionPane.

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


import javax.swing.*;

public class SetJOptionPaneWarningIcon
{
public static void main(String[]args)
{
//null-Message Box appear in no parent component
//Warning Icon-text in message box
//WARNING-JOptionPane title
//JOptionPane.WARNING_MESSAGE-Set warning icon that will be show in message box
JOptionPane.showMessageDialog(null,"Warning Icon","WARNING",JOptionPane.WARNING_MESSAGE);
}
}


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

Set JOptionPane error icon

Complete source code below will show you, how to set error icon in JOptionPane.

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


import javax.swing.*;

public class SetJOptionPaneErrorIcon
{
public static void main(String[]args)
{
//null-Message Box appear in no parent component
//Error Icon-text in message box
//ERROR-JOptionPane title
//JOptionPane.ERROR_MESSAGE-Set error icon that will be show in message box
JOptionPane.showMessageDialog(null,"Error Icon","ERROR",JOptionPane.ERROR_MESSAGE);
}
}


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

Set JOptionPane information icon

Complete source code below will show you, how to set information icon in JOptionPane.

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


import javax.swing.*;

public class SetJOptionPaneInformationIcon
{
public static void main(String[]args)
{
//null-Message Box appear in no parent component
//Information Icon-text in message box
//INFORMATION-JOptionPane title
//JOptionPane.INFORMATION_MESSAGE-Set information icon that will be show in message box
JOptionPane.showMessageDialog(null,"Information Icon","INFORMATION",JOptionPane.INFORMATION_MESSAGE);
}
}


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

Set JOptionPane question icon

Complete source code below will show you, how to set question icon in JOptionPane.

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


import javax.swing.*;

public class SetJOptionPaneQuestionIcon
{
public static void main(String[]args)
{
//null-Message Box appear in no parent component
//Question Icon-text in message box
//QUESTION-JOptionPane title
//JOptionPane.QUESTION_MESSAGE-Set question icon that will be show in message box
JOptionPane.showMessageDialog(null,"Question Icon","QUESTION",JOptionPane.QUESTION_MESSAGE);
}
}


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

Create simple digital clock in java

Complete source code below, will show you, how to create simple digital clock in java.

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


import javax.swing.*;

import java.awt.*;

import java.util.Date;

public class SimpleDigitalClock extends JPanel
{
JFrame frame;

int currentHour;
int currentMinute;
int currentSecond;

//Font that will be use to show digital clock
Font myFont=new Font("Tahoma",Font.BOLD+Font.ITALIC,20);

//Color that will be use to show digital clock
Color myColor=new Color(255,0,0);

//Font metrics that will use to store font informations
//For example, width of a character
FontMetrics fm;

public SimpleDigitalClock()
{
//Create a window using JFrame with title ( Simple Digital Clock )
frame=new JFrame("Simple Digital Clock");

//add(this) mean add created panel into JFrame
//Which panel ?
//See line 81 and 7 (I hope you understand it)
frame.add(this);

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

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

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

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

/*
*Loop that will make sure panel show current time
*like current second, current minute and current hour.
*/
while(true)
{
//It will do all code in method paint(See line 67)
repaint();

try
{
Thread.sleep(900);
}
catch(Exception exception)
{
exception.printStackTrace();
}
}
}

public void paint(Graphics g)
{
super.paint(g);

/*
*Create current Date object. It means it store information
*about current hour, minute and second.
*/
Date myDate=new Date();

currentHour=myDate.getHours();
currentMinute=myDate.getMinutes();
currentSecond=myDate.getSeconds();

//Set font that will use to draw digital number
g.setFont(myFont);

//Information about distance between number in digital clock
fm=g.getFontMetrics();
int hourXCoordinate=20;
int minuteXCoordinate=hourXCoordinate+(fm.getMaxAdvance()*2);
int secondXCoordinate=hourXCoordinate+(fm.getMaxAdvance()*4);

//Set color that will use to draw digital number
g.setColor(myColor);

//Draw hour, draw (:) between number, draw minute and draw second.
g.drawString(Integer.toString(currentHour),hourXCoordinate,20);
g.drawString(":",(hourXCoordinate+minuteXCoordinate)/2,20);
g.drawString(Integer.toString(currentMinute),minuteXCoordinate,20);
g.drawString(":",(secondXCoordinate+minuteXCoordinate)/2,20);
g.drawString(Integer.toString(currentSecond),secondXCoordinate,20);
}

public static void main(String[]args)
{
SimpleDigitalClock sdc=new SimpleDigitalClock();
}
}


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

Get current second

Complete source code below, will show you how to get current computer second and print the value. The second value that it get is second value at program executing time.

>>Get current minute
>>Get current hour
>>Get current computer time in java

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


import java.util.Date;

public class GetCurrentSecond
{
public static void main(String[]args)
{
Date myDate=new Date();

//Get current second
int currentSecond=myDate.getSeconds();

//Print current second that we get
System.out.println("Current second is : "+currentSecond);
}
}


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

Get current minute

Complete source code below will print current computer minute.

>>Get current second
>>Get current hour
>>Get current computer time in java

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


import java.util.Date;

public class GetCurrentMinute
{
public static void main(String[]args)
{
Date myDate=new Date();

//Get current minute
int currentMinute=myDate.getMinutes();

//Print current minute that we get
System.out.println("Current minute is : "+currentMinute);
}
}


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

Get current hour

Complete source code below will print current computer hour in soldier time format.Soldier time format is 24 hour format.

>>Get current minute
>>Get current second
>>Get current computer time in java

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


import java.util.Date;

public class GetCurrentHour
{
public static void main(String[]args)
{
Date myDate=new Date();

//Get current hour in soldier time format
int currentHour=myDate.getHours();

//Print current hour that we get
System.out.println("Current hour is : "+currentHour);
}
}


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

Get current computer time in java

Complete source code below will show you, how to get current computer time in java.

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


import java.util.Date;

public class GetCurrentTime
{
public static void main(String[]args)
{
Date myDate=new Date();

System.out.println(myDate.getHours()+":"+myDate.getMinutes()+":"+myDate.getSeconds());
}
}


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

Set ToolTipText background color

Complete source code below, will show you how to set ToolTipText background color.

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


import javax.swing.UIManager;
import javax.swing.JFrame;
import javax.swing.JButton;

import java.awt.FlowLayout;
import java.awt.Color;

public class SetToolTipTextBackgroundColor
{
/**
*Create a button with text ( Put your cursor on me )
*/
JButton button=new JButton("Put your cursor on me");

//Create a window using JFrame with text ( Set ToolTipText background color )
JFrame frame=new JFrame("Set ToolTipText background color");

public SetToolTipTextBackgroundColor()
{
//Create a color base on RGB value
//You can get your color value base on RGB using Color picker at above
//R=204 G=0 B=153
Color backgroundColor=new Color(204,0,153);

//Create UIManager
UIManager uim=new UIManager();

//Set tooltiptext background color using created Color
uim.put("ToolTip.background",backgroundColor);

//Set tooltiptext for created button
button.setToolTipText("I am a button");

frame.setLayout(new FlowLayout());
frame.add(button);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(400,400);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}

public static void main(String[]args)
{
SetToolTipTextBackgroundColor stttbc=new SetToolTipTextBackgroundColor();
}
}


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

RELAXING NATURE VIDEO