Showing posts with label ADVANCED JAVA. Show all posts
Showing posts with label ADVANCED JAVA. Show all posts

Wednesday, 26 September 2012

Slide Show Applet

/* Java applet to display sildeshow to images from a given folder in thumbnail form, images can be selected one by one and can be enable/disable slideshow of images. The thumbnail images are placed in slides folder, the download button(rectangle) downloads the images from the web server, hence a webserver is required eg : any webserver even tomcat webserver with download folder with images*/

/* Requirements
1. Name of java file : Sildeshow.java
2. Name of images folder : slides
3. Names of images 1.jpg, 2.jpg and so on upto 8.jpg.
3. Name of download folder in webserver : download
4. Download images given below and paste them in slides folder :
1.jpg2.jpg3.jpg4.jpg5.jpg6.jpg7.jpg8.jpg
5. Download images given below and paste them in download folder in webserver :
1.jpg2.jpg3.jpg4.jpg5.jpg6.jpg7.jpg8.jpg

Java Code for Sildeshow

import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.net.*;
public class Slideshow extends Applet implements Runnable
{
// Variable Declaration
Thread runner;
boolean left,right,click,auto;
boolean but0,but1;
boolean b0,b1;
boolean waitMessage = true;
String str_desc[] = { // Display Messages
" This is an Abstract piece.Painted on:20/11/86.",
" This picture is an Abstract work.Painted on:10/1/89.",
" This picture is a Canvas oil painting (15/8/92).",
" This is a Pastel painting (2/10/99).",
" This picture is an Abstract piece.Painted on:6/5/03.",
" This is a Brush painting (2/6/05).",
" This a painted collage (30/1/83).",
" This is my Graphical art piece.Painted on:20/12/08."};
int number=1;
static final int MAX=8;
Image Picture[]=new Image[MAX]; // Image variable
Image Buffer;
Graphics gBuffer; // Graphics Variable
Font a = new Font("Helvetica", Font.PLAIN,12);
Font b = new Font("Dialog", Font.PLAIN,10);
Font c = new Font("Helvetica", Font.BOLD,13);
Rectangle r0=new Rectangle(400,70,50,20); // ON / OFF
Rectangle r1=new Rectangle(400,195,120,20); // Click Here
void loadGraphics()
{ //
Track the status of a number of media objects
MediaTracker t=new MediaTracker(this);
for(int i=0;i< MAX;i++)
{
// Load an image in an applet
Picture[i]=getImage(getCodeBase(),"slides/"+(i+1)+".jpg");
t.addImage(Picture[i],0);
try{
t.waitForAll(0);
}
catch(InterruptedException e)
{
}
waitMessage=false;
}
}

public void init()
{
// Creates an image
Buffer=createImage(size().width,size().height);
gBuffer=Buffer.getGraphics();
// Creates a graphics context for this component
}
public void start()
{
if (runner == null)
{
runner = new Thread (this);
runner.start();
}
}
public void stop()
{
if (runner != null)
{
runner.stop();
runner = null;
}
}
public void run()
{
while(true)
{
try
{
runner.sleep(2500);
}
catch (Exception e)
{ }
if(auto)
{
if(number< MAX)
number++;
else
number=1;
}
repaint();
}
}
public void update(Graphics g)
{ paint(g); }
public void drawArrow(int w,int h,int x,int y,boolean left,boolean over,boolean click)
{
if(click&&over) // set color to yellow on click or mouse over
gBuffer.setColor(Color.yellow);
else
if(over) // set color to orange on mouse over
gBuffer.setColor(Color.orange);
else
// set color to red on click
gBuffer.setColor(Color.red);
if(left)
{
int al[] = {x,x+w,x+w};
int bl[] = {y+h/2,y,y+h};
gBuffer.fillPolygon(al, bl, 3);
}
else {
int ar[] = {x,x,x+w};
int br[] = {y,y+h,y+h/2};
gBuffer.fillPolygon(ar, br, 3);
}
}
public void drawPanel()
{
gBuffer.setColor(Color.white);
gBuffer.fillRect(0,0,size().width,size().height);
// Display Text
drawArrow(40,40,330+70,120,true,left,click);
// Display Left Arrow
drawArrow(40,40,380+70,120,false,right,click);
// Display Right Arrow
gBuffer.setColor(Color.lightGray);
gBuffer.setFont(b);
gBuffer.setColor(auto?Color.orange:Color.lightGray);
gBuffer.fill3DRect(400,70,50,20,!but0);
// Rectangle for ON rectangle
gBuffer.setColor(b0?Color.red:Color.black);
// Color For ON rectangle
String s=auto?"OFF":"ON";
gBuffer.drawString(s,410,85);
gBuffer.setColor(Color.lightGray);
// Download
s="Click Here";
gBuffer.fill3DRect(400,190,120,20,!but1);
gBuffer.setFont(a);
gBuffer.setColor(b1?Color.red:Color.black);
gBuffer.drawString(s,430,205);
// Display Image
gBuffer.drawImage(Picture[number-1],20,20,this);
gBuffer.setColor(Color.black);
gBuffer.setFont(c);
gBuffer.drawString("Slideshow:",300,80);
gBuffer.drawString("Scroll:",300,140);
gBuffer.drawString("Download it!",300,200);
gBuffer.drawString("Description:",300,35);
gBuffer.setFont(a);
gBuffer.drawString(str_desc[number-1],300,50);
}
public boolean mouseDown(Event evt,int x,int y)
{
if(r0.inside(x,y))
{
but0=true; auto^=true;
}
if(r1.inside(x,y))
{
but1=true;
auto=false;
}
if(but1)
{
String link ="http://localhost:8080/download/"+number+".jpg";
try {
// corresponds to an applet's environment
AppletContext a = getAppletContext();
URL url = new URL(link);
// url of the image to be downloaded
a.showDocument(url,"_blank");
}
catch (MalformedURLException e){
System.out.println(e.getMessage());
}
}
if(left)
{
auto=false;
if(number>1)
number--;
else number=8;
}
if(right)
{
auto=false;

if(number< MAX)
number++;
else
number=1;
}
click=true;
repaint();
return true;
}
public boolean mouseUp(Event evt,int x,int y)
{
but0=but1=click=false;
repaint();
return true;
}
public boolean mouseMove(Event evt,int x,int y)
{
Rectangle rl=new Rectangle(330+70,120,40,40);
Rectangle rr=new Rectangle(380+70,120,40,40);
if(rl.inside(x,y))
left=true;
else
left=false;
if(rr.inside(x,y))
right=true;
else
right=false;
if(r0.inside(x,y))
b0=true;
else
b0=false;
if(r1.inside(x,y))
b1=true;
else
b1=false;
repaint();
return true;
}
public void paint(Graphics g)
{
if(waitMessage)
{ g.setColor(Color.blue);
g.drawString("Loading images, please wait...",200,100);
loadGraphics();
}
else
{
drawPanel();
g.drawImage (Buffer,0,0, this);
}
}
}
//< code ="Slideshow" height ="500" width="500">
//< /applet>

Ps: This program works fine, errors if any kindly leavea comment...

Databse Connectivity in Java

Program in java for inserting, recording, deleting, editing and searching student details stored in the SQL database.

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.sql.SQLException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import java.sql.ResultSet;


class studentdetails
{
Statement stmt;
String strSql;
Connection con;
BufferedReader bufferObj;
studentdetails (){
bufferObj=new BufferedReader(new InputStreamReader(System.in));
}

void establishConnection()
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException ex)
{
System.out.println(ex);
}

try
{
String url="jdbc:odbc:new_dsn";
con=DriverManager.getConnection(url,"sa","");
stmt=con.createStatement();
}
catch(SQLException ce)
{
System.out.println("Error... "+ce);
}
}


void add()
{
try
{
System.out.println("\nEnter Roll Number: ");
String rollno=bufferObj.readLine();

System.out.println("\nEnter Students Name: ");
String name=bufferObj.readLine();

System.out.println("\nEnter Course Name");
String course=bufferObj.readLine();

strSql="Insert into Student values(" +rollno+",'"+name+"',' "+course+" ')";

stmt.executeUpdate(strSql);
System.out.println("\nRecords Successfully Added!");

System.out.println();
}

catch(SQLException ce)
{
System.out.println("Error... "+ce);
}

catch(Exception e)
{
System.out.println(e);
}
}

void update()
{
try
{
System.out.println("\nEnter Roll Number whose "+"record should be updated: ");
String roll=bufferObj.readLine();
System.out.println("Enter Students Name to be Modified: ");
String name=bufferObj.readLine();
System.out.println("Enter course name to be modified: ");
String course=bufferObj.readLine();
strSql="update Student set name=' "+name+" ',course='"+course+"' where rollno='"+roll+"'";

stmt.executeUpdate(strSql);
System.out.println("\nRecord Successfully Modified !");
System.out.println();
}

catch(SQLException ioe)
{
System.out.println(ioe);
}

catch(Exception er)
{
System.out.println(er);
}
}

void delete()
{
try
{

System.out.println("Enter Students Name to be Deleted :") ;
String name=bufferObj.readLine();
strSql="Delete from Student where rtrim(name) like '"+name+ "'";

stmt.executeUpdate(strSql);
System.out.println("Record Successfully Deleted !");
System.out.println();
}

catch(SQLException et)
{
System.out.println("Error in Deletion.... "+et);
}

catch(Exception ty)
{
System.out.println("Error.... "+ty);
}
}

void search()
{
try
{
System.out.println("Enter Roll Number "+"whose record should be searched: ");
int roll=Integer.parseInt(bufferObj.readLine());

System.out.println("Enter Students Name to be Searched");
String name=bufferObj.readLine();

strSql="select * from student where name like'"+name;
strSql=strSql+"' and Rollno="+roll;

ResultSet rs=stmt.executeQuery(strSql);
if(!rs.next())
{
System.out.println("Name");
System.out.println(rs.getString(1)+"\t");
System.out.println("Roll Number");
System.out.println(rs.getInt(2)+"\t");
System.out.println("Course");
System.out.println(rs.getString(3)+"\n");
}
}

catch(SQLException er)
{
System.out.println(er);
}

catch(Exception t)
{
System.out.println(t);
}
}

public void menudisplay() throws IOException
{
char choice;
while(true)
{
System.out.println();
System.out.println("1. Add a Record");
System.out.println("2. Modify Record");
System.out.println("3. Delete a Record");
System.out.println("4. Search a Record");
System.out.println("5. Exit");
System.out.println("Enter your choice....:");

BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
choice=(char) br.read();
switch(choice)
{
case '1' :
System.out.println("Adding a Record........");
add();
break;

case '2' :
System.out.println("Updating a Record........");
update();
break;

case '3' :
System.out.println("Deleting a Record........");
delete();
break;

case '4' :
System.out.println("Searching a Record........");
search();
break;

case '5' :
System.exit(0);
break;

default :
System.out.println("Adding a Record........");
add();
break;

}
}
}
}

class student
{
public static void main(String[] args) throws IOException
{
studentdetails stud = new studentdetails();
stud.establishConnection();
stud.menudisplay();
}
}

Data Connectivity

/* Java Program that implements data connectivity */

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
public class Test extends JFrame implements ActionListener
{
Container con;
JLabel l1;
JLabel l2;
JLabel l3;
JLabel l4;
JLabel l5;
JTextField lt1;
JTextField lt2;
JTextField lt3;
JTextField lt4;
JTextField lt5;
JButton lb1;
Connection con1;
Statement s;
ResultSet rs;
public Test()
{
super("student details!!!");
con=getContentPane();
con.setLayout(null);
l1=new JLabel("Roll no.");
l1.setBounds(50,10,250,75);
con.add(l1);

l2=new JLabel("Name");
l2.setBounds(50,30,250,75);
con.add(l2);

l3=new JLabel("Age");
l3.setBounds(50,50,250,75);
con.add(l3);

l4=new JLabel("Address");
l4.setBounds(50,70,250,75);
con.add(l4);

l5=new JLabel("Marks");
l5.setBounds(50,90,250,75);
con.add(l5);

lt1=new JTextField(10);
lt1.setBounds(115,35,100,15);
con.add(lt1);

lt2=new JTextField(20);
lt2.setBounds(115,60,100,15);
con.add(lt2);

lt3=new JTextField(30);
lt3.setBounds(115,80,100,15);
con.add(lt3);

lt4=new JTextField(40);
lt4.setBounds(115,103,100,15);
con.add(lt4);

lt5=new JTextField(50);
lt5.setBounds(115,127,100,15);
con.add(lt5);

lb1=new JButton("GO");
lb1.setBounds(250,30,100,50);
con.add(lb1);

lb1.addActionListener(this);
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con1=DriverManager.getConnection("jdbc:odbc:mydsn","sa","");
s=con1.createStatement();
}
catch(SQLException e)
{
System.out.println(e.toString());
}
catch(ClassNotFoundException e)
{
System.out.println(e.toString());
}
}
public void actionPerformed(ActionEvent e)
{
/*int m=Integer.parseInt(lt1.getText());
String n=lt2.getText();
int o=Integer.parseInt(lt3.getText());
String p=lt4.getText();
int q=Integer.parseInt(lt5.getText());*/

String str="select *from student_det1 where roll_no='"+lt1.getText()+ "'";
System.out.println(str);
try
{
rs=s.executeQuery(str);
while(rs.next())
{
lt2.setText(rs.getString(2));
lt3.setText(rs.getString(3));
lt4.setText(rs.getString(4));
lt5.setText(rs.getString(5));
}
}
catch(SQLException ee)
{
System.out.println(ee.toString());
}
}
public static void main(String args[])
{
Test t=new Test();
t.setSize(500,600);
t.setVisible(true);
}
}

Properties Of URL

import java.net.*;

class Gotest
{
public static void main(String agrs[]) throws MalformedURLException
{
URL hp = new URL("http://www.javapgms.blogspot.com/Array.html");
System.out.println("Protocol : " +hp.getProtocol());
System.out.println("Port : " +hp.getHost());
System.out.println("Host : " + hp.getHost());
System.out.println("File : " +hp.getFile());
}
}

/*

getProtocol() : Returns the protocal identifier of the given URL object.
getPort() : Returns the integer value of the port number of the URL Object. If the port is not set the it returns -1.
getHost() : Returns The Host Name.
getFile() : Returns The file Name.
getRef() : Returns The reference component

Fetch Url Of A Site

/* Java Program To Fetch The Url Of Any Site */

import java.io.*;
import java.net.*;

public class fetchUrl
{
public static void main(String args[])
{
try
{
if(args.length !=1)
{
System.out.println("Usage: java fetchUrl < URL such as http://www.javapgms.blogspot.com>");
System.exit(0);
}
System.out.println("Hello");
URL url = new URL (args[0]);
System.out.println("\n Fetching URL :" +args[0] +"\n");
BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream()));
String strline;
while((strline = br.readLine())!=null)
{
System.out.println(strline);
}
br.close();
}
catch(MalformedURLException mue)
{
System.out.println("Unknown URL");
}

catch(IOException ioe)
{
System.out.println("IO Error");
}
}
}

Vertical Scroll a Shape

/* Java Program To Move a Shape say Oval from the bottom of the applet to the center, a vertical scroll in an infinite loop ie once the shape reaches the denter it goes back to the bottom and repeats the path */

import java.awt.*;
import java.applet.*;

public class VertiScroll extends Applet implements Runnable
{
int x,y;
Dimension size;

public void init()
{
//set initial co-ordinates for message
x = 230;
y = 450;
//creates new thread
Thread t = new Thread(this);
t.start();
}
public void run()
{
while (true)
{
try
{
/*initialize size to contain the current size of the applet window */

size = getSize();
/* if co-ordinate of the oval is lesser than reset the height of the applet the x coordinate to a value say 200 else decrement y */

if(y< 200)
y = 450;
y--;
Thread.sleep(20);
}
catch(InterruptedException e)
{
}
repaint();
}
}

public void paint(Graphics g)
{
g.setColor(Color.red);
g.fillOval(x,y,40,50);
}
}

/*< applet code=VertiScroll Width=500 Height = 500>< /applet>*/

Horizontal Scroll Text - 2

/* Program In Java To Display A text and to scroll the text from left to right, display the text as colored */

import java.awt.*;
import java.applet.*;

public class HoriScroll2 extends Applet implements Runnable
{
String message = "Pay-Per-Play Starts on Feburary....";
int x,y;
Dimension size;

public void init()
{
//set initial co-ordinates for message
x = 300;
y = 50;
//creates new thread
Thread t = new Thread(this);
t.start();
}
public void run()
{
while (true)
{
try
{
/*initialize size to contain the current size of the applet window */

size = getSize();
/* if co-ordinate of the text is lesser than a value say 5 reset the width of the applet the x coordinate to 500 else decrement x */

if(x< 5)
x = 500;
x--;
Thread.sleep(50);
}
catch(InterruptedException e)
{
}
repaint();
}
}

public void paint(Graphics g)
{
g.setFont(new Font("Terminal",Font.BOLD|Font.ITALIC,26));
g.setColor(Color.green);
g.drawString(message,x,y);
}
}

/*< applet code=HoriScroll2 Width=500 Height = 500>< /applet>*/

Horizontal Scroll Text

/* Program In Java To Display A text and to scroll the text from right to left, display the text as colored */

import java.awt.*;
import java.applet.*;

public class HoriScroll extends Applet implements Runnable
{
String message = "Lionel Cyril ....";
int x,y;
Dimension size;

public void init()
{
//set initial co-ordinates for message
x = 10;
y = 50;
//creates new thread
Thread t = new Thread(this);
t.start();
}
public void run()
{
while (true)
{
try
{
/*initialize size to contain the current size of the applet window */

size = getSize();
/* if co-ordinate of the text is greater than reset the width of the applet the x coordinate to 10 else increment x */

if(x>size.width)
x = 0;
x++;
Thread.sleep(50);
}
catch(InterruptedException e)
{
}
repaint();
}
}

public void paint(Graphics g)
{
g.setFont(new Font("Monotype Corsiva",Font.BOLD,24));
g.setColor(Color.red);
g.drawString(message,x,y);
}
}

/*< applet height="500" width="500" code="HoriScroll">< /applet>*/

ProgressBar

/* Simple Java Program for the implementation of ProgressBar, you can also refer to the progressbar code given beow and implement it in your programs */

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

class ProgressBarr extends JFrame implements ActionListener
{
JButton jb;
JProgressBar jpb1;
int value =0;
ProgressBarr()
{
Container contentPane=getContentPane();
contentPane.setLayout(new FlowLayout());

jb = new JButton("Click");
contentPane.add(jb);
jb.addActionListener(this);

jpb1 = new JProgressBar(0,1000);
contentPane.add(jpb1);
jpb1.setStringPainted(true);
}

public static void main(String args[])
{
ProgressBarr pb1 = new ProgressBarr();
pb1.setSize(500,500);
pb1.setVisible(true);
}

public void actionPerformed(ActionEvent ae)
{
while(value< =1000)
{
value = value+10;
jpb1.setValue(value);
}
}
}

Sunday, 23 September 2012

Log In Page / Calculation Of Product

/* Java Program :
Components included in this session : Buttons, Labels, Text Fileds, Combo Box and Menu Bar.
 




The Given Program that accepts a login name and password from the user. The application contains two buttons. The 'Log In 'button when clicked, checks the user name and password entered in the text box, and the ‘cancel’ button will terminate the application. The user is excepted to enter both username and password before clicking the Log In button.
If the correct username and password is entered by the user, then a new frame is opened where product rate and quantity are displayed. The product is a combo box which has 5 options :

Product 1
Product 2
Product 3
Product 4
Product 5

On selecting product 1 the rate displayed on the text field will be 150, similarly product 2, product 3, product 4 and product5 will display rate as 250, 350, 450 and 550 respectively. The rate text field will be Editable false i.e. the contents of rate box cannot be edited. The select the respective Quantity for the product. On clicking the enter button again a new frame will be opened where all the components are editable false and a new text field is displayed where the total amount is displayed. In addition to this a menu bar called ‘file’ is also displayed on the container which has two menu items new and exit, on clicking new the log in page is opened and on clicking exit the application is terminated.

The username and password in the given program
username: javapgms
password: lionel
*/

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

public class Admin extends JFrame implements ActionListener
{
JTextField jft1,jft2;
JButton b1,b2;
Container cont;

Admin()
{
cont = getContentPane();
cont.setLayout(null);

JLabel jl1=new JLabel("Username:");
cont.add(jl1);
jl1.setBounds(20,30,100,20);

jft1=new JTextField();
cont.add(jft1);
jft1.setBounds(100,30,200,30);

JLabel jl2=new JLabel("Password:");
cont.add(jl2);
jl2.setBounds(20,80,100,20);

jft2=new JTextField();
cont.add(jft2);
jft2.setBounds(100,80,200,30);

b1=new JButton("Sign In");
cont.add(b1);
b1.setBounds(75,150,100,30);
b1.addActionListener(this);

b2=new JButton("Cancel");
cont.add(b2);
b2.setBounds(200,150,100,30);
b2.addActionListener(this);
}

public static void main(String args[])
{
Admin admn=new Admin();
admn.setSize(400,400);
admn.setVisible(true);
}

public void actionPerformed(ActionEvent ae)
{
if(ae.getSource() == b2)
System.exit(0);

String user=jft1.getText();
String password=jft2.getText();

if(user.equals("javapgms")&&password.equals("lionel"))
{
Admin2 jf=new Admin2();
jf.setSize(400,300);
jf.setVisible(true);
}
else
JOptionPane.showMessageDialog(cont,"Invalid Details","Lionel's Message",

JOptionPane.ERROR_MESSAGE);
}
}

class Admin2 extends JFrame implements ActionListener,ItemListener
{
JComboBox jc;
JTextField ft1,ft2,ft3;
JButton B1;
String z,t;
Admin2()
{
Container cont=getContentPane();
cont.setLayout(null);

JLabel l1=new JLabel("Product:");
cont.add(l1);
l1.setBounds(20,30,100,20);

jc=new JComboBox();
jc.addItem("product1");
jc.addItem("product2");
jc.addItem("product3");
jc.addItem("product4");
jc.addItem("product5");
cont.add(jc);
jc.setBounds(80,30,200,20);
jc.addItemListener(this);

JLabel l2=new JLabel("Rate:");
cont.add(l2);
l2.setBounds(20,60,50,20);

ft1=new JTextField();
cont.add(ft1);
ft1.setEditable(false);
ft1.setBounds(80,60,50,20);

JLabel l3=new JLabel("Quantity:");
cont.add(l3);
l3.setBounds(20,90,100,20);

ft2=new JTextField();
cont.add(ft2);
ft2.setBounds(80,90,50,20);

B1=new JButton("Enter");
cont.add(B1);
B1.setBounds(150,150,100,30);
B1.addActionListener(this);
}

public void actionPerformed(ActionEvent ne)
{
String m=ft1.getText();
int a=Integer.parseInt(m);
String n=ft2.getText();
int b=Integer.parseInt(n);
z=jc.getSelectedItem().toString();

int tot=a*b;
t = String.valueOf(tot);

Admin3 admn3=new Admin3(z,m,n,t);
admn3.setSize(400,400);
admn3.setVisible(true);
}

public void itemStateChanged(ItemEvent me)
{
z=jc.getSelectedItem().toString();
if(z.equals("product1"))
ft1.setText("150");
else if(z.equals("product2"))
ft1.setText("250");
else if(z.equals("product3"))
ft1.setText("350");
else if(z.equals("product4"))
ft1.setText("450");
else if(z.equals("product5"))
ft1.setText("550");
}
}

class Admin3 extends JFrame implements ActionListener
{
JTextField ftf1,ftf2,ftf3,ftf0;
String x,y,z,q;
int l,m,n,tot1;
JMenuBar bar= new JMenuBar();
JMenuItem it1,it2;

Admin3(String l,String m,String n,String t)
{
Container cont=getContentPane();
cont.setLayout(null);

JMenu file = new JMenu ("File");
it1 = new JMenuItem("New");
it2 = new JMenuItem("Exit");
file.add(it1);
file.add(it2);

it1.addActionListener(this);
it2.addActionListener(this);

bar.add(file);
setJMenuBar(bar);

JLabel lb1=new JLabel("Product:");
cont.add(lb1);
lb1.setBounds(20,30,100,20);

ftf0=new JTextField();
ftf0.setEditable(false);
ftf0.setBounds(80,30,200,20);
cont.add(ftf0);
ftf0.setText(l);

JLabel lb2=new JLabel("Rate:");
cont.add(lb2);
lb2.setBounds(20,60,50,20);

ftf1=new JTextField();
cont.add(ftf1);
ftf1.setEditable(false);
ftf1.setBounds(80,60,50,20);
ftf1.setText(m);

JLabel lb3=new JLabel("Quantity:");
cont.add(lb3);
lb3.setBounds(20,90,100,20);

ftf2=new JTextField();
cont.add(ftf2);
ftf2.setEditable(false);
ftf2.setBounds(80,90,50,20);
ftf2.setText(n);

JLabel lb4=new JLabel("Total Amt");
cont.add(lb4);
lb4.setBounds(20,120,100,20);

ftf3=new JTextField();
cont.add(ftf3);
ftf3.setEditable(false);
ftf3.setBounds(80,120,100,20);
ftf3.setText(t);
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==it1)
{
Admin admn=new Admin();
admn.setSize(400,400);
admn.setVisible(true);
}

if(ae.getSource()==it2)
System.exit(0);
}
}

/* Kindly leave your useful comments or suggesstin if any. */

Java Program To Display a Simple Tree

/* Java Program To Display A simple tree with root node as ENGINEERING and the courses under it as sub nodes or leaves. The program makes use of Frames. The Normal way of defining a tree node is 'DefaultMutableTreeNode root_name =new DefaultMutableTreeNode (argument_name)'.*/


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

public class Tree1 extends JFrame
{
public static void main(String args[])
{
Tree1 frame = new Tree1(" A Tree");
frame.setSize(200,200);
frame.setVisible(true);
}
public Tree1(String title)
{
setTitle(title);
DefaultMutableTreeNode root=new DefaultMutableTreeNode ("Engineering");
DefaultMutableTreeNode style=new DefaultMutableTreeNode ("Information Technology");
root.add(style);
style=new DefaultMutableTreeNode("Electronics");
root.add(style);
style=new DefaultMutableTreeNode ("Computer Science");
root.add(style);
style=new DefaultMutableTreeNode ("Mechanical");
root.add(style);
style=new DefaultMutableTreeNode ("Electrical");
root.add(style);
style=new DefaultMutableTreeNode ("Sound");
root.add(style);

JTree jt=new JTree(root);
Container contentPane=getContentPane();
contentPane.add(new JScrollPane(jt));
}
}

Java Program To Display A Human Face - Graphics

/*Program Displaying the human face suing basic figures, circles, arcs, lines, etc. Done using Applets.

/* < applet code = "Face" width = 500 height =500>
< /applet> */

import java.awt.*;
import java.applet.*;

public class Face extends Applet
{
public void paint(Graphics g)
{
g.drawString("Hi !!!!!!!!!!!!!!! I Am Ninad.",20,30);

g.drawArc(30,50,200,200,0,360); // Main Face
g.drawArc(82,80,30,30,20,160); //Left Eye Brow
g.fillArc(85,85,25,25,0,360); //Left Eye
g.drawArc(152,80,30,30,20,160); //Right Eye Brow
g.fillArc(155,85,25,25,0,360); //Right Eye
g.drawRect(90,190,80,20); //Mouth

g.drawLine(130,135,115,160); //Nose Left Line
g.drawLine(130,135,145,160); // Nose Right Line
g.drawLine(115,160,145,160); // Nose Base

g.drawString(" ------------- Created By Lionel.",10,350);
}
}