Search
Sponsors
Sponsors

Archive for the ‘System’ Category

Copy to clipboard

Thursday, August 25th, 2011

 

Clipboard clip = Toolkit.getDefaultToolkit().getSystemClipboard();
                    ImageTransferable imageTrans = new ImageTransferable(bufferImage);
                    clip.setContents(imageTrans, null);

Keyboard input

Thursday, August 25th, 2011

 

import java.io.*;

public class ReadString {

   public static void main (String[] args) {

      //  prompt the user to enter their name
      System.out.print("Enter your name: ");

      //  open up standard input
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

      String userName = null;

      //  read the username from the command-line; need to use try/catch with the
      //  readLine() method
      try {
         userName = br.readLine();
      } catch (IOException ioe) {
         System.out.println("IO error trying to read your name!");
         System.exit(1);
      }

      System.out.println("Thanks for the name, " + userName);

   }

}  // end of ReadString class

Send SMS using SMSMatrix

Thursday, August 25th, 2011

 

try
{
String MATRIXURL = "http://www.smsmatrix.com/matrix";
String PHONE = "12506063167";
String USERNAME = "user@hotmail.com";
String PASSWORD = "pass72727";
String TXT = "This is a test, pls ignore";

String q = "username=" + URLEncoder.encode (USERNAME, "UTF-8");
q += "&" + "password=" + URLEncoder.encode (PASSWORD, "UTF-8");
q += "&" + "phone=" + PHONE;
q += "&" + "txt=" + URLEncoder.encode (TXT, "UTF-8");

URL url = new URL (MATRIXURL);
URLConnection conn = url.openConnection();
conn.setDoOutput (true);
OutputStreamWriter wr = new OutputStreamWriter (conn.getOutputStream());
wr.write (q);
wr.flush();
   
BufferedReader rd = new BufferedReader (new InputStreamReader (conn.getInputStream()));
String line;
System.out.println ("Matrix API Response :");
while ((line = rd.readLine()) != null) { System.out.println (line); }
wr.close();
rd.close();
} catch (Exception e) { }

Get JDK version

Tuesday, February 24th, 2009

/**
 * @(#)test.java
 * test application
 */
import java.io.*;

public class test
{
   
    public static void main(String[] args)
    {
  String version = System.getProperty(”java.version”);
        System.out.println(”JDK version installed is “+ version);

    }

}

On my system I had

JDK version installed is 1.6.0_12

Get the user name

Tuesday, February 24th, 2009

/**
 * @(#)test.java
 * test application
 */
import java.io.*;

public class test
{
   
    public static void main(String[] args)
    {
  String name = System.getProperty(”user.name”);
        System.out.println(name);
    }

}

System properties

Tuesday, February 24th, 2009

/**
 * @(#)test.java
 * test application
 */
import java.io.*;

public class test
{
   
    public static void main(String[] args)
    {
  System.getProperties().list(System.out);
    }

}

here is part of  the output from my machine

os.name=Windows XP
sun.jnu.encoding=Cp1252
java.library.path=C:\Program Files\Java\jdk1.6.0_12\bin…
java.specification.name=Java Platform API Specification
java.class.version=50.0

Translate