Sunday, November 20, 2011
tips Of java 1:Changing The Icon of Java frame
By default java frame have the icon in the picture below
. Here i am going to explain a way to change the icon of java frame.
Create jframe using JFrame f=new JFrame("sample");
Set static java.net.URL imgURL = Window.class.getResource("images/icon.jpg");
Call f.setIconImage(getFDImage());
function getFDImage()
protected static Image getFDImage() {
if (imgURL != null) {
return new ImageIcon(imgURL).getImage();
} else {
return null;
}
}
This will change the icon to icon.jpg put this file into images folder.
. Here i am going to explain a way to change the icon of java frame.
Create jframe using JFrame f=new JFrame("sample");
Set static java.net.URL imgURL = Window.class.getResource("images/icon.jpg");
Call f.setIconImage(getFDImage());
function getFDImage()
protected static Image getFDImage() {
if (imgURL != null) {
return new ImageIcon(imgURL).getImage();
} else {
return null;
}
}
This will change the icon to icon.jpg put this file into images folder.
Changed Icon |
Monday, November 14, 2011
Two Way Chat
In two way chat we have two programs one is a server and the other is a client
Here in server program we create a server socket with a port of 6789(can be changed) by usingser=new ServerSocket(6789); and socket is connected to it by using socket=ser.accept(); Also we create inputstream reader and outputstream reader in the server.java file
In client we create a socket and connect it to the port number 6789 by using socket=new Socket(InetAddress.getLocalHost(),6789); Also we create inputstream reader and outputstream reader in the client.java file
For running the Chat we have to run server using a one command prompt and client using another command prompt.
Sunday, November 13, 2011
Analogue Clock
This is a program for creating Analogue Clock using applet. An applet is a program written in the Java programming language that can
be included in an HTML page, much in the same way an image is included
in a page. When you use a Java technology-enabled browser to view a page
that contains an applet, the applet's code is transferred to your
system and executed by the browser's Java Virtual Machine (JVM). For
information and examples on how to include an applet in an HTML page.
For this we need two files one java file and one html file. In the java file the below program should be pasted and should save as "Clock.java" and html file you have to include the program given bellow
Java Hello World
Basic Java Program
This is the first step to the java world. Here i am going to explain how can a simple string "Hello World" print or display in the command prompt. For this all we need is the JDK(java development kit).
You can download it from the link given below. If you had it, then you are ready now.
Just install it and find the path where the jdk is located and the find the bin folder (for 64bit os it is "C:\Program Files\Java\jdk1.7.0_01\bin" , for 32 bit os it isC:\Program Files (x86)\Java\jdk1.7.0_01\bin)
If you have any other version of java then you can replace the version no with yours..
This is the first step to the java world. Here i am going to explain how can a simple string "Hello World" print or display in the command prompt. For this all we need is the JDK(java development kit).
You can download it from the link given below. If you had it, then you are ready now.
Just install it and find the path where the jdk is located and the find the bin folder (for 64bit os it is "C:\Program Files\Java\jdk1.7.0_01\bin" , for 32 bit os it isC:\Program Files (x86)\Java\jdk1.7.0_01\bin)
If you have any other version of java then you can replace the version no with yours..
Simple Calculator
SIMPLE CALCULATOR PROGRAM USING J FRAME
Given Bellow Is a java Program To create a simple calculator......
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Calculator extends JFrame implements ActionListener{
// Variables
Given Bellow Is a java Program To create a simple calculator......
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Calculator extends JFrame implements ActionListener{
// Variables
Subscribe to:
Posts (Atom)