Put image as jframe background

Put image as jframe background


bg.jpg



Source code below will make a jframe with bg.jpg as it's background image.

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


import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JButton;

import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.FlowLayout;

public class PutImageOnJFrame extends JPanel
{
public PutImageOnJFrame()
{
setOpaque(false);
setLayout(new FlowLayout());
}

public static void main(String[]args)
{
JFrame myFrame=new JFrame("Put Image");
JButton button1=new JButton("Sample 1");
JButton button2=new JButton("Sample 2");
PutImageOnJFrame c=new PutImageOnJFrame();
c.add(button1);
c.add(button2);
myFrame.add(c);
myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
myFrame.setSize(400,400);
myFrame.setVisible(true);
}

public void paint(Graphics g)
{ //IT DEPEND ON YOUR PICTURE AND PUT IT'S LOCATION IN
Image a=Toolkit.getDefaultToolkit().getImage("E:\\_JAVA_\\---SOURCE CODE---\\bg.jpg");
g.drawImage(a,0,0,getSize().width,getSize().height,this);
super.paint(g);
}

//THANKS FOR WATCHING
}


********************************************************
JUST COMPILE AND EXECUTE IT.
Note : Before that, you must know your image location. Copy and paste your image location into Image a=Toolkit.getDefaultToolkit().getImage(PASTE_IN_THIS);
********************************************************

Change jframe background color

Source code below will show you how to change jframe background color. You can try new color base on RGB value by change value at Color b=new Color(R_value,G_value,B_value). You can use "Color picker" above to get new R,G and B value.

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


import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.Color;

public class ChangeJFrameBackgroundColour
{
public static void main(String[]args)
{
JFrame a=new JFrame("CHANGE BACKGROUND COLOUR");

//Now we will try change it's value
Color b=new Color(120,255,0);

JPanel c=new JPanel();
c.setBackground(b);

a.add(c);
a.setSize(600,200);
a.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
a.setVisible(true);

//I hope you enjoy
//Bye
}
}


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

Pause thread in java

Source code below will print hi after pause for 5 seconds.

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


public class ThreadPause extends Thread
{
public void run()
{
//Pause thread for 5 seconds before print hi
try
{
sleep(5000);
}
catch(Exception exception)
{
exception.printStackTrace();
}

//Print hi
System.out.println("hi");
}

public static void main(String[]args)
{
//Create a thread by create ThreadPause object
ThreadPause a=new ThreadPause();

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


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

Stop thread in java

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


import javax.swing.JOptionPane;

public class StopThread implements Runnable
{
int currentValue=0;

public void run()
{
while(true)
{
JOptionPane.showMessageDialog(null,"currentValue = "+currentValue);

String temp=JOptionPane.showInputDialog(null,"CHOOSE 1 OR 2\n1-Continue Thread\n2-Stop Thread");

if(temp.equals("2"))
{
JOptionPane.showMessageDialog(null,"Thread Stop, Bye");
return;//This will make thread stop
}
else if(temp.equals("1"))
{
currentValue=currentValue+1;
JOptionPane.showMessageDialog(null,"Please stop me, i'm tired\ncurrentValue will add one");
}
else
{
JOptionPane.showMessageDialog(null,"I don't know your input");
}
}
}

public static void main(String[]args)
{
//Create a thread by create StopThread object
StopThread a=new StopThread();

//run thread
a.run();
}
}


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

Create thread in java

Create thread in java

COMPLETE SOURCE CODE FOR CreateThread.java


public class CreateThread implements Runnable
{
//all thread implementation will be put in run method
public void run()
{
//Print hi
System.out.println("HI");
}

public static void main(String[]args)
{
//Create thread by create CreateThread object
CreateThread a=new CreateThread();

//run the thread
a.run();
}
}


JUST COMPILE AND EXECUTE IT

Simple Shutdown Timer For Windows XP

Source code below will show you how to create simple shutdown timer for Windows XP.

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


import javax.swing.JOptionPane;

public class ShutdownComputer
{
public static void main(String[]args)
{
int wholeTimeBeforeShutdown=0;

int hour=0;
int minute=0;
int second=0;

try
{
String a=JOptionPane.showInputDialog(null,"HOUR","HOUR BEFORE SHUTDOWN",JOptionPane.QUESTION_MESSAGE);
String b=JOptionPane.showInputDialog(null,"MINUTE","MINUTE BEFORE SHUTDOWN",JOptionPane.QUESTION_MESSAGE);
String c=JOptionPane.showInputDialog(null,"SECOND","SECOND BEFORE SHUTDOWN",JOptionPane.QUESTION_MESSAGE);

if((a==null)||(a.equals("")))
{
a="0";
}

if((b==null)||(b.equals("")))
{
b="0";
}

if((c==null)||(c.equals("")))
{
c="0";
}

int e=Integer.parseInt(a);
int f=Integer.parseInt(b);
int g=Integer.parseInt(c);

wholeTimeBeforeShutdown=wholeTimeBeforeShutdown+((e*60)*60);
wholeTimeBeforeShutdown=wholeTimeBeforeShutdown+(f*60);
wholeTimeBeforeShutdown=wholeTimeBeforeShutdown+(g);

wholeTimeBeforeShutdown=wholeTimeBeforeShutdown*1000;

Thread.sleep(wholeTimeBeforeShutdown);

Runtime.getRuntime().exec("shutdown -s -t 00 -f");
}
catch(Exception exception)
{
exception.printStackTrace();
}
}
}


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

Remove element from array

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


public class RemoveElementFromAnArray
{
public static void main(String[]args)
{
//Now we want to remove last element,"crocodile"
String[]animal={"lion","tiger","elephant","crocodile"};

//Step 1:Create a temp array with sizeArrayAnimal-1
String[]temp=new String[animal.length-1];

//Step 2:Copy element from "lion" to "elephant" into array temp
System.arraycopy(animal,0,temp,0,(animal.length-1));

//Make animal array point to temp array
animal=temp;

//Print all element in animal
int temp2=0;
while(temp2!=animal.length)
{
System.out.println(animal[temp2]);
temp2=temp2+1;
}
}
}


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

Add element in array

Note : Source code below will show you how to add new element in a created array. It will add "monkey" word in an array that contains "lion","tiger","elephant","crocodile" word.

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


public class AddElementInArray
{
public static void main(String[]args)
{
//Create array with it's component
String[]animal={"lion","tiger","elephant","crocodile"};

//Add an element - "Monkey"
String a="monkey";

//Step 1:Create temp array (size=(arrayThatWeWantToAddElement)+1)
String[]temp=new String[(animal.length)+1];
System.arraycopy(animal,0,temp,0,animal.length);
temp[temp.length-1]=a;

//Make animal array point to temp array
animal=temp;

//Print all element in animal
int temp2=0;
while(temp2!=animal.length)
{
System.out.println(animal[temp2]);
temp2=temp2+1;
}
}
}


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

Copy all contents from one array to other array

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


public class CopyArray
{
public static void main(String[]args)
{
//Create array with it's component
String[]animal={"lion","tiger","elephant","crocodile"};

//Create empty array with size same as animal
String[]animal2=new String[animal.length];

//Copy all element in animal into animal2
System.arraycopy(animal,0,animal2,0,animal.length);

//Print all element in animal2
int temp=0;
while(temp!=(animal.length))
{
System.out.println(animal2[temp]);
temp=temp+1;
}
}
}


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

Convert primitive type to string in java

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


public class ConvertPrimitiveTypeToString
{
public static void main(String[]args)
{
//boolean
String a=String.valueOf(true);
System.out.println("boolean : "+a);

//byte
a=String.valueOf((byte)9);
System.out.println("byte : "+a);

//char
a=String.valueOf('a');
System.out.println("char : "+a);

//short
a=String.valueOf((short)9);
System.out.println("short : "+a);

//int
a=String.valueOf(9);
System.out.println("int : "+a);

//long
a=String.valueOf(9L);
System.out.println("long : "+a);

//float
a=String.valueOf(9.0F);
System.out.println("float : "+a);

//double
a=String.valueOf(9.0D);
System.out.println("double : "+a);
}
}


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

RELAXING NATURE VIDEO