導航:首頁 > 編程語言 > java調用介面傳參數類型

java調用介面傳參數類型

發布時間:2025-06-28 13:09:54

java調用GetWindowRect怎麼傳參數

GetWindowRect方法的完整描述


booleancom.sun.jna.platform.win32.User32.GetWindowRect(HWNDarg0,RECTarg1)

Note:couldbefound.

傳入的參數是HWND 窗口的句柄 ,根據你自己的需求傳入窗口句柄

User32INSTANCE=(User32)Native.loadLibrary(User32.class,W32APIOptions.UNICODE_OPTIONS);
HWNDhwnd=User32.INSTANCE.FindWindow("yourWindowClassName","yourWindowName");//參數是:窗口的類,和窗口的標題
//這兩個參數,至少一個不為null

// RECT 參數,可以提前構造一個 ,代碼如下

WinDef.RECTrect=newWinDef.RECT();

最後調用GetWindowRect方法

User32.INSTANCE.GetWindowRect(hwnd,rect);//最後獲取到的數據都存在了rect裡面,可以取出來用
intmyWidth=rect.right-rect.left;//右頂點-左頂點=寬
intmyHight=rect.bottom-rect.top;//下頂點-上頂點=高

⑵ Java中的形參和實參的區別以及傳值調用和傳

1.形參:用來接收調用該方法時傳遞的參數。只有在被調用的時候才分配內存空間,一旦調用結束,就釋放內存空間。因此僅僅在方法內有效。

2.實參:傳遞給被調用方法的值,預先創建並賦予確定值。

3.傳值調用:傳值調用中傳遞的參數為基本數據類型,參數視為形參。

4.傳引用調用:傳引用調用中,如果傳遞的參數是引用數據類型,參數視為實參。在調用的過程中,將實參的地址傳遞給了形參,形參上的改變都發生在實參上。

案例分析:

1.基礎數據類型(傳值調用)

傳值,方法不會改變實參的值。

2.引用數據類型(引用調用)

傳引用,方法體內改變形參引用,不會改變實參的引用,但有可能改變實參對象的屬性值。

舉兩個例子:

(1)方法體內改變形參引用,但不會改變實參引用 ,實參值不變。

⑶ java HttpPost怎麼傳遞參數

public class HttpURLConnectionPost {

/**

* @param args

* @throws IOException

*/

public static void main(String[] args) throws IOException {

readContentFromPost();

}

public static void readContentFromPost() throws IOException {

// Post請求的url,與get不同的是不需要帶參數

URL postUrl = new URL("http://www.xxxxxxx.com");

// 打開連接

HttpURLConnection connection = (HttpURLConnection) postUrl.openConnection();

// 設置是否向connection輸出,因為這個是post請求,參數要放在

// http正文內,因此需要設為true

connection.setDoOutput(true);

// Read from the connection. Default is true.

connection.setDoInput(true);

// 默認是 GET方式

connection.setRequestMethod("POST");

// Post 請求不能使用緩存

connection.setUseCaches(false);

//設置本次連接是否自動重定向

connection.setInstanceFollowRedirects(true);

// 配置本次連接的Content-type,配置為application/x-www-form-urlencoded的

// 意思是正文是urlencoded編碼過的form參數

connection.setRequestProperty("Content-Type","application/x-www-form-urlencoded");

// 連接,從postUrl.openConnection()至此的配置必須要在connect之前完成,

// 要注意的是connection.getOutputStream會隱含的進行connect。

connection.connect();

DataOutputStream out = new DataOutputStream(connection

.getOutputStream());

// 正文,正文內容其實跟get的URL中 '? '後的參數字元串一致

String content = "欄位名=" + URLEncoder.encode("字元串值", "編碼");

// DataOutputStream.writeBytes將字元串中的16位的unicode字元以8位的字元形式寫到流裡面

out.writeBytes(content);

//流用完記得關

out.flush();

out.close();

//獲取響應

BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));

String line;

while ((line = reader.readLine()) != null){

System.out.println(line);

}

reader.close();

//該乾的都幹完了,記得把連接斷了

connection.disconnect();

}

(3)java調用介面傳參數類型擴展閱讀:

關於Java HttpURLConnection使用

public static String sendPostValidate(String serviceUrl, String postData, String userName, String password){

PrintWriter out = null;

BufferedReader in = null;

String result = "";

try {

log.info("POST介面地址:"+serviceUrl);

URL realUrl = new URL(serviceUrl);

// 打開和URL之間的連接

URLConnection conn = realUrl.openConnection();

HttpURLConnection httpUrlConnection = (HttpURLConnection) conn;

// 設置通用的請求屬性

httpUrlConnection.setRequestProperty("accept","*/*");

httpUrlConnection.setRequestProperty("connection", "Keep-Alive");

httpUrlConnection.setRequestProperty("user-agent","Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");

httpUrlConnection.setRequestMethod("POST");

httpUrlConnection.setRequestProperty("Content-Type","application/json;charset=UTF-8");

Base64 base64 = new Base64();

String encoded = base64.encodeToString(new String(userName+ ":" +password).getBytes());

httpUrlConnection.setRequestProperty("Authorization", "Basic "+encoded);

// 發送POST請求必須設置如下兩行

httpUrlConnection.setDoOutput(true);

httpUrlConnection.setDoInput(true);

// 獲取URLConnection對象對應的輸出流

out = new PrintWriter(new OutputStreamWriter(httpUrlConnection.getOutputStream(),"utf-8"));

// 發送請求參數

out.print(postData);

out.flush();

// 定義BufferedReader輸入流來讀取URL的響應

in = new BufferedReader(new InputStreamReader(httpUrlConnection.getInputStream(),"utf-8"));

String line;

while ((line = in.readLine()) != null) {

result += line;

}

//

// if (!"".equals(result)) {

// BASE64Decoder decoder = new BASE64Decoder();

// try {

// byte[] b = decoder.decodeBuffer(result);

// result = new String(b, "utf-8");

// } catch (Exception e) {

// e.printStackTrace();

// }

// }

return result;

} catch (Exception e) {

log.info("調用異常",e);

throw new RuntimeException(e);

}

//使用finally塊來關閉輸出流、輸入流

finally{

try{

if(out!=null){

out.close();

}

if(in!=null){

in.close();

}

}

catch(IOException e){

log.info("關閉流異常",e);

}

}

}

}

⑷ 在java中傳遞參數的方法有幾種做簡要的說明

傳入的數據類型:基本類型是值拷貝,復雜類型(對象)則是引用傳版遞。
傳入的參數權個數:固定參數列表,可變參數列表(類似public static int add(int... i)這樣)

另外,傳遞參數時還可以定義泛型,類似這樣public <E> E get(Class<E> clazz, Long id)。目前只想到這些。。

閱讀全文

與java調用介面傳參數類型相關的資料

熱點內容
scratch編程怎麼畫曲線 瀏覽:995
分類信息網站叫什麼名字好 瀏覽:289
php刪除資料庫表 瀏覽:484
excel文件放桌面打不開 瀏覽:844
手機炫酷密碼 瀏覽:206
韓國人吃播用什麼社交app 瀏覽:77
哪個app可以測算生理安全期 瀏覽:629
cad家居圖源文件 瀏覽:612
hs網路用語什麼意思 瀏覽:462
手機流量不夠用如何打開資料庫 瀏覽:202
感測器用什麼編程的語言 瀏覽:615
如何成長電商行業數據分析 瀏覽:292
哪個app可以遠程一起看劇 瀏覽:307
手機rar解壓文件 瀏覽:581
哪些資料庫適合存儲長向量 瀏覽:280
重建資料庫日誌文件 瀏覽:83
ps文件存不上去怎麼辦 瀏覽:954
文件里的圖片照片怎麼弄清晰 瀏覽:577
文本按鈕和文件按鈕在哪裡顯示 瀏覽:661
java調用介面傳參數類型 瀏覽:739

友情鏈接