Skip to main content

Posts

Showing posts from March, 2009

File and Directory handling

To work with files and directories java.io package has a class File , which has all necessary methods and constructors to work with Files and Directories. The object of File class can be used to handle both file and directory. You can create File object that will work as abstract representation of file or directory.  There are following constructors used to create File object. 1. public File (String pathname) Creates a new File instance by converting the given pathname string into an abstract pathname. If the given string is the empty string, then the result is the empty abstract pathname. e.g . File f=new File (“ F:/java/programs ”); it creates  File object that is abstract represantioan of directory , F:\java\programs.   e.g. File f=new File (“ F:/java/programs/MyClass.java ”); it creates  File object that is abstract represantioan of file MyClass.java File f=new File (“ F:/java/programs ”);                         2. File (File parent,String child)

CardLayout

import  javax.swing. * ; import  java.awt. * ; import  java.awt.event. * ; class  CardLayoutDemo {      static   CardLayout  card;      static   JPanel  desk;      public   static   void  main( String  ar[])     {                   JPanel  p1 = new   JPanel ();p1.setBackground( new   Color (234,234,255));          JPanel  p2 = new   JPanel ();p2.setBackground( new   Color (200,200,200));          JPanel  p3 = new   JPanel ();p3.setBackground( new   Color (200,200,255));          JPanel  p4 = new   JPanel ();p4.setBackground( new   Color (100,200,255));                            JFrame  f = new   JFrame ( "New Frame" );          Container  c = f.getContentPane();         c.setLayout( new   BorderLayout ());         card = new   CardLayout ();         desk = new   JPanel ();         desk.setLayout(card);         desk.add(p1, "p1" );         desk.add(p2, "p2" );          desk.add(p3, "p3" );         desk.add(p4, "p4&q