请问java是否可以做像金山词霸那样的屏幕取字功能?高分请教 请教高手。怎样用java做像像金山词霸那样的屏幕取字功能。最好有源代码。讲讲思路也行。我是一学生,不会c++/c,请问有java能做吗?谢谢指教。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 要俘获到java编写GUI以外的内容需要利用jni方法调用操作系统API才能实现 用java做像像金山词霸那样的屏幕取字功能。可以做java+ajax可以做 <script type="text/javascript">var xmlHttp; //用于保存XMLHttpRequest对象的全局变量var wordCache = new Array(); //用于缓存已查过的单词//获取选中的文本function getselection(e) { var txt = ""; //用于保存选中文本 //根据不同浏览器支持的方式获取选中的文本 if (window.getSelection) { txt = window.getSelection(); } else if (document.getSelection) { txt = document.getSelection(); } else if (document.selection) { txt = document.selection.createRange().text; } else { return; } //如果选中的文本不为空字符串,则向服务器查询单词信息 if (txt != "") { loadExplain(txt); } return false; //取消原有的上下文菜单显示}//用于创建XMLHttpRequest对象function createXmlHttp() { //根据window.XMLHttpRequest对象是否存在使用不同的创建方式 if (window.XMLHttpRequest) { xmlHttp = new XMLHttpRequest(); //FireFox、Opera等浏览器支持的创建方式 } else { xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");//IE浏览器支持的创建方式 }}//在单词解释div中显示传入的内容function displayExplain(content, isLoading, word) { explainDiv.innerHTML = content; //将内容写入explainDiv //当信息不是加载过程的提示信息时,将获取的单词解释写入缓存数组 if (!isLoading) { wordCache[word] = content; }}//从服务器加载单词的解释function loadExplain(word) { var explainDiv = document.getElementById("explainDiv"); //获取explainDiv对象 //如果缓存中存在需要加载的单词解释,直接从缓存读取 if(wordCache[word]){ explainDiv.innerHTML = wordCache[word]; return; //从缓存读取后终止函数调用 } displayExplain("正在加载……", true); //显示“正在加载……”提示信息 createXmlHttp(); //创建XMLHttpRequest对象 xmlHttp.onreadystatechange = function() { if (xmlHttp.readyState == 4) { displayExplain(xmlHttp.responseText, false, word); //显示获取到的单词解释 } }; xmlHttp.open("GET", "online_dict.jsp?word=" + word, true); xmlHttp.send(null);}//当打开上下文菜单时(即点击鼠标右键时),调用getselection函数document.oncontextmenu = getselection;</script> <%! //查询数据库返回单词解释 String getExplain(String word) { String explain = null; //存放信息信息 String sql = "select chinese from words where word = ?"; //定义查询数据库的SQL语句 Connection conn = null; //声明Connection对象 PreparedStatement pstmt = null; //声明PreparedStatement对象 ResultSet rs = null; //声明ResultSet对象 try { conn = DBUtils.getConnection(); //获取数据库连接 pstmt = conn.prepareStatement(sql); //根据sql创建PreparedStatement pstmt.setString(1, word); //设置参数 rs = pstmt.executeQuery(); //执行查询,返回结果集 if (rs.next()) { explain = rs.getString(1); } } catch (SQLException e) { System.out.println(e.toString()); } finally { DBUtils.close(rs); //关闭结果集 DBUtils.close(pstmt); //关闭PreparedStatement DBUtils.close(conn); //关闭连接 } return explain; }%><% out.clear(); //清空当前的输出内容(空格和换行符) String word = request.getParameter("word"); //获取word参数 String explain = getExplain(word); //调用getExplain方法获取关键词详细信息 //当解释存在时写入响应体 if (explain != null) { out.print(word + ":" + explain); }%> 呵呵lz 我的分记在你那哈 java+ajax做的对于屏幕取词你稍微修改以下就可以了我做的是鼠标选定单词的 http://blog.sina.com.cn/s/blog_4b6047bc01000ayn.html后面有后续文章继续介绍 代码:http://blogs.sun.com/Swing/resource/dictionary_experiment.zip http://hi.csdn.net/xiyuan1999xiyuan1999 jackie2004 http://hi.csdn.net/xiyuan1999 xiyuan1999怎么了啊 有什么问题吗? 要依赖操作系统的API吧 关于 java 与苹果 一個關於JDBC的問題 一个关于Java传参的简单问题,困扰了我很久。。 ascii 码问题已经困扰我两天了 最近装了JAVA 3D 导入以后出了点问题 记事本程序 请问JAVA操作PDF的问题 QueryDataSet几种方法的使用? 关于JBUIIDER7中JDBC开发问题 sos:高分求软件(逐个付分)以及注册码。。。。。。 笔试问题 如何调用另一个文件?
var xmlHttp; //用于保存XMLHttpRequest对象的全局变量
var wordCache = new Array(); //用于缓存已查过的单词//获取选中的文本
function getselection(e) {
var txt = ""; //用于保存选中文本 //根据不同浏览器支持的方式获取选中的文本
if (window.getSelection) {
txt = window.getSelection();
} else if (document.getSelection) {
txt = document.getSelection();
} else if (document.selection) {
txt = document.selection.createRange().text;
} else {
return;
} //如果选中的文本不为空字符串,则向服务器查询单词信息
if (txt != "") {
loadExplain(txt);
}
return false; //取消原有的上下文菜单显示
}//用于创建XMLHttpRequest对象
function createXmlHttp() {
//根据window.XMLHttpRequest对象是否存在使用不同的创建方式
if (window.XMLHttpRequest) {
xmlHttp = new XMLHttpRequest(); //FireFox、Opera等浏览器支持的创建方式
} else {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");//IE浏览器支持的创建方式
}
}//在单词解释div中显示传入的内容
function displayExplain(content, isLoading, word) {
explainDiv.innerHTML = content; //将内容写入explainDiv //当信息不是加载过程的提示信息时,将获取的单词解释写入缓存数组
if (!isLoading) {
wordCache[word] = content;
}
}//从服务器加载单词的解释
function loadExplain(word) {
var explainDiv = document.getElementById("explainDiv"); //获取explainDiv对象 //如果缓存中存在需要加载的单词解释,直接从缓存读取
if(wordCache[word]){
explainDiv.innerHTML = wordCache[word];
return; //从缓存读取后终止函数调用
} displayExplain("正在加载……", true); //显示“正在加载……”提示信息
createXmlHttp(); //创建XMLHttpRequest对象
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState == 4) {
displayExplain(xmlHttp.responseText, false, word); //显示获取到的单词解释
}
};
xmlHttp.open("GET", "online_dict.jsp?word=" + word, true);
xmlHttp.send(null);
}//当打开上下文菜单时(即点击鼠标右键时),调用getselection函数
document.oncontextmenu = getselection;
</script>
//查询数据库返回单词解释
String getExplain(String word) {
String explain = null; //存放信息信息 String sql = "select chinese from words where word = ?"; //定义查询数据库的SQL语句
Connection conn = null; //声明Connection对象
PreparedStatement pstmt = null; //声明PreparedStatement对象
ResultSet rs = null; //声明ResultSet对象
try {
conn = DBUtils.getConnection(); //获取数据库连接
pstmt = conn.prepareStatement(sql); //根据sql创建PreparedStatement
pstmt.setString(1, word); //设置参数
rs = pstmt.executeQuery(); //执行查询,返回结果集
if (rs.next()) {
explain = rs.getString(1);
}
} catch (SQLException e) {
System.out.println(e.toString());
} finally {
DBUtils.close(rs); //关闭结果集
DBUtils.close(pstmt); //关闭PreparedStatement
DBUtils.close(conn); //关闭连接
}
return explain;
}
%>
<%
out.clear(); //清空当前的输出内容(空格和换行符) String word = request.getParameter("word"); //获取word参数
String explain = getExplain(word); //调用getExplain方法获取关键词详细信息 //当解释存在时写入响应体
if (explain != null) {
out.print(word + ":" + explain);
}
%>
我的分记在你那哈 java+ajax做的对于屏幕取词你稍微修改以下就可以了我做的是鼠标选定单词的
后面有后续文章继续介绍
xiyuan1999
xiyuan1999怎么了啊 有什么问题吗?