import javax.swing.JFrame;
import javax.swing.JButton;
import java.awt.CardLayout;
import java.awt.Container;
import java.awt.Toolkit;
import java.awt.Dimension;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
class cardlayout implements ActionListener
{
static CardLayout cl;
static JFrame jf;
static JButton[] jb = new JButton[5];
static Container ct;
public static void main(String args[])
{
/* JFrame Object instansiated */
jf=new JFrame("Maulin");
/* toolkit to get screen size */
Toolkit tk=jf.getToolkit();
Dimension dm=tk.getScreenSize();
jf.setBounds(dm.width/4,dm.width/4,dm.height/2,dm.height/2);
/* Card Layout instansiated*/
cl=new CardLayout(50,50);
/*get contentpane of JFrame which return Container */
Container ct=jf.getContentPane();
/* set Card Layout for Container */
ct.setLayout(cl);
for(int i=0;i<5;i++)
{
jb[i]=new JButton("Maulin"+i);
jb[i].addActionListener(new cardlayout());
}
for(int i=0;i<5;i++)
{
/*Adding Button to Container(JFrame)*/
ct.add(jb[i],"Maulin"+i);
}
/*First Card Display on Screen :) First Button display*/
cl.show(jf.getContentPane(),"Maulin"+2);
jf.setVisible(true);
/*Destroy the Frame*/
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent e)
{
cl.next(jf.getContentPane());
}
}
Note : This Blog Has No Concerns With Any Of The College Institute.
Developed & Maintained By RAJ SAHIN N.
...::: Recent Updates :::...
Tuesday, September 27, 2011
Friday, September 23, 2011
Develop an application which is having one rectangle and three textboxes of Red, Green, and Blue (i.e. RGB). As the value of RGB Textbox changing the fill color of rectangle should change.
------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------
JAVA APPLET PROGRAM
RBG Program
------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------
Develop an application which is having one rectangle and three textboxes of Red, Green, and Blue (i.e. RGB). As the value of RGB Textbox changing the fill color of rectangle should change.
------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------
NAME : SAHIN NISAR RAJ
ENROLL : 105200693009
COLLEGE : LAXMI INSTITUTE OF COMPUTER APPLICATIONS
ENROLL : 105200693009
COLLEGE : LAXMI INSTITUTE OF COMPUTER APPLICATIONS
------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------
package session9;
import java.applet.Applet;
import java.awt.Button;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Label;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javax.swing.JOptionPane;
public class S9Q5 extends Applet implements KeyListener,ActionListener
{
int vred = 20;
int vgreen = 30;
int vblue = 40;
TextField red;
TextField green;
TextField blue;
Label lbred;
Label lbgreen;
Label lbblue;
Button Change;
@Override
public void init()
{
setLayout(null);
red = new TextField(20);
green = new TextField(20);
blue = new TextField(20);
lbred = new Label("Red :");
lbgreen = new Label("Green :");
lbblue = new Label("Blue :");
Change = new Button("Change");
add(red);
red.setBackground(Color.red);
add(green);
green.setBackground(Color.green);
add(blue);
blue.setBackground(Color.blue);
add(lbred);
lbred.setBackground(Color.gray);
lbred.setForeground(Color.white);
add(lbgreen);
lbgreen.setBackground(Color.gray);
lbgreen.setForeground(Color.white);
add(lbblue);
lbblue.setBackground(Color.gray);
lbblue.setForeground(Color.white);
add(Change);
red.setBounds(230,30,100,20);
green.setBounds(230,50,100,20);
blue.setBounds(230,70,100,20);
lbred.setBounds(180,30,100,20);
lbgreen.setBounds(180,50,100,20);
lbblue.setBounds(180,70,100,20);
Change.setBounds(180,100, 150, 30);
red.addKeyListener(this);
green.addKeyListener(this);
blue.addKeyListener(this);
Change.addActionListener(this);
setBackground(Color.GRAY);
}
@Override
public void paint(Graphics g)
{
try
{
Color c = new Color(vred,vgreen,vblue);
g.setColor(c);
g.fillRect(20, 20,130,100);
g.drawString("* Range Must be Between 0 - 255", 90, 180);
} catch (Exception e)
{
JOptionPane.showMessageDialog(null,e.getMessage());
}
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource() == Change)
{
this.vblue = Integer.parseInt(blue.getText().toString());
this.vgreen = Integer.parseInt(green.getText().toString());
this.vred = Integer.parseInt(red.getText().toString());
repaint();
}
}
}
import java.applet.Applet;
import java.awt.Button;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Label;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javax.swing.JOptionPane;
public class S9Q5 extends Applet implements KeyListener,ActionListener
{
int vred = 20;
int vgreen = 30;
int vblue = 40;
TextField red;
TextField green;
TextField blue;
Label lbred;
Label lbgreen;
Label lbblue;
Button Change;
@Override
public void init()
{
setLayout(null);
red = new TextField(20);
green = new TextField(20);
blue = new TextField(20);
lbred = new Label("Red :");
lbgreen = new Label("Green :");
lbblue = new Label("Blue :");
Change = new Button("Change");
add(red);
red.setBackground(Color.red);
add(green);
green.setBackground(Color.green);
add(blue);
blue.setBackground(Color.blue);
add(lbred);
lbred.setBackground(Color.gray);
lbred.setForeground(Color.white);
add(lbgreen);
lbgreen.setBackground(Color.gray);
lbgreen.setForeground(Color.white);
add(lbblue);
lbblue.setBackground(Color.gray);
lbblue.setForeground(Color.white);
add(Change);
red.setBounds(230,30,100,20);
green.setBounds(230,50,100,20);
blue.setBounds(230,70,100,20);
lbred.setBounds(180,30,100,20);
lbgreen.setBounds(180,50,100,20);
lbblue.setBounds(180,70,100,20);
Change.setBounds(180,100, 150, 30);
red.addKeyListener(this);
green.addKeyListener(this);
blue.addKeyListener(this);
Change.addActionListener(this);
setBackground(Color.GRAY);
}
@Override
public void paint(Graphics g)
{
try
{
Color c = new Color(vred,vgreen,vblue);
g.setColor(c);
g.fillRect(20, 20,130,100);
g.drawString("* Range Must be Between 0 - 255", 90, 180);
} catch (Exception e)
{
JOptionPane.showMessageDialog(null,e.getMessage());
}
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource() == Change)
{
this.vblue = Integer.parseInt(blue.getText().toString());
this.vgreen = Integer.parseInt(green.getText().toString());
this.vred = Integer.parseInt(red.getText().toString());
repaint();
}
}
}
Sunday, September 18, 2011
Mod Convertor Java Applets
------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------
JAVA APPLET PROGRAM
( Mod Converter )
------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------
2. Create applet for Mod Convertor which converts from different bases to base 10.
------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------
NAME : SAHIN NISAR RAJ
ENROLL : 105200693009
COLLEGE : LAXMI INSTITUTE OF COMPUTER APPLICATIONS
ENROLL : 105200693009
COLLEGE : LAXMI INSTITUTE OF COMPUTER APPLICATIONS
------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------
package session9;
//Create applet for Mod Convertor which converts from different bases to base 10.
import java.applet.Applet;
import java.awt.Button;
import java.awt.Color;
import java.awt.Label;
import java.awt.TextArea;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javax.swing.JOptionPane;
public class S9Q3 extends Applet implements ActionListener,KeyListener
{
Button Convert;
Label lb_Num;
Label lb_Base;
Label devl;
Button Clear;
TextField Num,Base;
TextArea Res;
int i=0;
@Override
public void init()
{
setSize(210,300);
setBackground(Color.LIGHT_GRAY);
Convert = new Button("Convert");
Clear = new Button("Clear");
lb_Num = new Label("Number");
lb_Base = new Label("Base");
devl = new Label("Developed By : RAJ SAHIN N.");
Num = new TextField(20);
Base = new TextField(20);
Res = new TextArea(3,25);
add(lb_Num);
add(Num);
add(lb_Base);
add(Base);
add(Convert);
add(Clear);
add(Res);
add(devl);
Convert.setBackground(Color.white);
Clear.setBackground(Color.white);
Convert.addActionListener(this);
Clear.addActionListener(this);
devl.setForeground(Color.red);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource() == Convert)
{
try
{
int oprand,div= 0;
StringBuffer res;
oprand = Integer.parseInt(Num.getText());
div = Integer.parseInt(Base.getText());
res = Calculation(oprand,div);
Res.setText("00"+res.reverse().toString());
} catch (Exception ex)
{
JOptionPane.showMessageDialog(this,"Please Enter Valid Input Values");
}
}
if(e.getSource() == Clear)
{
Num.setText("");
Base.setText("");
Res.setText("");
}
}
public StringBuffer Calculation(int operand,int div)
{
StringBuffer trans = new StringBuffer();
do
{
trans.append(operand % div);
operand = operand / div;
this.i++;
}while(operand != 0);
return trans;
}
}
//Create applet for Mod Convertor which converts from different bases to base 10.
import java.applet.Applet;
import java.awt.Button;
import java.awt.Color;
import java.awt.Label;
import java.awt.TextArea;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javax.swing.JOptionPane;
public class S9Q3 extends Applet implements ActionListener,KeyListener
{
Button Convert;
Label lb_Num;
Label lb_Base;
Label devl;
Button Clear;
TextField Num,Base;
TextArea Res;
int i=0;
@Override
public void init()
{
setSize(210,300);
setBackground(Color.LIGHT_GRAY);
Convert = new Button("Convert");
Clear = new Button("Clear");
lb_Num = new Label("Number");
lb_Base = new Label("Base");
devl = new Label("Developed By : RAJ SAHIN N.");
Num = new TextField(20);
Base = new TextField(20);
Res = new TextArea(3,25);
add(lb_Num);
add(Num);
add(lb_Base);
add(Base);
add(Convert);
add(Clear);
add(Res);
add(devl);
Convert.setBackground(Color.white);
Clear.setBackground(Color.white);
Convert.addActionListener(this);
Clear.addActionListener(this);
devl.setForeground(Color.red);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource() == Convert)
{
try
{
int oprand,div= 0;
StringBuffer res;
oprand = Integer.parseInt(Num.getText());
div = Integer.parseInt(Base.getText());
res = Calculation(oprand,div);
Res.setText("00"+res.reverse().toString());
} catch (Exception ex)
{
JOptionPane.showMessageDialog(this,"Please Enter Valid Input Values");
}
}
if(e.getSource() == Clear)
{
Num.setText("");
Base.setText("");
Res.setText("");
}
}
public StringBuffer Calculation(int operand,int div)
{
StringBuffer trans = new StringBuffer();
do
{
trans.append(operand % div);
operand = operand / div;
this.i++;
}while(operand != 0);
return trans;
}
}
------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------
Java Program Which Show a Rectangle That Will Change Color When The Mouse Moves Over It.
------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------
JAVA APPLET PROGRAM
------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------
2. Write a java program to create applet which will show a rectangle that will change color when the mouse moves over it.
------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------
NAME : SAHIN NISAR RAJ
ENROLL : 105200693009
COLLEGE : LAXMI INSTITUTE OF COMPUTER APPLICATIONS
ENROLL : 105200693009
COLLEGE : LAXMI INSTITUTE OF COMPUTER APPLICATIONS
------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------
import java.applet.Applet;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;
public class S9Q2 extends Applet implements ActionListener,KeyListener,MouseMotionListener
{
int rectx;
int recty;
int rectwidth;
int rectheight;
int mx,my,mw,mh;
@Override
public void init()
{
rectx = 20;
recty = 20;
rectwidth = 200;
rectheight = 100;
addMouseMotionListener(this);
}
public void paint(Graphics g)
{
if((mx>rectx && my>recty) && (mx<rectx+rectwidth && my<recty+rectheight))
{
g.setColor(Color.MAGENTA);
g.fillRect(rectx,recty,rectwidth,rectheight);
}
else
{
g.setColor(Color.red);
g.fillRect(rectx,recty,rectwidth,rectheight);
}
}
public void mouseMoved(MouseEvent e)
{
mx = e.getX();
my = e.getY();
repaint();
}
}
{
int rectx;
int recty;
int rectwidth;
int rectheight;
int mx,my,mw,mh;
@Override
public void init()
{
rectx = 20;
recty = 20;
rectwidth = 200;
rectheight = 100;
addMouseMotionListener(this);
}
public void paint(Graphics g)
{
if((mx>rectx && my>recty) && (mx<rectx+rectwidth && my<recty+rectheight))
{
g.setColor(Color.MAGENTA);
g.fillRect(rectx,recty,rectwidth,rectheight);
}
else
{
g.setColor(Color.red);
g.fillRect(rectx,recty,rectwidth,rectheight);
}
}
public void mouseMoved(MouseEvent e)
{
mx = e.getX();
my = e.getY();
repaint();
}
}
------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------
Download Source : Click Here...
------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------
Tuesday, September 13, 2011
Threading in JAVA
------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------
THREADING IN JAVA
------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------
Q Create two Thread subclasses, one with a run( ) that starts up and then calls wait( ). The other class’ run( ) should capture the reference of the first Thread object. Its run( ) should call notifyAll( ) for the first thread after some number of seconds have passed, so the first thread can print a message.
------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------
NAME : SAHIN NISAR RAJ
ENROLL : 105200693009
COLLEGE : LAXMI INSTITUTE OF COMPUTER APPLICATIONS
ENROLL : 105200693009
COLLEGE : LAXMI INSTITUTE OF COMPUTER APPLICATIONS
------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------
package session8threads;class Thread1 implements Runnable
{
Thread thrd1;
Thread1()
{
thrd1 = new Thread(this,"Thread One");
thrd1.start();
}
public void run()
{
try
{
System.out.println("Thread First Started");
synchronized(this)
{
System.out.println("Thread First Entering into Wait State");
this.wait(20000);
System.out.println("Thread First Resumed after Notify");
}
} catch (Exception e)
{
System.out.println("Exception in First Thread" +e.getMessage());
}
}
}
class Thread2 implements Runnable
{
Thread thrd2;
Thread1 temp;
Thread2(Thread1 th)
{
thrd2 = new Thread(this,"Thread Two");
temp = th;
thrd2.start();
}
public void run()
{
try
{
System.out.println("Thread Two Started");
synchronized(temp)
{
System.out.println("Thread Two Notified Thread First");
temp.notify();
}
} catch (Exception e)
{
System.out.println("Exception in Second Thread" +e.getMessage());
}
}
}
public class Main
{
public static void main(String[] args)
{
Thread1 thrd1 = new Thread1();
Thread2 thrd2 = new Thread2(thrd1);
}
}
Sunday, September 11, 2011
FileHandling With StatisticalData In JAVA.
------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------
A college maintains the information about the marks of the students of a class in a text file with fixed record length. Each line in the file contains data of one student. The first 15 characters have the name of the student, next 12 characters have marks in the four subjects, and each subject has 3 characters. Create a class called StudentMarks, which has student Name, and marks for four subjects. Provide appropriate getter methods and constructors, for this class. Write an application class to load the file into an array of Student Marks. Use the StatisticalData class to compute the statistics mean, median for each of the subjects in the class.------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------
NAME : SAHIN NISAR RAJ
ENROLL : 105200693009
COLLEGE : LAXMI INSTITUTE OF COMPUTER APPLICATIONS
ENROLL : 105200693009
COLLEGE : LAXMI INSTITUTE OF COMPUTER APPLICATIONS
Thanks Sir For Helping
Manjoor Hussain Kapoor
------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------
Main.java
------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------
package filehandling;import java.util.ArrayList;
public class Main
{
public static void main(String[] args)
{
ArrayList<String> MyArr;
ArrayList<String> Name;
ArrayList<String> Java;
ArrayList<String> OS;
ArrayList<String> SS;
ArrayList<String> SM;
ArrayList<Float> Mean;
ArrayList<Float> Median;
new WriteFile("FileHandling.txt").WriteToFile();
MyArr = new ReadFile("FileHandling.txt").ReadFromFile();
Name = new ArrayList<String>();
Java = new ArrayList<String>();
OS = new ArrayList<String>();
SS = new ArrayList<String>();
SM = new ArrayList<String>();
Mean = new ArrayList<Float>();
Median = new ArrayList<Float>();
for(int i=0;i<MyArr.size();i++)
{
Name.add(MyArr.get(i).substring(0,15));
Java.add(MyArr.get(i).substring(15,18));
OS.add(MyArr.get(i).substring(18,21));
SS.add(MyArr.get(i).substring(21,24));
SM.add(MyArr.get(i).substring(24));
}
Mean.add(mean(Java));
Mean.add(mean(OS));
Mean.add(mean(SS));
Mean.add(mean(SM));
Median.add(median(Java));
Median.add(median(OS));
Median.add(median(SS));
Median.add(median(SM));
DisplayMean(Mean);
DisplayMedian(Median);
}
public static float mean(ArrayList<String> sub)
{
float mean,total = 0;
for(int i=0;i<sub.size();i++)
{
total = total + Integer.parseInt(sub.get(i).trim());
}
mean = total/sub.size();
return mean;
}
public static float median(ArrayList<String> sub)
{
float median = 0;
int tmp=((sub.size()+1)/2);
if(sub.size()%2==0)
{
median= (Float.parseFloat(sub.get(tmp-1)) + Float.parseFloat(sub.get(tmp)))/2;
}
else
{
median=Float.parseFloat(sub.get(tmp));
}
return median;
}
public static void DisplayMean(ArrayList<Float> Mean)
{
System.out.println("Mean Of All Subject");
System.out.println("JAVA "+Mean.get(0));
System.out.println("OS "+Mean.get(1));
System.out.println("SS "+Mean.get(2));
System.out.println("SM "+Mean.get(3));
}
public static void DisplayMedian(ArrayList<Float> Median)
{
System.out.println("Median Of All Subject");
System.out.println("JAVA "+Median.get(0));
System.out.println("OS "+Median.get(1));
System.out.println("SS "+Median.get(2));
System.out.println("SM "+Median.get(3));
}
}
public class Main
{
public static void main(String[] args)
{
ArrayList<String> MyArr;
ArrayList<String> Name;
ArrayList<String> Java;
ArrayList<String> OS;
ArrayList<String> SS;
ArrayList<String> SM;
ArrayList<Float> Mean;
ArrayList<Float> Median;
new WriteFile("FileHandling.txt").WriteToFile();
MyArr = new ReadFile("FileHandling.txt").ReadFromFile();
Name = new ArrayList<String>();
Java = new ArrayList<String>();
OS = new ArrayList<String>();
SS = new ArrayList<String>();
SM = new ArrayList<String>();
Mean = new ArrayList<Float>();
Median = new ArrayList<Float>();
for(int i=0;i<MyArr.size();i++)
{
Name.add(MyArr.get(i).substring(0,15));
Java.add(MyArr.get(i).substring(15,18));
OS.add(MyArr.get(i).substring(18,21));
SS.add(MyArr.get(i).substring(21,24));
SM.add(MyArr.get(i).substring(24));
}
Mean.add(mean(Java));
Mean.add(mean(OS));
Mean.add(mean(SS));
Mean.add(mean(SM));
Median.add(median(Java));
Median.add(median(OS));
Median.add(median(SS));
Median.add(median(SM));
DisplayMean(Mean);
DisplayMedian(Median);
}
public static float mean(ArrayList<String> sub)
{
float mean,total = 0;
for(int i=0;i<sub.size();i++)
{
total = total + Integer.parseInt(sub.get(i).trim());
}
mean = total/sub.size();
return mean;
}
public static float median(ArrayList<String> sub)
{
float median = 0;
int tmp=((sub.size()+1)/2);
if(sub.size()%2==0)
{
median= (Float.parseFloat(sub.get(tmp-1)) + Float.parseFloat(sub.get(tmp)))/2;
}
else
{
median=Float.parseFloat(sub.get(tmp));
}
return median;
}
public static void DisplayMean(ArrayList<Float> Mean)
{
System.out.println("Mean Of All Subject");
System.out.println("JAVA "+Mean.get(0));
System.out.println("OS "+Mean.get(1));
System.out.println("SS "+Mean.get(2));
System.out.println("SM "+Mean.get(3));
}
public static void DisplayMedian(ArrayList<Float> Median)
{
System.out.println("Median Of All Subject");
System.out.println("JAVA "+Median.get(0));
System.out.println("OS "+Median.get(1));
System.out.println("SS "+Median.get(2));
System.out.println("SM "+Median.get(3));
}
}
------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------
ReadFile.java
------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------
package filehandling;
import java.io.FileInputStream;
import java.util.ArrayList;
import java.util.Scanner;
public class ReadFile
{
FileInputStream fip;
Scanner sc;
String FileName;
ArrayList<String> MyArr;
int i=0;
ReadFile(String FileName)
{
this.FileName = FileName;
}
public ArrayList ReadFromFile()
{
try
{
fip = new FileInputStream(FileName);
sc = new Scanner(fip);
MyArr = new ArrayList<String>();
while(sc.hasNextLine())
{
String Str = sc.nextLine();
MyArr.add(Str);
Str = null;
}
} catch (Exception ex)
{
System.out.println("Exception in ReadFromFile : " + ex.getMessage());
}
return MyArr;
}
}
import java.io.FileInputStream;
import java.util.ArrayList;
import java.util.Scanner;
public class ReadFile
{
FileInputStream fip;
Scanner sc;
String FileName;
ArrayList<String> MyArr;
int i=0;
ReadFile(String FileName)
{
this.FileName = FileName;
}
public ArrayList ReadFromFile()
{
try
{
fip = new FileInputStream(FileName);
sc = new Scanner(fip);
MyArr = new ArrayList<String>();
while(sc.hasNextLine())
{
String Str = sc.nextLine();
MyArr.add(Str);
Str = null;
}
} catch (Exception ex)
{
System.out.println("Exception in ReadFromFile : " + ex.getMessage());
}
return MyArr;
}
}
------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------
WriteFile.java
------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------
package filehandling;import java.io.FileOutputStream;
public class WriteFile
{
FileOutputStream fop;
String FileName;
WriteFile(String FileName)
{
this.FileName = FileName;
}
public void WriteToFile()
{
try
{
fop = new FileOutputStream(FileName);
fop.write("SAHIN 90 87 65 78 \n".getBytes());
fop.write("RAJ 80 69 54 67 \n".getBytes());
fop.write("KAUSHAL 62 37 52 65 \n".getBytes());
fop.write("BHUMIKA 74 39 81 57 \n".getBytes());
fop.write("VIKAS 56 61 91 48 \n".getBytes());
fop.close();
} catch (Exception ex)
{
System.out.println("Exception in WriteToFile : " +ex.getMessage());
}
}
}
public class WriteFile
{
FileOutputStream fop;
String FileName;
WriteFile(String FileName)
{
this.FileName = FileName;
}
public void WriteToFile()
{
try
{
fop = new FileOutputStream(FileName);
fop.write("SAHIN 90 87 65 78 \n".getBytes());
fop.write("RAJ 80 69 54 67 \n".getBytes());
fop.write("KAUSHAL 62 37 52 65 \n".getBytes());
fop.write("BHUMIKA 74 39 81 57 \n".getBytes());
fop.write("VIKAS 56 61 91 48 \n".getBytes());
fop.close();
} catch (Exception ex)
{
System.out.println("Exception in WriteToFile : " +ex.getMessage());
}
}
}
------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------
Download Full Program : Click Here
------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------
Thanks For Help
Manjoor Hussain Kapoor
Manjoor Hussain Kapoor
------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------
Sunday, September 4, 2011
Filter File in java (display only a*.java) files
import java.io.FilenameFilter;
import java.io.File;
class filterfilelist implements FilenameFilter
{
String FileName;
String Extention;
String startwith;
String endswith;
String inbetween_startwith,inbetween_endswith;
filterfilelist(String tmp)
{
FileName=tmp.substring(0,(tmp.indexOf('.')));
System.out.println("Name:-"+FileName);
Extention=tmp.substring((tmp.indexOf('.')+1));
System.out.println("Extension:-"+Extention);
}
public boolean accept(File dir,String file)
{
boolean m=true;
String f1=" ";
/* If Star Place At First Place *a.java */
int len=FileName.length()-1;
if(FileName.indexOf('*')==0)
{
startwith=FileName.substring((FileName.indexOf('*')+1));
if(file.indexOf('.')!= -1)
{
f1=file.substring(0,(file.indexOf('.')));
}
m = f1.endsWith(startwith) && file.endsWith(Extention);
}/* a*.java */
if(FileName.indexOf('*')==len)
{
endswith=FileName.substring(0,(FileName.indexOf('*')));
m = file.startsWith(endswith) && file.endsWith(Extention);
}
/* else a*b.java Still remain
{
inbetween_startwith=FileName.substring(0,(FileName.indexOf('*')));
inbetween_endswith=FileName.substring((FileName.indexOf('*')+1));
m =file.startsWith(inbetween_endswith) & file.endsWith(inbetween_startwith) & file.endsWith(Extention);
}*/
return m;
}
}
import java.io.File;
class filterfilelist implements FilenameFilter
{
String FileName;
String Extention;
String startwith;
String endswith;
String inbetween_startwith,inbetween_endswith;
filterfilelist(String tmp)
{
FileName=tmp.substring(0,(tmp.indexOf('.')));
System.out.println("Name:-"+FileName);
Extention=tmp.substring((tmp.indexOf('.')+1));
System.out.println("Extension:-"+Extention);
}
public boolean accept(File dir,String file)
{
boolean m=true;
String f1=" ";
/* If Star Place At First Place *a.java */
int len=FileName.length()-1;
if(FileName.indexOf('*')==0)
{
startwith=FileName.substring((FileName.indexOf('*')+1));
if(file.indexOf('.')!= -1)
{
f1=file.substring(0,(file.indexOf('.')));
}
m = f1.endsWith(startwith) && file.endsWith(Extention);
}/* a*.java */
if(FileName.indexOf('*')==len)
{
endswith=FileName.substring(0,(FileName.indexOf('*')));
m = file.startsWith(endswith) && file.endsWith(Extention);
}
/* else a*b.java Still remain
{
inbetween_startwith=FileName.substring(0,(FileName.indexOf('*')));
inbetween_endswith=FileName.substring((FileName.indexOf('*')+1));
m =file.startsWith(inbetween_endswith) & file.endsWith(inbetween_startwith) & file.endsWith(Extention);
}*/
return m;
}
}
Subscribe to:
Posts (Atom)