Unknown

import java.lang.reflect.*;

public class MethodInspector {
public static void main(String[] arguments) {
Class inspect;
try {
if (arguments.length > 0)
inspect = Class.forName(arguments[0]);
else
inspect = Class.forName("MethodInspector");
Method[] methods = inspect.getDeclaredMethods();
for (int i = 0; i < methods.length; i++) {
Method methVal = methods[i];
Class returnVal = methVal.getReturnType();
int mods = methVal.getModifiers();
String modVal = Modifier.toString(mods);
Class[] paramVal = methVal.getParameterTypes();
StringBuffer params = new StringBuffer();
for (int j = 0; j < paramVal.length; j++) {
if (j > 0)
params.append(", ");
params.append(paramVal[j].getName());
}
System.out.println("Method: " + methVal.getName() + "()");
System.out.println("Modifiers: " + modVal);
System.out.println("Return Type: " + returnVal.getName());
System.out.println("Parameters: " + params + "\n");
}
} catch (ClassNotFoundException c) {
System.out.println(c.toString());
}
}
}
Unknown

Using Runtime.exec()

This example will capture the output (from stdio) of an external program.

import java.io.*;
public class CmdExec {

public static void main(String argv[]) {
try {
String line;
Process p = Runtime.getRuntime().exec
(System.getenv("windir") +"\\system32\\"+"tree.com /A");
BufferedReader input =
new BufferedReader
(new InputStreamReader(p.getInputStream()));
while ((line = input.readLine()) != null) {
System.out.println(line);
}
input.close();
}
catch (Exception err) {
err.printStackTrace();
}
}
}
The next example, launch CMD.EXE, grab stdin/stdout and push to stdin command to be interpreted by the shell.
    String line;
OutputStream stdin = null;
InputStream stderr = null;
InputStream stdout = null;

// launch EXE and grab stdin/stdout and stderr
Process process = Runtime.getRuntime ().exec ("/folder/exec.exe");
stdin = process.getOutputStream ();
stderr = process.getErrorStream ();
stdout = process.getInputStream ();

// "write" the parms into stdin
line = "param1" + "\n";
stdin.write(line.getBytes() );
stdin.flush();

line = "param2" + "\n";
stdin.write(line.getBytes() );
stdin.flush();

line = "param3" + "\n";
stdin.write(line.getBytes() );
stdin.flush();

stdin.close();

// clean up if any output in stdout
BufferedReader brCleanUp =
new BufferedReader (new InputStreamReader (stdout));
while ((line = brCleanUp.readLine ()) != null) {
//System.out.println ("[Stdout] " + line);
}
brCleanUp.close();

// clean up if any output in stderr
brCleanUp =
new BufferedReader (new InputStreamReader (stderr));
while ((line = brCleanUp.readLine ()) != null) {
//System.out.println ("[Stderr] " + line);
}
brCleanUp.close();

Launch a Windows CMD (or BAT) file and retrieve the errorlevel or exitcode

// win xp
import java.io.*;
public class CmdExec {
public static void main(String argv[]) {
try {
String line;
Process p = Runtime.getRuntime().exec("test.cmd");
p.waitFor();
System.out.println(p.exitValue());
}
catch (Exception err) {
err.printStackTrace();
}
}
}
test.cmd (set the errorlevel manually)
@echo hello world
@exit 42
test.cmd (set the errorlevel 1 (problem detected)
@java -garbage
test.cmd (set the errorlevel 0 (execution Ok)
@java -version

Launch a Unix script

String[] cmd = {"/bin/sh", "-c", "ls > hello"};
Runtime.getRuntime().exec(cmd);

Using the ProcessBuilder

Since 1.5, the ProcessBuilder class provides more controls overs the process to be started. It's possible to set a starting directory.

import java.io.*;
import java.util.*;

public class CmdProcessBuilder {
public static void main(String args[])
throws InterruptedException,IOException
{
List command = new ArrayList();
command.add(System.getenv("windir") +"\\system32\\"+"tree.com");
command.add("/A");

ProcessBuilder builder = new ProcessBuilder(command);
Map environ = builder.environment();
builder.directory(new File(System.getenv("temp")));

System.out.println("Directory : " + System.getenv("temp") );
final Process process = builder.start();
InputStream is = process.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String line;
while ((line = br.readLine()) != null) {
System.out.println(line);
}
System.out.println("Program terminated!");
}
}

Windows rundll32 utility

Windows File association
Any program using the Windows file association mechanism can be started with the rundll32 utility.
// "file" is the filename of the data file
// ex. myresume.doc
// to start Word if the doc extension is associated with it.
Runtime.getRuntime().exec
("rundll32 SHELL32.DLL,ShellExec_RunDLL " + file.getAbsolutePath());

See also this HowTo about the new Desktop API, the recommended solution (but you need JDK1.6).
See also this one to open the default browser.

The following example start a Dial-up connection on the Win plateform :

[Dialup.java]
public class Dialup {
public static void main(String[] args) throws Exception {
Process p = Runtime.getRuntime()
.exec("rundll32.exe rnaui.dll,RnaDial MyConnection");
p.waitFor();
System.out.println("Done.");
}
}
The "MyConnection" is the DUN and it's case sensitive.

You still need to press ENTER to CONNECT, there is an option in the Connection properties to connect automatically.

On NT and W2K, rnaui.dll is not available. Use rasdial.exe instead.

rasdial "connection name"
rasdial "connection name" /d to drop
rasdial /? for more options

PDF (Windows only)

public class ShowPDF {
public static void main(String[] args) throws Exception {
Process p =
Runtime.getRuntime()
.exec("rundll32 url.dll,FileProtocolHandler c:/pdf/mypdf.pdf");
p.waitFor();
System.out.println("Done.");
}
}

PDF (Mac only)

public class ShowPDF {
public static void main (String[] args) throws Exception{
Process p = Runtime.getRuntime().exec("open /Documents/mypdf.pdf");
}
}

More runddl32 examples


Path to executable with spaces in them

You can include a path for the program to be executed. On the Win plateform, you need to put the path in quotes if the path contains spaces.


public class Test {
public static void main(String[] args) throws Exception {
Process p = Runtime.getRuntime().exec(
"\"c:/program files/windows/notepad.exe\"");
p.waitFor();
}
}

If you need to pass arguments, it's safer to a String array especially if they contain spaces.

String[] cmd = { "myProgram.exe", "-o=This is an option" };
Runtime.getRuntime().exec(cmd);
If using the start command and the path of the file to be started contains a space then you must specified a title to the start command.
String fileName = "c:\\Applications\\My Documents\\test.doc";
String[] commands = {"cmd", "/c", "start", "\"DummyTitle\"",fileName};
Runtime.getRuntime().exec(commands);

VBSCRIPT

// Win9x
Runtime.getRuntime().exec("start myscript.vbs");

// WinNT
Runtime.getRuntime().exec("cmd /c start myscript.vbs");

or

// with a visible console
Runtime.getRuntime().exec("cscript myscript.vbs");

// with no visible console
Runtime.getRuntime().exec("wscript myscript.vbs");

HTML Help (Windows only)

Runtime.getRuntime().exec("hh.exe myhelpfile.chm");

Start Excel

import java.io.IOException;

class StartExcel {
public static void main(String args[])
throws IOException
{
Runtime.getRuntime().exec("cmd /c start excel.exe");
}
}
To load a worksheet
import java.io.IOException;

class StartExcel {
public static void main(String args[])
throws IOException
{
String fileName = "c:\\temp\\xls\\test2.xls";
String[] commands = {"cmd", "/c", "start", "\"DummyTitle\"",fileName};
Runtime.getRuntime().exec(commands);
}
}
It's important to pass a dummy title to the Windows start command where there is a possibility that the filename contains a space. It's a feature.

Start a Windows application under another account

You use the RUNAS command from the command line to start an application under another account (not available with XP Home edition). There are many switches that can enhance the behaviour of RUNAS. Typing "runas /?" from the command prompt gets you all the options.
  String  commands [] = new String [] {
"CMD.EXE",
"/C",
"RUNAS /profile /savecred /user:"
+ "administrator"
+ " " + "regedit.exe"
};

Runtime.getRuntime().exec(commands);
/SaveCred option allows you to save a password for that account and then reuse it later. For example, The command runas /savecred /user:administrator regedit.exe prompts for the password, and then Regedit runs. Next time you use the same command, there is no password prompt.

One potential problem is that when /SaveCred saves the credentials it saves it for whenever RUNAS invokes that user account. This can be a huge security risk so be careful using it!

RUNAS capability can be disabled by editing the Registry or by disabling the RUNAS or Secondary Logon Services. The appropriate registry key is HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\policies\Explorer, create a new DWORD value named HideRunAsVerb and assign it a value of 1 to disable Run as.

RUNAS doesn't work when used from a Windows service.

Windows : execute something in Program Files

We want to execute the textpad editor located in C:\Program Files\TextPad 4 but without hard coding the path since it can be different for a localized version of Windows.

We simply extract to environnment variable called %programfiles% and build the complete path from there.

[JDK1.5]

public class Exec {
static String WIN_PROGRAMFILES = System.getenv("programfiles");
static String FILE_SEPARATOR = System.getProperty("file.separator");

public static void main(String[] args) throws Exception {
String[] commands =
{"cmd.exe",
"/c",
WIN_PROGRAMFILES
+ FILE_SEPARATOR
+ "textpad 4"
+ FILE_SEPARATOR + "textpad.exe"};
Runtime.getRuntime().exec(commands);
}
}
Unknown
A quick note about these two assertions, let's start with positive lookahead:



"Assert that the regex below can be matched, starting at this position".



Let's go with this little example:



Regex:

\s+\w+(?=\.)



This would mean, match a space between one and many times followed by a word character between one an many times only if there is a dot following the previous match:



Eg.

andy mypass ok orange..see what is going on



The matched text here would be orange (Because there was a dot after "orange", ah yes, and many spaces before).



Now, let's go with the other case, negative lookahead:

"Assert that it is impossible to match the regex below starting at this position".

The regex changes to

\s+\w+(?!\.)



Do you see the difference?. this should read now:



Match a space between one and many times followed by a word character between one and many times only if the following character is not a dot, so what is matched now using our previous example:





mypass (Because after "mypass" was a space)

ok (Same reason using the word "ok")

orang (Because after "orang" there is an e)

see (Because after "see" there is a space)

.... and so on
Unknown

Horizontal Scrolling Menu made with CSS and jQuery


There are a lot of cool flash scrolling menus out there, but I decided to make a similarly looking menu with just CSS and jQuery. I couldn’t achieve the same smoothness in animation, but anyway I’m really satisfied with the result. My menu works fine in all major browsers and degrades gracefully when Javascript is turned off.

In case you need a vertical version of a scrolling menu, please go to my newer tutorial.


Unknown
Ứng dụng và slide giới thiệu javafx cho thực tập nhận thưc








http://www.mediafire.com/?idzxddtr3ma
Unknown
Code Th_Java của tui bài 13 trở về sau edit lại của J
bài 6 thì mới đầu code như sau

public String[] tenSo_arr = { "Không", "Một", "Hai", "Ba", "Bốn", "Năm", "Sáu",
"Bảy", "Tám", "Chín" };
public String[] donVi_arr = { "", "Mười", "Trăm" };
public String[] donViKhong_arr = { "", "Lẻ", "" };
public String[] donViNgan_arr = { "", "Ngàn", "Triệu", "Tỷ"};
public String docSoSangChu(long so) {
StringBuffer strBuff = new StringBuffer();
int i = 0, j = 0, k = 0;
long tmp = so;
int prev=0;//so truoc so hien tai 1 so
boolean check=false; //kiem tra xem da doc so nao !0 chua
while (tmp != 0) {
i = (char) (tmp % 10);
if(i!=0) check=true;
if (j == 3) {// neu bang 3 tang he so don vi *1000
j = 0;
if(k==3)k=1;else k++;
strBuff.insert(0, " " + donViNgan_arr[k]);
}
// doc don vi
if (i != 0||(j==2&&check)) {
strBuff.insert(0, " " + donVi_arr[j]);
} else {
if(prev!=0)strBuff.insert(0, " " + donViKhong_arr[j]);//han che doc khi co 2 so ko lien tuc
}
// doc chu so
// neu bang ko thi ko doc hoac neu =1 vd 211 thi doc 2 tram muoi mot
// nen ko can doc
if ((i!=0||(j==2&&check))&& !(i == 1 && j == 1)) {
strBuff.insert(0," "+ tenSo_arr[i]);
}
tmp = tmp / 10;
j++;
prev=i;
}
return strBuff.toString();

}

cái này đọc số nhỏ cũng tốt nhưng số lớn hơi chuối nên chuyển qua code này

package Phan1;

public class bai6 {
// main
public int[] a;
public String[] tenSo_arr = { "Không", "Một", "Hai", "Ba", "Bốn", "Năm", "Sáu",
"Bảy", "Tám", "Chín" };
public String[] donViNgan_arr = { "", "Ngàn", "Triệu", "Tỷ"};

public static void main(String[] args) {
bai6 b = new bai6();
System.out.println(b.docSoSangChu("190000001"));
System.out.println(b.docSoSangChu("1900000000"));
System.out.println(b.docSoSangChu("90000"));
System.out.println(b.docSoSangChu("1001001"));
System.out.println(b.docSoSangChu("1000001"));
System.out.println(b.docSoSangChu("100"));
System.out.println(b.docSoSangChu("2111"));
System.out.println(b.docSoSangChu("551231"));
System.out.println(b.docSoSangChu("199999999999900"));

do {
try {
System.out.println(b.docSoSangChu(Libary.NhapString(" nhap so can doi")));
} catch (NumberFormatException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

} while (Libary.IsContinue());

}

public String docSoSangChu(String str)throws NumberFormatException {
System.out.print(str+" :");
StringBuffer strBuff = new StringBuffer();
int currentValue = 0, k = 0,j=0;
Boolean check=false;//kiem tra xem da doc so nao khac ko chua
Boolean check2=false;//kiem tra xem da doc so nao khac ko trong bo 3 so chua
for (int i = str.length()-1; i>=0; i--,j++) {
currentValue=str.charAt(i)-48;
if(currentValue!=0) check=check2=true;
if(currentValue <0&¤tValue>9) throw new NumberFormatException(" Ko phai la so");
switch (j) {
case 2:
if(currentValue==0){
if(check2)
strBuff.insert(0, " "+ tenSo_arr[0]+" Trăm");
check2=false;
}
else strBuff.insert(0, " Trăm");
break;
case 1:
if(currentValue==0){
if(str.charAt(i+1)!=48) strBuff.insert(0, " lẻ");
}else if (currentValue==1){
strBuff.insert(0, " Mười");
continue;
}else {
strBuff.insert(0, " Mươi");
}
break;
case 3 :
if(k==3){
k=1;check=false;
}k++;
j=0;

if(currentValue!=0){
strBuff.insert(0, " "+ donViNgan_arr[k]);
}else {
if(check){
if( (i-2)>=0&&str.charAt(i-1)==48&& str.charAt(i-2)==48){
strBuff.insert(0, " "+ tenSo_arr[0]+" "+ donViNgan_arr[k]);
}else {
strBuff.insert(0, " "+ donViNgan_arr[k]);
}
}else {
if( (i-2)<0){
strBuff.insert(0, " "+ donViNgan_arr[k]);
}else if (str.charAt(i-1)!=48|| str.charAt(i-2)!=48){
strBuff.insert(0, " "+ donViNgan_arr[k]);
}
}
}
case 0:
if(currentValue==1 &&(i-1)>=0&&str.charAt(i-1)!=48&&str.charAt(i-1)!=49){
strBuff.insert(0, " Mốt");
continue;
}
break;
}
if(currentValue!=0) {

strBuff.insert(0," " +tenSo_arr[currentValue]);
}

}

return strBuff.toString();
}
}



Đọc rất chi là pro


190000001 : Một Trăm Chín Mươi Triệu Không Ngàn Không Trăm lẻ Một

1900000000 : Một Tỷ Chín Trăm Triệu

90000 : Chín Mươi Ngàn

1900 : Một Ngàn Chín Trăm

1000001 : Một Triệu Không Ngàn Không Trăm lẻ Một

100 : Một Trăm

2111 : Hai Ngàn Một Trăm Mười Một

551231 : Năm Trăm Năm Mươi Mốt Ngàn Hai Trăm Ba Mươi Mốt

199999999999900 : Một Trăm Chín Mươi Chín Triệu Chín Trăm Chín Mươi Chín Tỷ Chín Trăm Chín Mươi Chín Triệu Chín Trăm Chín Mươi Chín Ngàn Chín Trăm


Đây là code phần 1

bài 6 mình có sửa 1 tí các bạn lấy code thì update lại nhé
Code
Unknown

Các hàm cho Unicode chữ Việt

Dưới đây là Listing của một Sub và 13 hàm (Functions) dùng để xử lý Unicode chữ Việt. Ðể hiểu thêm về Unicode và nhất là cách hoán chuyển giữa UTF-16 và UTF-8 xin đọc bài Căn bản Unicode cho VB6 Programers.
http://www.vovisoft.com/unicode/UniFunctions.htm