Showing posts with label system. Show all posts
Showing posts with label system. Show all posts

Closing Jframe on Jbutton Click

Saturday, 24 May 2014

java logo

Not going to do too much bla bla..

Just open up Netbeans Ide

create new project—>java—> java desktop applcation

Switch  to design View Take a Jbutton from the right side of Ide Palette

Right Click Jbutton You will see

Events—>Action—>ActionPerformed

Click it you will be automatically Switched to Source View

You will see code like this

 1: private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) 
 2: { 
 3: System.exit(0);//Closes Jframe with exit code '0' 
 4: }


 


Now Run and compile it press Jbutton It closes the jframe


 


Thanks

File Attribute Viewer

Saturday, 8 February 2014



Its is a useful Application to see hiddden attributes of a file for ex.. is it a system file ,readonly or something else.
To do this first of all we have to take some java component given below
all though it is a GUI Application or Program
  1. jButton
  2. jLabel
That’s It
Now On jButton1ActionPerformed we have to write down this code

   

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        JFileChooser jfc=new JFileChooser();

        jfc.setFileSelectionMode(jfc.FILES_ONLY);

        jfc.setCurrentDirectory(new File("C:/"));

        int a=jfc.showOpenDialog(null);
       
        if(a==jfc.APPROVE_OPTION)
        {
            
            String hg=jfc.getSelectedFile().toString();
         try
         {
         String lines;
        Process procs=Runtime.getRuntime().exec("attrib "+hg);

        BufferedReader binput=new BufferedReader(new InputStreamReader(procs.getInputStream()));
       
        while ((lines = binput.readLine()) != null)
        {
         if (!lines.trim().equals(""))
         {
              lines = lines.substring(0);
              
              filterme(lines);
         }//if  ends
        } //while ends
         }
         catch(Exception esd)
         {
            System.out.println(esd.toString());
         }
        }//open dialog if ends
       
    }

Now The filterme function
public void filterme(String getline)
   {

        boolean b=getline.trim().startsWith("S");

        String one=getline.substring(0,6);

        hamja(one.trim()); //Here calling hamja function with parameters }
Now The hamja function in this function we Filter the parameters sent by  filterme function you can also use switch case for this but I have used if,else
public void hamja(String exten)
   {
       
      if(exten.equals("SHR"))
      {
        System.out.println("System,Hidden,Readonly");
        jLabel1.setText("System,Hidden,Readonly");
      }
      else if(exten.equals("S R"))
      {
       System.out.println("Its System Readonly");
       jLabel1.setText("Its System Readonly");
      }
      else if(exten.equals("SH"))
      {
      System.out.println("Its System,Hidden");
      jLabel1.setText("Its System,Hidden");
      }
      else if(exten.equals("S"))
      {
         System.out.println("Its System");
         jLabel1.setText("Its System");
      }
      else if(exten.equals("H"))
      {
         System.out.println("Its Hidden");
         jLabel1.setText("Its Hidden");
      }
      else if(exten.equals("R"))
      {
         System.out.println("Its Readonly");
         jLabel1.setText("Its Readonly");
      }
      else if(exten.equals("A   HR"))
      {
       System.out.println("Its archive,Hidden,Readonly");
       jLabel1.setText("Its Archive,Hidden,Readonly");
      }
      else if(exten.equals("A"))
      {
       System.out.println("Its archive");
       jLabel1.setText("Its archive");
      }
       else if(exten.equals("A  SH"))
      {
       System.out.println("Its archive,system,hidden");
       jLabel1.setText("Its Archive,System,Hidden");
      }
       else if(exten.equals("A   H"))
      {
       System.out.println("Its archive,hidden");
       jLabel1.setText("Its Archive,Hidden");
      }
      else
      {
           System.out.println(exten);
      }
     
   }

Get Host Data

Friday, 24 January 2014


If we want to know about Host data for example Ip address,pc name,operating system etc.
To do this job we have to first Import java.net package,
on Jbutton action performed as you see below 

 

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
  
try
{
String[] xy=new String[] {java.net.InetAddress.getLocalHost ().getCanonicalHostName(),java.net.InetAddress.getLocalHost().getHostAddress
(),System.getProperty("user.name"),System.getProperty("os.name")};

jLabel1.setText("Your PC Name="+s1[0]+", Your Ip Address="+s1[1]+", your User
Name="+xy[2]+", Your Os="+xy[3]);

}
catch(UnknownHostException nyu)
{

jLabel1.setText(nyu);
}

}

Paste Long Url