如何在.net中获得JAVA应用程序的控件句柄

如何在.net中获得JAVA应用程序的控件句柄,第1张

API函数的声明就不说了。

先用findwindow找到窗体,用GetWindow和GetClassName获得其窗体内各对象的句柄,从而可以获得文本框的句柄。

最后用SendMessage函数想文本框发送文本。

tWnd = FindWindow(vbNullString, "窗口名")可以获得外部程序窗口的句柄twnd bwnd = GetWindow(tWnd, GW_CHILD)可以获得该窗口子对象的集合句柄bwnd !

使用JPanel.getComponents()方法,可以JPanel上的组件的数组,然后再对组件 *** 作就可以了,运行如下程序会看到效果。

import java.awt.*

import javax.swing.*

public class GetComponentsTest extends JFrame {

private Container buttonpanel

public GetComponentsTest() {

super("GetcomponetsTest")

String[] button = { "按钮A", "按钮B", "按钮C", "按钮D", "按钮E", "按钮F" }

buttonpanel = getContentPane()

buttonpanel.setLayout(new GridLayout(1, 6))

for (int x = 0x <6x++) {

buttonpanel.add(new JButton(button[x]))

}

setSize(640, 60)

setVisible(true)

}

public static void main(String[] args) {

GetComponentsTest test = new GetComponentsTest()

Component[] com = test.getContentPane().getComponents()

for(int i=0i<6i++){

((JButton)com[i]).setFont(new Font("隶书",Font.ITALIC,20 ))

((JButton)com[i]).setForeground(Color.RED)

}

}

}


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/11263479.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-14
下一篇 2023-05-14

发表评论

登录后才能评论

评论列表(0条)

保存