Sunday, June 19, 2016

Lab Programs

import java.io.*; class AppendFile { public static void main(String[] args) { try { FileOutputStream out = new FileOutputStream(new File("new.txt"), true); String str = "There is always a way-if you're committed.\n"; //while(){ out.write(str.getBytes()); //} out.close(); System.out.println("String is appended."); } catch (IOException e) { } } }/* ----------------------------------------------------------------------------- (#)Vowels file.java (#)5 aug (#) */ // importing packages import java.io.FileReader; import java.io.BufferedReader; public class lab$1{ public static void main(String args[])throws Exception{ System.out.println("vowels program"); FileReader fr= new FileReader("lab$1.java"); BufferedReader br= new BufferedReader(fr); int c; int count=0; while((c=br.read())!=-1){ char temp=(char)c; System.out.println(temp); if(temp=='a'){ count++; } else if(temp=='e'){ count++; } else if(temp=='i'){ count++; } else if(temp=='o'){ count++; } else if(temp=='u'){ count++; } } System.out.println("the number of vowels present in the system is...."+count); } } ------------------------------------------------------------------------------------------- /* (#)Raf.java (#)5 aug 2011 (#) */ //importing packages import java.io.RandomAccessFile; public class lab$2{ public static void main(String args[])throws Exception{ System.out.println("random file"); RandomAccessFile rf= new RandomAccessFile("lab$2.java","r"); rf.seek(250); int c; StringBuffer sb= new StringBuffer(); for(int i=0;i<100;i++) { char temp=(char)rf.readByte(); sb=sb.append(temp); //System.out.println(temp); } System.out.println("\n\n\n"+sb); System.out.println("\n\nsize of the buffer: "+ sb.length()); } } --------------------------------------------------------------------------------- /* (#)copy file (#)5 aug 2011 (#) */ //importing packages import java.io.FileInputStream; import java.io.FileOutputStream; public class lab$3{ public static void main(String args[])throws Exception{ System.out.println("copy file"); FileInputStream in = new FileInputStream("lab$3.java"); FileOutputStream out = new FileOutputStream("temp.txt"); int c; while((c=in.read())!=-1){ System.out.println((char)c); out.write(c); } } } ---------------------------------------------------------------------------------------------------------- /* (#)employee file.java (#)5 aug 2011 */ //importing packages import java.io.FileReader; import java.io.BufferedReader; import java.io.FileWriter; import java.io.PrintWriter; import java.io.File; import java.util.Scanner; public class lab$4{ public static void main(String args[])throws Exception{ System.out.println("employee record"); String[] s={"anand male","siva male","banu female","ram male","guru male","latha female","mala female","geetha female","selvam male","ragu male"}; String memp[]= new String[10]; String femp[]= new String[10]; File f= new File("employee.txt"); f.createNewFile(); FileReader fr= new FileReader(f); BufferedReader br = new BufferedReader(fr); //Scanner in= new Scanner(fr); FileWriter fw= new FileWriter("employee.txt"); PrintWriter pw= new PrintWriter(fw); int fc=0; int mc=0; for(int i=0;i<10;i++){ //System.out.println(s[i]); pw.println(s[i]); } pw.flush(); pw.close(); String temp; while((temp=br.readLine())!=null){ if((temp.indexOf("female"))!=-1){ femp[fc]=temp; //System.out.println(temp); fc++; } else{ memp[mc]=temp; //System.out.println(temp); mc++; } } System.out.println("\n\n\nMale employees"); for(int i=0;i<mc;i++){ System.out.println(memp[i]); } System.out.println("\n\n\nFemale employees"); for(int i=0;i<fc;i++){ System.out.println(femp[i]); } /*while(in.hasNextLine()){ System.out.println(in.nextLine()); }*/ } } ---------------------------------------------------------------------------------------- /* (#)employee file.java (#)5 aug 2011 */ //importing packages import java.io.FileReader; import java.io.BufferedReader; import java.io.FileWriter; import java.io.PrintWriter; import java.io.File; import java.util.StringTokenizer; public class lab$5{ public static void main(String args[])throws Exception{ System.out.println("employee record"); String[] s={"anand 20000 mgr","siva 2000 clrk","banu 10000 prog"}; File f= new File("employee.txt"); File f1= new File("nemployee.txt"); File f2= new File("above10k.txt"); File f3= new File("below10k.txt"); f.createNewFile(); f1.createNewFile(); f2.createNewFile(); f3.createNewFile(); FileReader fr= new FileReader(f); FileReader fr1= new FileReader(f1); FileReader fr2= new FileReader(f2); FileReader fr3= new FileReader(f3); BufferedReader br = new BufferedReader(fr); BufferedReader br1 = new BufferedReader(fr1); BufferedReader br2 = new BufferedReader(fr2); BufferedReader br3 = new BufferedReader(fr3); FileWriter fw= new FileWriter("employee.txt"); FileWriter fw1= new FileWriter("nemployee.txt"); FileWriter fw2= new FileWriter("above10k.txt"); FileWriter fw3= new FileWriter("below10k.txt"); PrintWriter pw= new PrintWriter(fw); PrintWriter pw1= new PrintWriter(fw1); PrintWriter pw2= new PrintWriter(fw2); PrintWriter pw3= new PrintWriter(fw3); for(int i=0;i<3;i++){ //System.out.println(s[i]); pw.println(s[i]); } pw.flush(); String ename[]= new String[5]; String ecat[]= new String[5]; String ebpay[]= new String[5]; String egpay[]= new String[5]; String enetpay[]= new String[5]; String eallow[]= new String[5]; String edet[]= new String[5]; String temp; int i=0; StringTokenizer st= null; while((temp=br.readLine())!=null){ //System.out.println(temp); st= new StringTokenizer(temp); while(st.hasMoreTokens()){ ename[i]=st.nextToken(); ebpay[i]=st.nextToken(); ecat[i]=st.nextToken(); if(ecat[i].equals("mgr")){ eallow[i]="1000"; int t1,t2,t3; t1=Integer.parseInt(ebpay[i]); t2=Integer.parseInt(eallow[i]); t3=t1+t2; egpay[i]=egpay[i].valueOf(t3); double d; d=t1*0.1; edet[i]=edet[i].valueOf(d); d=(double)t3-d; enetpay[i]=enetpay[i].valueOf(d); } else if(ecat[i].equals("clrk")){ eallow[i]="500"; int t1,t2,t3; t1=Integer.parseInt(ebpay[i]); t2=Integer.parseInt(eallow[i]); t3=t1+t2; egpay[i]=egpay[i].valueOf(t3); double d; d=t1*0.1; edet[i]=edet[i].valueOf(d); d=(double)t3-d; enetpay[i]=enetpay[i].valueOf(d); } else if(ecat[i].equals("prog")){ eallow[i]="100"; int t1,t2,t3; t1=Integer.parseInt(ebpay[i]); t2=Integer.parseInt(eallow[i]); t3=t1+t2; egpay[i]=egpay[i].valueOf(t3); double d; d=t1*0.1; edet[i]=edet[i].valueOf(d); d=(double)t3-d; enetpay[i]=enetpay[i].valueOf(d); } } i++; } String temp1; for(int j=0;j<3;j++){ temp1=ename[j]+" "+ebpay[j]+" "+egpay[j]+" "+enetpay[j]+" "+edet[j]+" "+eallow[j]; pw1.println(temp1); System.out.println("b: "+ebpay[j]); System.out.println("g: "+egpay[j]); System.out.println("d: "+edet[j]); System.out.println("a: "+eallow[j]); System.out.println("n: "+enetpay[j]); double tvar; tvar=Double.parseDouble(enetpay[j]); if(tvar>10000){ pw2.println(temp1); } else{ pw3.println(temp1); } } pw1.flush(); pw2.flush(); pw3.flush(); } } ------------------------------------------------------------------- import java.lang.String; public class lab$6{ public static void main(String args[])throws Exception{ System.out.println("util package"); String s="E - EXPERT SOLUTIONS"; System.out.println("String: "+s); System.out.println("\n\ns.charAt(5): "+s.charAt(5)); System.out.println("\n\ns.indexOf('T'): "+s.indexOf("T")); String name= "OFFICE DEPOT, COIMBATORE 641002"; System.out.println("\n\nString : "+name+"\n\nname.substring(7,12): "+name.substring(7,12)+"\n\nname.substring(14,24): "+name.substring(14,24)+"\n\nname.substring(25) : "+name.substring(25)); String bomb="Bomb blast"; System.out.println("\n\nstring: "+bomb); System.out.println("\n\nbomb.replace('B','C'): "+bomb.replace('B','C')); System.out.println("\n\nbomb.replace('o','a'): "+bomb.replace('o','a')); String st="feature lies in ecommerce"; int begin=7; int end=11; char[] buffer= new char[end-begin]; //line.getChars(begin,end,buffer,0); //System.out.println(buffer); String a="jini"; String A= "JINI"; System.out.println(a.equals(A)); System.out.println(a.equalsIgnoreCase(A)); int pincode=1234; StringBuffer sb= new StringBuffer(30); String s3; s3= sb.append("pincode: ").append(pincode).toString(); System.out.println(s3); StringBuffer sb4= new StringBuffer("software park " ); sb4.insert(9,"techno"); System.out.println(sb4); } } ------------------------------------------------------------------------------------ import java.util.StringTokenizer; public class lab$7{ public static void main(String args[])throws Exception{ StringTokenizer st= new StringTokenizer("abc xyz blah blah"); String temp[]= new String[10]; int i=0; while(st.hasMoreTokens()){ String t; temp[i]= new StringBuffer(st.nextToken()).reverse().toString(); i++; } for(int j=0;j<i;j++) { System.out.println(temp[j]); } } } -------------------------------------------------------------------------------------------------- import java.io.BufferedReader; import java.util.Scanner; import java.io.InputStreamReader; public class test$1{ public static void main(String args[])throws Exception{ System.out.println("hello world"); Scanner in = new Scanner(System.in); System.out.println(in.nextLine()); System.out.println(in.next()); InputStreamReader in1 = new InputStreamReader(System.in); BufferedReader br = new BufferedReader(in1); String str; str= br.readLine(); System.out.println(str); int n; n=Integer.parseInt(br.readLine()); System.out.println(n); } } ------------------------------------------------------------------------------ /* (#) Notepad program (#)version 1.0 (#)author balaji (#)date 28 aug 2011 */ import java.util.StringTokenizer; import java.util.Date; import java.awt.*; import javax.swing.*; import java.awt.Image; import javax.swing.ImageIcon; import java.io.*; import javax.swing.JMenu; import java.io.FileWriter; import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.JFrame; import javax.swing.JTextArea; import javax.swing.JSeparator; import java.awt.event.ActionListener; import java.awt.event.WindowListener; import java.awt.event.ActionEvent; import java.awt.event.WindowEvent; import java.awt.event.WindowAdapter; import javax.swing.JScrollBar; //import javax.swing.JPopupMenu; import java.awt.Container; //import javax.swing.JFlowLayout; import javax.swing.JScrollPane; import java.awt.Color; import java.awt.Font; import java.awt.FlowLayout; import javax.swing.JFileChooser; import javax.swing.JColorChooser; import javax.swing.JWindow; import javax.swing.JOptionPane; //import java.awt.*; import javax.swing.KeyStroke; import java.awt.event.KeyEvent; import javax.swing.JSeparator; import javax.swing.JToolBar.Separator; class wl extends WindowAdapter{ public void windowClosing(WindowEvent e){ System.out.println("closing window"+e); String s[]={"Yes","NO"}; //int result=JOptionPane.showOptionDialog(null, "Are you sure to exit?","Confirm Exit", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE, null, s, s[1]); int result=JOptionPane.showConfirmDialog(null, "Are you sure to exit?","Confirm Exit", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE ); if (result==JOptionPane.YES_OPTION){ System.exit(0); } } public void windowOpened(WindowEvent e) {} public void windowClosed(WindowEvent e) {} public void windowIconified(WindowEvent e) {} public void windowDeiconified(WindowEvent e) {} public void windowActivated(WindowEvent e) {} public void windowDeactivated(WindowEvent e) { } /*public void windowClosed(WindowEvent e){ System.out.println("closing window"+e); }*/ } class Notepad extends JFrame implements ActionListener{ private JMenu file; private JMenu edit ; private JMenu format ; private JMenu view; private JMenu help; private JMenuBar jb; private JMenuItem New ; private JMenuItem open; private JMenuItem save; private JMenuItem save1; private JMenuItem ps ; private JMenuItem print ; private JMenuItem exit; private JMenuItem undo; private JMenuItem cut; private JMenuItem copy; private JMenuItem paste; private JMenuItem delete; private JMenuItem find; private JMenuItem fnext; private JMenuItem replace; private JMenuItem gto; private JMenuItem sall; private JMenuItem tdate1; private JMenuItem wwrap; private JMenuItem fon; private JMenuItem font1; private JMenuItem fstyle; private JMenuItem ftype; private JMenuItem sbar; private JMenuItem vhelp; private JMenuItem anp; private JTextArea ja; private JScrollPane jsp; private JFileChooser jfc; private JColorChooser jcc; private JWindow w; private Image img; private Date d; private Font font; //JPopupMenu popup; Notepad(){ super("Program-Notepad"); //JFrame jf= new JFrame("Program-Notepad"); //setLayout(new JFlowLayout()); Container ct= getContentPane(); //ct.setLayout(new FlowLayout()); jb= new JMenuBar(); setJMenuBar(jb); file = new JMenu("File"); edit = new JMenu("Edit"); format = new JMenu("Format"); view= new JMenu("View"); help= new JMenu("Help"); jb.add(file); jb.add(edit); jb.add(format); jb.add(view); jb.add(help); New =new JMenuItem("New"); open =new JMenuItem("Open"); save =new JMenuItem("Save"); save1=new JMenuItem("Save AS"); ps =new JMenuItem("Page Setup"); print =new JMenuItem("Print"); exit=new JMenuItem("Exit"); open.setMnemonic('o'); open.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.CTRL_MASK)); New.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, ActionEvent.CTRL_MASK)); save.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.CTRL_MASK)); print.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_P, ActionEvent.CTRL_MASK)); exit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F4, ActionEvent.ALT_MASK)); file.add(New); file.add(open); file.add(save); file.add(save1); file.add(new JSeparator()); file.add(ps); file.add(print); file.addSeparator(); file.add(exit); undo=new JMenuItem("Undo"); cut=new JMenuItem("Cut"); copy=new JMenuItem("Copy"); paste=new JMenuItem("Paste"); delete=new JMenuItem("Delete"); find=new JMenuItem("Find"); fnext=new JMenuItem("Find Next"); replace=new JMenuItem("Replace"); gto=new JMenuItem("Goto"); sall=new JMenuItem("Select All"); tdate1=new JMenuItem("Time/Date"); undo.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Z, ActionEvent.CTRL_MASK)); sall.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, ActionEvent.CTRL_MASK)); gto.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_G, ActionEvent.CTRL_MASK)); replace.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R, ActionEvent.CTRL_MASK)); find.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F, ActionEvent.CTRL_MASK)); cut.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, ActionEvent.CTRL_MASK)); copy.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, ActionEvent.CTRL_MASK)); paste.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V, ActionEvent.CTRL_MASK)); edit.add(undo); edit.add(new JSeparator()); edit.add(cut); edit.add(copy); edit.add(paste); edit.add(new JSeparator()); edit.add(delete); edit.add(find); edit.add(fnext); edit.add(find); edit.add(fnext); edit.add(replace); edit.add(gto); edit.addSeparator(); edit.add(sall); edit.add(tdate1); wwrap=new JMenuItem("Word Wrap"); fon=new JMenuItem("Font Color"); font1=new JMenuItem("Font Size"); fstyle= new JMenuItem("Font Style"); ftype= new JMenuItem("Font Type"); format.add(wwrap); format.addSeparator(); format.add(fon); format.add(ftype); format.add(fstyle); format.add(font1); sbar=new JMenuItem("Status Bar"); view.add(sbar); vhelp=new JMenuItem("View Help"); anp=new JMenuItem("About Notepad"); help.add(vhelp); help.add(anp); New.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ System.out.println(e.getActionCommand()); new Notepad(); } }); //open.addActionListener(this); //save.addActionListener(this); //save1.addActionListener(this); //ps.addActionListener(this); //print.addActionListener(this); exit.addActionListener(this); sall.addActionListener(this); copy.addActionListener(this); cut.addActionListener(this); paste.addActionListener(this); open.addActionListener(this); fon.addActionListener(this); font1.addActionListener(this); ftype.addActionListener(this); fstyle.addActionListener(this); replace.addActionListener(this); this.addWindowListener(new wl()); jfc= new JFileChooser(); jcc= new JColorChooser(); /*open.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ System.out.println(e.getActionCommand()); //jfc.showOpenDialog(this); } });*/ /*save.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ System.out.println(e.getActionCommand()); } } );*/ save.addActionListener(this); save1.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ System.out.println(e.getActionCommand()); } } ); ps.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ System.out.println(e.getActionCommand()); } } ); anp.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ System.out.println(e.getActionCommand()); javax.swing.JOptionPane.showMessageDialog(null,"Notepad Version 1.0\n Copy right@2011 SSK Corporation\n All Rights Reserved ","About Notepad",javax.swing.JOptionPane.INFORMATION_MESSAGE); } } ); vhelp.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ System.out.println(e.getActionCommand()); } } ); tdate1.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ System.out.println(e.getActionCommand()); d= new Date(); ja.append(d.toString()); } } ); ja= new JTextArea(); add(ja); jsp = new JScrollPane(ja); ct.add(jsp); //setTitle("Program-Notepad"); ja.setLineWrap(true); ja.setWrapStyleWord(true); setVisible(true); setSize(1024,768); //setExtendedState(JFrame.MAXIMIZED_BOTH); setResizable(true); //setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); this.setIconImage(new ImageIcon(ClassLoader.getSystemResource("images/appicon.png")).getImage()); } public void actionPerformed(ActionEvent e){ if (e.getSource()==sall){ System.out.println(e.getActionCommand()); System.out.println(ja.getText()); ja.selectAll(); } if (e.getSource()==exit){ System.out.println(e.getActionCommand()); System.exit(0); } if (e.getSource()==copy){ System.out.println(e.getActionCommand()); ja.copy(); } if (e.getSource()==cut){ System.out.println(e.getActionCommand()); ja.cut(); } if (e.getSource()==paste){ System.out.println(e.getActionCommand()); ja.paste(); } if (e.getSource()==replace){ System.out.println(e.getActionCommand()); String t=JOptionPane.showInputDialog("Enter String to be replaced!!",""); System.out.println(t); String temp1=ja.getText(); System.out.println(temp1); StringTokenizer s= new StringTokenizer(temp1); int flag=0; while(s.hasMoreTokens()){ if((s.nextToken()).equalsIgnoreCase(t)){ System.out.println("yes"); flag=1; } } if(flag==0){ System.out.println("word not found"); JOptionPane.showMessageDialog(null,"Sorry '"+t+"' not Found","Information",JOptionPane.INFORMATION_MESSAGE); } else if(flag==1){ System.out.println("word found"); String temp=JOptionPane.showInputDialog("Enter value of String to be replaced!!",""); String temp3= temp1.replace(t,temp); ja.setText(temp3); JOptionPane.showMessageDialog(null,"'"+t+"' Successfully Replaced!!","Information",JOptionPane.INFORMATION_MESSAGE); } } if (e.getActionCommand()=="Font Color"){ System.out.println(e.getActionCommand()); Color c=jcc.showDialog(this,"ColorDailog",Color.red); ja.setForeground(c); } if (e.getActionCommand()=="Font Style"){ System.out.println(e.getActionCommand()); String temp=JOptionPane.showInputDialog("Enter Font Style....\n1.PLAIN\n2.BOLD\n3.ITALIC\n4.BOLD+ITAILC",""); //int s= Font.getSize(); int var=Integer.parseInt(temp); Font f=ja.getFont(); String name=f.getName(); int size=f.getSize(); System.out.println("sname: "+name+"size: "+size); if(var==1){ font = new Font(name, Font.PLAIN, size); ja.setFont(font); } else if(var==2){ font = new Font(name, Font.BOLD, size); ja.setFont(font); } else if(var==3){ font = new Font(name, Font.ITALIC, size); ja.setFont(font); } else if(var==4){ font = new Font(name,Font.BOLD+Font.ITALIC, size); ja.setFont(font); } } if (e.getActionCommand()=="Font Type"){ System.out.println(e.getActionCommand()); String temp=JOptionPane.showInputDialog("Enter Font Name....\n1.TimesRoman\n2.Helvetica\n3.Courier\n4.Serif\n5.Sansserif\n6.Monospaced\n7.Dialog\n8.Arial",""); //int s= Font.getSize(); int var=Integer.parseInt(temp); Font f=ja.getFont(); int style= f.getStyle(); int size=f.getSize(); System.out.println("style: "+style+"size: "+size); if(var==1){ font = new Font("TimesRoman", style, size); ja.setFont(font); } else if(var==2){ font = new Font("Helvetica", style, size); ja.setFont(font); } else if(var==3){ font = new Font("Courier", style, size); ja.setFont(font); } else if(var==4){ font = new Font("Serif",style, size); ja.setFont(font); } else if(var==5){ font = new Font("Sansserif",style, size); ja.setFont(font); } else if(var==6){ font = new Font("Monospaced",style, size); ja.setFont(font); } else if(var==7){ font = new Font("Dialog",style, size); ja.setFont(font); } else if(var==8){ font = new Font("Arial",style, size); ja.setFont(font); } } if (e.getActionCommand()=="Font Size"){ System.out.println(e.getActionCommand()); String temp=JOptionPane.showInputDialog("Enter size of the font!!",""); int size=Integer.parseInt(temp); Font f=ja.getFont(); String name=f.getName(); int style= f.getStyle(); System.out.println("sname: "+name+"size: "+size+"style: "+style); //style="Font."+style; font = new Font(name, style, size); ja.setFont(font); } if (e.getSource()==save){ System.out.println(e.getActionCommand()); try{ jfc.showSaveDialog(this); FileWriter fw= new FileWriter(jfc.getSelectedFile(),true); String temp=ja.getText(); fw.write(temp); fw.close(); } catch(Exception e1){} } if (e.getSource()==open){ System.out.println(e.getActionCommand()); jfc.showOpenDialog(this); try{ FileReader fr=new FileReader(jfc.getSelectedFile()); BufferedReader br=new BufferedReader(fr); ja.setText(""); String data=""; while((data=br.readLine())!=null) { ja.append(data+"\n"); } fr.close(); } catch(Exception e1) { System.out.println("error in reading "+e1); } } } } -------------------------------------------------------------------------- public class Test$10{ public static void main(String args[]){ System.out.println("Notepad program"); new Notepad(); } } /* (#)program for applet demo 26 aug */ /* <applet code=test$11.class height=1024 width=768> </applet> */ import java.awt.Dimension; import java.applet.Applet; import java.awt.Graphics; import java.util.Date; import java.util.Random; public class test$11 extends Applet implements Runnable { Date d; public void init(){ System.out.println("init method"); Thread t= new Thread(this); t.start(); } /*public void start(){ System.out.println("start method"); //repaint(); //d=new Date(); }*/ public void run(){ System.out.println("run method"); while(true){ repaint(); try{ Thread.sleep(1000); } catch(InterruptedException e){ } } } public void stop(){ System.out.println("stop method"); } public void update(Graphics g){ System.out.println("update method"); paint(g); } public void destroy(){ System.out.println("destroy method"); } public void paint(Graphics g){ Random r= new Random(); Dimension d1= getSize(); d=new Date(); System.out.println("height"+ d1.height); int x= r.nextInt(d1.height)+1; int y=r.nextInt(d1.width)+1; System.out.println("x"+x+"y"+y); //g.drawString("hello world",x,y); //g.drawString(d.toString(),x,y); g.fillRect(x,y,5,5); } } -------------------------------------------------------------------------------- import java.applet.Applet; import java.awt.Graphics; import java.awt.Dimension; /* <applet code=test$12.class height=700 width=500><param name="height" value=1024></applet>*/ public class test$12 extends Applet implements Runnable { int x=1024; int y=768; int a; int b; public void init(){ Thread t= new Thread(this); t.start(); } public void run(){ for (int i=1;i<x;i=i+100) { for(int j=1;j<y;j++) { a=j; b=i; repaint(); try{ Thread.sleep(10); } catch(Exception e) { } } } } public void paint(Graphics g) { System.out.println("paint"+a+b); g.drawOval(a,b,50,50); } } ---------------------------------------------------------------------------------------- /* (#) thread program demo 23 aug 2011 (#) file Test$13.java */ class gm extends Thread{ public void run(){ while(true){ try{ Thread.sleep(1000); System.out.println("Good Morning"); } catch(InterruptedException e){ } } } } class hello extends Thread{ public void run(){ while(true){ try{ Thread.sleep(2000); System.out.println("Hello"); } catch(InterruptedException e){ } } } } class welcome extends Thread{ public void run(){ while(true){ try{ Thread.sleep(3000); System.out.println("welcome"); } catch(InterruptedException e){ } } } } ---------------------------------------------------------------------------------------- public class Test$13{ public static void main(String args[]){ System.out.println("thread program"); gm g= new gm(); hello h= new hello(); welcome w= new welcome(); g.start(); h.start(); w.start(); } } ----------------------------------------------------------------------------------------------- /* (#) thread prog demo 23 aug 2011 (#) file: test$14.java */ class odd extends Thread{ odd(){ super("odd thread"); } public void run(){ for (int i=0;i<50;i++){ if ((i%2)!=0){ System.out.println("Odd Thread : " + i ); } } } } class even extends Thread{ even(){ super("even thread"); } public void run(){ for (int i=0;i<50;i++){ if ((i%2)==0){ System.out.println("Even Thread: "+ i); } } } } -------------------------------------------------------- public class test$14{ public static void main(String args[]){ System.out.println("Thread program"); odd o = new odd(); even e= new even(); o.start(); e.start(); } } ------------------------------------------------------------------------------------------- /* (#) thread prog demo 23 aug 2011 (#) file: test$14.java */ class odd extends Thread{ odd(){ super("odd thread"); } public void run(){ for (int i=0;i<50;i++){ if ((i%2)!=0){ System.out.println("Odd Thread : " + i ); } } } } class even extends Thread{ even(){ super("even thread"); } public void run(){ for (int i=0;i<50;i++){ if ((i%2)==0){ System.out.println("Even Thread: "+ i); } } } } ------------------------------------------------------------------------------------------------------ public class test$15{ public static void main(String args[]){ System.out.println("Thread program"); odd o = new odd(); even e= new even(); o.setPriority(Thread.MAX_PRIORITY); e.setPriority(Thread.MIN_PRIORITY); //e.setPriority(1); //o.setPriority(10); e.start(); o.start(); } } class sroot implements Runnable{ public void run(){ System.out.println("square root of first 30 natural numbers"); for (int i=1;i<=30;i++){ System.out.println("square root of "+i+" "+ Math.sqrt(i)); } } } ------------------------------------------------------------------------ public class test$16{ public static void main(String args[]){ //sroot s=new sroot(); //new Thread(s).start(); new Thread(new sroot()).start(); } } ------------------------------------------------------------------- /* (#) thread program demo 23 aug 2011 (#) test$17.java */ class factorial extends Thread{ public void run(){ System.out.println("factorial of first twenty natural numbers: "); long s=1; int n=1; while(n!=30){ s=1; for (int i=1;i<=n;i++){ s=s*i; } System.out.println("factorial of "+n+ " is..."+s ); n++; } } } ---------------------------------------------------------------------------------------- public class test$17{ public static void main(String args[]){ factorial f = new factorial(); f.start(); } } import java.io.BufferedReader; import java.io.FileReader; public class test$18{ public static void main(String args[]){ System.out.println("hello world"); String s="test$18.java"; try{ FileReader fr= new FileReader(s); BufferedReader br = new BufferedReader(fr); while(br.readLine()!=null) System.out.println(br.readLine()); br.close(); } catch (Exception e){} } } --------------------------------------------------------------------- import java.text.DecimalFormat; import java.text.NumberFormat; public class test$19{ public static void main(String args[]){ System.out.println("test program"); System.out.println((int)(Math.random()*1000)); System.out.println(Math.floor(Math.random() * 41) + 10); System.out.println(Math.random()*41); NumberFormat d= new DecimalFormat("0.000"); DecimalFormat d1= new DecimalFormat("0.000"); //NumberFormat d2= new NumberFormat("0.000"); double i=15.24566; //System.out.println(d2.format(i)); System.out.println(d1.format(i)); System.out.println(d.format(i)); System.out.println(Math.round(i)); System.out.printf("%1$.2f", i); }} ------------------------------------------------------------------------- /* program for abstract class */ abstract class hello{ void print(){ System.out.println("hello world print method"); } } ------------------------------------------------------------------------------ public class test$2 extends hello { public static void main(String args[]){ System.out.println("hello world"); test$2 t = new test$2(); hello h; h=t; h.print(); //hello h = new hello(); //h.print(); } } ----------------------------------------------------------------------------- import java.net.*; import java.io.*; public class test$20 { public static void main(String[] args) throws Exception { URL yahoo = new URL("http://www.dinamalar.com/"); BufferedReader in = new BufferedReader(new InputStreamReader(yahoo.openStream())); String inputLine; while ((inputLine = in.readLine()) != null) System.out.println(inputLine); in.close(); } } import java.lang.Thread; class mythread extends Thread{ mythread(String s){ super(s); } public void run(){ for(int i=0;i<5;i++) { try{ join(); } catch(Exception e){} System.out.println(Thread.currentThread().getName()); //yield(); } } } -------------------------------------------------------------------- public class test$21 { public static void main(String args[])throws Exception { int a; //System.out.println("test program"+a); mythread one = new mythread("one"); mythread two = new mythread("two"); one.start(); two.start(); String test = "This is a test string"; String[] tokens = test.split(" "); System.out.println(tokens.length); } } ----------------------------------------------------------------- import java.io.*; /* (#) prog file demo (#) 31 aug 2011 */ public class test$22{ public static void main(String args[])throws Exception { System.out.println("hello world "); System.out.println("Enter file name?"); FileReader fr = new FileReader("test$22.java"); BufferedReader br = new BufferedReader(fr); while(br.readLine()!=null){ System.out.println(br.readLine()); } br.close(); } }import java.io.StreamTokenizer; import java.io.FileReader; public class test$23{ public static void main(String args[])throws Exception { System.out.println("hello world "); try{ StreamTokenizer s= new StreamTokenizer(new FileReader("test$23.java")); while(s.nextToken()!=StreamTokenizer.TT_EOF){ if (s.ttype==StreamTokenizer.TT_WORD){ System.out.println(s.sval); } } } catch(Exception e){ } }} ------------------------------------------------------------------------------------------------- import java.io.StreamTokenizer; import java.io.FileReader; public class test$24{ public static void main(String args[]){ System.out.println("hello world "); try{ StreamTokenizer s= new StreamTokenizer(new FileReader("numbers.txt")); while(s.nextToken()!=StreamTokenizer.TT_EOF){ if(s.ttype==StreamTokenizer.TT_NUMBER){ System.out.println(s.nval); } } } catch(Exception e ){ } } } ------------------------------------------------------------------------------------------------- import java.net.URL; public class test$25{ public static void main(String args[])throws Exception{ System.out.println("Hello world program"); URL u= new URL("http://www.cs.rpi.edu/"); System.out.println("protocal: "+u.getProtocol()); System.out.println("host: "+ u.getHost()); System.out.println("file name: "+ u.getFile()); System.out.println("port: "+ u.getPort()); System.out.println("refernece: "+u.getRef()); } } ------------------------------------------------------------------------------------------------- import java.io.*; public class test$26{ public static void main(String args[]){ System.out.println("test program"); try{ StringReader s=new StringReader(" abc xcs werw werwe wrewrw sf"); StreamTokenizer st= new StreamTokenizer(s); //while(st.nextToken()!=StreamTokenizer.TT_EOF){ while(st.nextToken()!=-1){ //while(st.nextToken()!=StreamTokenizer.TT_EOF){ if(st.ttype==StreamTokenizer.TT_WORD){ System.out.println(st.sval); } } } catch(Exception e){} } } ------------------------------------------------------------------------------------------------- import java.io.*; import java.util.*; public class test$27{ public static void main(String args[])throws Exception{ System.out.println("test program"); DataInputStream dis=new DataInputStream(System.in); System.out.println("Enter a sentence: "); String s=dis.readLine(); StringTokenizer st=new StringTokenizer(s); while (st.hasMoreTokens()) System.out.println(st.nextToken()); } } ------------------------------------------------------------------------------------------------- public class test$28{ public static void main(String args[]){ System.out.println("test program"); String s1=new String("hello "); String s2=new String("abc"); Object[] o =new Object[2]; o[0]=s1; o[1]=s2; System.out.println(o[1]); } }public class test$29{ public static void main(String args[]){ System.out.println("test program"); String s="hello balaji hello hello, hello."; System.out.println(s); s=s.replace("hello","hai"); System.out.println(s); } } ------------------------------------------------------------------------------------------------- import pack.*; import pack.subpack.*; public class test$3 { public static void main(String args[])throws Exception{ pack1 p= new pack1(); sub s= new sub(); System.out.println("hai hello"+p.i+s.j); } } ------------------------------------------------------------------------------------------------- class test$30 { public static void main(String[] args) { System.out.println(System.getProperty("user.home")); } } import java.awt.Font; import java.awt.GraphicsEnvironment; public class test$31 { public static void main(String[] args) { // // Get all available fonts from GraphicsEnvironment GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); Font[] fonts = ge.getAllFonts(); // // Iterates all available fonts and get their name and family name for (Font font : fonts) { String fontName = font.getName(); String familyName = font.getFamily(); System.out.println("Font: " + fontName + "; family: " + familyName); } } } //Sample Java Program to generate the message digest from a given input file: ------------------------------------------------------------------------------------------------- import java.security.MessageDigest; import java.io.*; import sun.misc.*; public class test$32 { /** * The only argument is the name of the file to be digested. */ public static void main (String[] args) throws Exception { if (args.length != 1) { System.err.println("Usage: java DigestFile filename"); System.exit(1); } // Create a message digest MessageDigest md = MessageDigest.getInstance("MD5"); BufferedInputStream in = new BufferedInputStream(new FileInputStream(args[0])); int theByte = 0; while ((theByte = in.read()) != -1) { md.update((byte)theByte); } in.close(); byte[] theDigest = md.digest(); System.out.println(new BASE64Encoder().encode(theDigest)); } } PrinterJob myPrinterJob = PrinterJob.getPrinterJob(); myPrinterJob.setPrintable(new MyDocument()); try { myPrinterJob.print(); } catch (PrinterException ex) { JOptionPane.showConfirmDialog(null, ex.getMessage(), "Print Error", JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE); } class MyDocument implements Printable { public int print(Graphics g, PageFormat pf, int pageIndex) { if (pageIndex > LoanCalculator.numberOfPages - 1) { return NO_SUCH_PAGE; } // print repayment knowing loan values // makes no assumptions about how many times print method is called per page Graphics2D g2D = (Graphics2D) g; Font printFont = new Font("Courier New", Font.PLAIN, 12); Rectangle2D fontRect = printFont.getStringBounds("A", g2D.getFontRenderContext()); double currentY = pf.getImageableY() + fontRect.getHeight(); g2D.setFont(printFont); // Print header g2D.drawString("Loan Repayment Schedule - Page " + String.valueOf(pageIndex + 1), (int) pf.getImageableX(), (int) currentY); currentY += 2 * fontRect.getHeight(); g2D.drawString("Loan Amount: $" + new DecimalFormat("0.00").format(LoanCalculator.loan), (int) pf.getImageableX(), (int) currentY); currentY += fontRect.getHeight(); g2D.drawString("Interest Rate: " + new DecimalFormat("0.00").format(LoanCalculator.interest) + "%", (int) pf.getImageableX(), (int) currentY); currentY += fontRect.getHeight(); g2D.drawString("Number of Months: " + String.valueOf(LoanCalculator.months), (int) pf.getImageableX(), (int) currentY); currentY += fontRect.getHeight(); g2D.drawString("Payment Amount: $" + new DecimalFormat("0.00").format(LoanCalculator.payment), (int) pf.getImageableX(), (int) currentY); currentY += 2 * fontRect.getHeight(); g2D.setFont(new Font("Courier New", Font.BOLD, 12)); g2D.drawString("Month Payment Principal Interest Balance", (int) pf.getImageableX(), (int) currentY); g2D.setFont(new Font("Courier New", Font.PLAIN, 12)); currentY += fontRect.getHeight(); double b; double pa; double p; double i; int mstart; int mend; // compute balance remaining at start of current page b = LoanCalculator.loan; if (pageIndex !=0) { for (int m = 1; m <= (pageIndex * LoanCalculator.monthsPerPage); m++) { // Find interest i = LoanCalculator.interest * b / 1200; // Round to two decimals i = Double.valueOf(new DecimalFormat("0.00").format(i)).doubleValue(); // Calculate balance b -= LoanCalculator.payment - i; } } // find month range on current page mstart = (pageIndex * LoanCalculator.monthsPerPage) + 1; mend = mstart + LoanCalculator.monthsPerPage - 1; if (mend > LoanCalculator.months) { mend = LoanCalculator.months; } // compute current page payment schedule for (int m = mstart; m <= mend; m++) { // Find interest i = LoanCalculator.interest * b / 1200; // Round to two decimals i = Double.valueOf(new DecimalFormat("0.00").format(i)).doubleValue(); // Determine payment amount - Compute principal and balance if (m != LoanCalculator.months) { pa = LoanCalculator.payment; p = pa - i; b -= p; } else { // Adjust last payment to payoff balance pa = b + i; p = b; b = 0; } // Print payment line currentY += fontRect.getHeight(); g2D.drawString(paymentLine(m, pa, p, i, b), (int) pf.getImageableX(), (int) currentY); } return PAGE_EXISTS; } private String paymentLine(int m, double pa, double p, double i, double b) { // build up line with payoff information // using info from Chapter 6 char[] pl = new char[60]; String s; // blank out line with spaces for (int j = 0; j < 60; j++) { pl[j] = ' '; } // Months s = String.valueOf(m); midLine(s, pl, 4 - s.length()); // Payment amount s = new DecimalFormat("0.00").format(pa); midLine(s, pl, 17 - s.length()); // Principal s = new DecimalFormat("0.00").format(p); midLine(s, pl, 31 - s.length()); // Interest s = new DecimalFormat("0.00").format(i); midLine(s, pl, 44 - s.length()); // Balance s = new DecimalFormat("0.00").format(b); midLine(s, pl, 56 - s.length()); // convert character array to string s = String.copyValueOf(pl); return (s); } private void midLine(String inString, char[] charLine, int pos) { for (int i = pos; i < pos + inString.length(); i++) { charLine[i] = inString.charAt(i - pos); } } } ------------------------------------------------------------------------------------------------- import java.awt.Graphics; import java.awt.print.PageFormat; import java.awt.print.Printable; import java.awt.print.PrinterException; import java.awt.print.PrinterJob; import javax.swing.JPanel; public class Test$34 extends JPanel { public static void main(String[] args) { try { PrinterJob pjob = PrinterJob.getPrinterJob(); pjob.setJobName("Graphics Demo Printout"); pjob.setCopies(1); pjob.setPrintable(new Printable() { public int print(Graphics pg, PageFormat pf, int pageNum) { if (pageNum > 0) // we only print one page return Printable.NO_SUCH_PAGE; // ie., end of job pg.drawString("www.java2s.com", 10, 10); return Printable.PAGE_EXISTS; } }); if (pjob.printDialog() == false) // choose printer return; pjob.print(); } catch (PrinterException pe) { pe.printStackTrace(); } } } ------------------------------------------------------------------------------------------------- import java.awt.Color; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.geom.Line2D; import java.awt.print.PageFormat; import java.awt.print.Printable; import java.awt.print.PrinterJob; class JavaWorldPrintExample1 implements Printable { public static void main(String[] args) { JavaWorldPrintExample1 example1 = new JavaWorldPrintExample1(); System.exit(0); } //--- Private instances declarations private final double INCH = 72; /** * Constructor: Example1 * <p> * */ public JavaWorldPrintExample1() { //--- Create a printerJob object PrinterJob printJob = PrinterJob.getPrinterJob(); //--- Set the printable class to this one since we //--- are implementing the Printable interface printJob.setPrintable(this); //--- Show a print dialog to the user. If the user //--- click the print button, then print otherwise //--- cancel the print job if (printJob.printDialog()) { try { printJob.print(); } catch (Exception PrintException) { PrintException.printStackTrace(); } } } /** * Method: print * <p> * * This class is responsible for rendering a page using the provided * parameters. The result will be a grid where each cell will be half an * inch by half an inch. * * @param g * a value of type Graphics * @param pageFormat * a value of type PageFormat * @param page * a value of type int * @return a value of type int */ public int print(Graphics g, PageFormat pageFormat, int page) { int i; Graphics2D g2d; Line2D.Double line = new Line2D.Double(); //--- Validate the page number, we only print the first page if (page == 0) { //--- Create a graphic2D object a set the default parameters g2d = (Graphics2D) g; g2d.setColor(Color.black); //--- Translate the origin to be (0,0) g2d.translate(pageFormat.getImageableX(), pageFormat .getImageableY()); //--- Print the vertical lines for (i = 0; i < pageFormat.getWidth(); i += INCH / 2) { line.setLine(i, 0, i, pageFormat.getHeight()); g2d.draw(line); } //--- Print the horizontal lines for (i = 0; i < pageFormat.getHeight(); i += INCH / 2) { line.setLine(0, i, pageFormat.getWidth(), i); g2d.draw(line); } return (PAGE_EXISTS); } else return (NO_SUCH_PAGE); } } //Example1 import java.awt.print.PrinterJob; public class Test$36{ public static void main(String args[]){ System.out.println("hello world"); PrinterJob pj= PrinterJob.getPrinterJob(); pj.printDialog(); } } ------------------------------------------------------------------------------------------------- import java.io.BufferedReader; import java.awt.Graphics; import java.awt.print.PageFormat; import java.awt.print.Printable; import java.awt.print.PrinterException; import java.awt.print.PrinterJob; import java.io.*; import javax.swing.JPanel; public class Test$37 extends JPanel { public static void main(String[] args)throws Exception { try { PrinterJob pjob = PrinterJob.getPrinterJob(); // pjob.setJobName("Graphics Demo Printout"); pjob.setCopies(1); pjob.setPrintable(new Printable() { public int print(Graphics pg, PageFormat pf, int pageNum) { if (pageNum > 0) // we only print one page return Printable.NO_SUCH_PAGE; // ie., end of job try{ FileReader fr = new FileReader("Test$37.java"); BufferedReader br = new BufferedReader(fr); String temp=" "; int i=30; while((temp=br.readLine())!=null){ i=i+15; pg.drawString(temp, 50, i); } }catch(Exception e){} return Printable.PAGE_EXISTS; } }); if (pjob.printDialog() == false) // choose printer return; pjob.print(); } catch (Exception pe) { pe.printStackTrace(); } } }import java.awt.EventQueue; import javax.swing.JFrame; import javax.swing.JWindow; import javax.swing.JLabel; import java.awt.BorderLayout; import javax.swing.SwingConstants; import javax.swing.JDesktopPane; import javax.swing.BorderFactory; import javax.swing.*; import java.awt.*; public class test$38 extends JFrame implements Runnable{ test$38(){ JDesktopPane tp = new JDesktopPane(); tp.setBorder(BorderFactory.createEmptyBorder()); //tp.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE); //JFrame f = new JFrame(); JLabel welcome = new JLabel("Welcome: Today is " + new java.util.Date() + " ", JLabel.CENTER); getContentPane().add(welcome, BorderLayout.PAGE_END, JLabel.CENTER); getContentPane().add(tp); /* welcome.setFont(new Font("monospaced", Font.PLAIN, 12)); welcome.setForeground(Color.blue); JDesktopPane desktop = new JDesktopPane(); desktop.setBorder(BorderFactory.createEmptyBorder()); desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE); //getContentPane().add(welcome, BorderLayout.PAGE_END, JLabel.CENTER); getContentPane().add(desktop, BorderLayout.CENTER); */ setVisible(true); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //JLabel t= new JLabel("balaji",SwingConstants.CENTER); //JWindow w= new JWindow(); //w.add(t); //,BorderLayout.CENTER); //w.setBounds(200,300,300,300); //w.setVisible(true); } public void run(){ System.out.println("event queue demo run "); } public static void main(String args[]){ System.out.println("event queue demo"); EventQueue.invokeLater(new test$38()); } } ------------------------------------------------------------------------------------------------- import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; class addremove extends JPanel implements ActionListener{ private JButton addbut; private JButton revbut; private JPanel panel1; private JPanel panel2; public addremove() { addbut = new JButton ("Add"); revbut = new JButton ("Remove"); panel1 = new JPanel(); panel2 = new JPanel(); panel1.setBackground(Color.blue); panel2.setBackground(Color.red); setPreferredSize (new Dimension (218, 160)); setLayout (null); add (addbut); add (revbut); add (panel2); addbut.setBounds (20, 120, 80, 25); revbut.setBounds (120, 120, 80, 25); panel1.setBounds (20,10,180,60); panel2.setBounds (20,10,180,60); } public void actionPerformed(ActionEvent e) { if(e.getSource() == addbut) { remove(panel2); add(panel1); } else if (e.getSource() == revbut) { remove(panel1); add(panel2); } } public static void main (String[] args) { JFrame frame = new JFrame ("addremove"); frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); frame.getContentPane().add (new addremove()); frame.pack(); frame.setVisible (true); frame.setLocation(450,280); frame.setResizable(false); } } interface xyz{ void print(); void print1(); } class one implements xyz{ public void print(){ System.out.println("class one"); } public void print1(){ System.out.println("class one"); } } class two implements xyz{ public void print(){ System.out.println("class two"); } public void print1(){ System.out.println("class one"); } } public class test$4 { public static void main(String args[]){ System.out.println("hello world"); one o= new one(); two t= new two(); t.print(); o.print(); } } public class test$40{ public static void main(String arfs[]){ new test$41(); } } public class test$41{ public test$41(){ System.out.println("hello world"); } } import java.util.Map; import java.util.Properties; import java.io.Console; import java.io.PrintWriter; public class test$42{ public static void main(String args[])throws Exception{ System.out.println("Shut down program"); Properties p = new Properties(); Runtime r= Runtime.getRuntime(); //r.exec("shutdown -l"); String temp; p=System.getProperties(); //System.out.println(temp); //System.out.println(System.getProperty("user.home")); //System.out.println(System.getProperties()); //System.out.println(System.getProperty("sun.boot.library.path")); //System.out.println(p.toString()); //System.out.println(System.getenv()); //Console.WriteLine("hello"); Console c= System.console(); String temp1=c.readLine(); char[] c1= c.readPassword("enter password: "); System.out.println(c1); System.out.println(temp1); c.printf("esdfsd"+"hello","balaji"); PrintWriter out= c.writer(); out.println("hello world"); } } ------------------------------------------------------------------------------------------------- /* (#)System program (#)10 aug 2011 (#)author : bala */ import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.util.StringTokenizer; import java.util.Properties; import javax.swing.JFrame; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import javax.swing.JButton; import javax.swing.JPanel; import java.awt.FlowLayout; import java.awt.Container; import javax.swing.JOptionPane; import java.lang.Runtime; import javax.swing.JLabel; import javax.swing.JTextArea; import javax.swing.JScrollPane; public class test$43 extends JFrame implements ActionListener { private JButton sdown; private JButton loff; private JButton rstrt; private JButton suser; private JButton env; private JButton prp; private JButton abt; private JPanel p; private Container ct; private Runtime r; private Properties pr; private StringTokenizer st; private JTextArea ta; public test$43(){ //super("System program"); sdown= new JButton("Shut Down"); loff=new JButton("Log Off"); rstrt=new JButton("Restart"); suser=new JButton("Switch User"); env=new JButton("Environment Variables"); prp=new JButton("System Properties"); abt= new JButton("About"); p= new JPanel(); //p.setLayout(new FlowLayout()); r= Runtime.getRuntime(); ct= getContentPane(); ct.setLayout(new FlowLayout()); ct.add(sdown); ct.add(loff); ct.add(rstrt); ct.add(suser); ct.add(env); ct.add(prp); ct.add(abt); sdown.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ System.out.println(e.getActionCommand()); try{ r.exec("shutdown -s"); } catch(Exception e1){ } } } ); loff.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ System.out.println(e.getActionCommand()); try{ r.exec("shutdown -l"); } catch(Exception e1){} } } ); rstrt.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ System.out.println(e.getActionCommand()); try{ r.exec("shutdown -r"); } catch(Exception e1){} } } ); suser.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ System.out.println(e.getActionCommand()); try{ r.exec("shutdown -l"); } catch(Exception e1){} } } ); env.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ System.out.println(e.getActionCommand()); //JOptionPane.showMessageDialog(null,"\n"+System.getenv()); String temp; temp=JOptionPane.showInputDialog("Enter environment variable Name??"); System.out.println(temp); if(temp.equals("")){ JOptionPane.showMessageDialog(null,"\nfield not be empty"); } else{ JOptionPane.showMessageDialog(null,"\n"+System.getenv(temp)); } } } ); prp.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ System.out.println(e.getActionCommand()); pr= new Properties(); pr=System.getProperties(); String temp=pr.toString(); String temp1=""; System.out.println(temp); st= new StringTokenizer(temp,","); int i=0; while(st.hasMoreTokens()){ i++; temp1=temp1+"\n"+st.nextToken(); } JFrame jf= new JFrame(); ta= new JTextArea(); ta.setText(temp1); jf.setVisible(true); jf.setSize(1024,768); jf.setDefaultCloseOperation(EXIT_ON_CLOSE); jf.add(ta); System.out.println(temp1); //new Text(temp1); } } ); abt.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ System.out.println(e.getActionCommand()); JOptionPane.showMessageDialog(null,"\nSystem Program\nVersion 1.0\nCopy Right@ 2011 SSK Technologies\n"); } } ); setResizable(false); setSize(400,100); setVisible(true); setDefaultCloseOperation(EXIT_ON_CLOSE); setTitle("System program"); } public void actionPerformed(ActionEvent e){ } public static void main(String args[])throws Exception{ System.out.println("shutdown gui"); new test$43(); } } ------------------------------------------------------------------------------------------------- import java.io.*; import java.util.Properties; class App { public static void main( String[] args ) { Properties prop = new Properties(); try { //set the properties value prop.setProperty("database", "localhost"); prop.setProperty("dbuser", "mkyong"); prop.setProperty("dbpassword", "password"); //save properties to project root folder prop.store(new FileOutputStream("config.properties"), null); } catch (IOException ex) { ex.printStackTrace(); } } }import java.lang.String; public class test$5{ test$5(String s){ } public String toString(String s){ return s; } public static void main(String args[]){ System.out.println("hello world"); String s="hello "; String ss= "balaji"; System.out.println(s+ss); System.out.println(s.equals(ss)); char sss; sss=s.charAt(0); System.out.println(sss); sss=ss.charAt(0); System.out.println(sss); //string str= s.subString(1,3); test$5 t= new test$5("test$5 program"); System.out.println(t); } }class ExA extends Exception{ ExA(String s ){ super(s); } } class ExB extends Exception{ ExB(String s){ super(s); } } ------------------------------------------------------------------------------------------------- public class test$6{ public static void main(String args[]) { System.out.println("hello world"); try{ print(); } catch(ExB e){ System.out.println(e); e.printStackTrace(); } } public static void print()throws ExB{ System.out.println("print method"); throw new ExB("just testing.."); } } ------------------------------------------------------------------------------------------------- public class Test$7{ public static void main(String args[]){ System.out.println("test 7 program"); float f; f=100.25034500f; double d; d=4646.1634; System.out.println(f); System.out.println(d); } }interface base3{ } interface base4{ } class base{ } class base1{ } class derived1 extends base implements base3,base4 { } class derived2 extends base{ } public class Test$8 { public static void main(String args[]){ System.out.println("test program"); } }public class test$9 { public static void main(String args[]){ System.out.println("test9 program"); String s=new String("one"); s=new String("two"); System.out.println(s); StringBuffer s1=new StringBuffer("hello"); System.out.println(s1); } } ------------------------------------------------------------------------------------------------- import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.util.StringTokenizer; import java.util.Properties; import javax.swing.JFrame; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import javax.swing.JButton; import javax.swing.JPanel; import java.awt.FlowLayout; import java.awt.Container; import javax.swing.JOptionPane; import java.lang.Runtime; import javax.swing.JLabel; import javax.swing.JTextArea; import javax.swing.JScrollPane; import java.awt.FlowLayout; import java.awt.Container; public class Text extends JFrame{ public Text(String temp1){ Container ct= getContentPane(); ct.setLayout(new FlowLayout()); JTextArea ta= new JTextArea(); JScrollPane jsp=new JScrollPane(ta); ct.add(jsp); ta.setText(temp1); ct.add(ta); setTitle("System properties"); setSize(1024,768); setVisible(true); setDefaultCloseOperation(EXIT_ON_CLOSE); addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent e){ //dispose(); } } ); } /* public static void main(String args[]){ new Text("dsfsdf"); } */ }

No comments:

Post a Comment

உப்பு மாங்காய்

சுருக்குப்பை கிழவி. சுருக்கங்கள் சூழ் கிழவி. பார்க்கும் போதெல்லாம் கூடையுடனே குடியிருப்பாள். கூடை நிறைய குட்டி குட்டி மாங்காய்கள். வெட்டிக்க...