日期:2014-05-20  浏览次数:20684 次

java打开一个IE后......
在java中打开一个IE后,我现在想在打开的IE的地址里自动输入我在程度中预设好的一个地址,然后IE通过这个地址后进入到另一个窗口后,在新打开的那个窗口里的文本框里也自动输入一些值,然后再自动点击窗口中的确定按钮。请问这个可以实现的吗?有的请说说!
另,我想知道在JAVA中如何才能在某一个特定的时间里运行一个JAVA程序??

如果提供的方法是可行的。分绝对给分。同时也可以再加分。

------解决方案--------------------
1.关于使用系统IE,需要JDK.1.6具体代码如下,实现原理应该是JNI,所以不是所有系统都支持的
2.定时执行程序都是有个后台进程的,TIMER类可以实现,如果需要的功能比较大,建议用开源的QUARTZ
package csdn;

import java.awt.Desktop;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.UIManager;
/**
* java.awt.Desktop类可获得操作平台的桌面系统,以便使用系统默认浏览器、编辑器、邮件、打印等。
* Java1.6.0实现调用操作平台桌面系统
* Desktop类将获得操作平台的桌面系统,以便使用系统默认浏览器、编辑器、邮件、打印等
* 一堆按钮摆在一起不大好看,懒的布局了,大家能看明白就成,打开文件、编辑文件和打印文件需要先按“浏览”按钮,选择一个文件后才行。
*
* @author 五斗米 <如转载请保留作者和出处>
* @blog http://blog.csdn.net/mq612
*/
class Desktoptest extends JFrame {
private JPanel pane = null;
private JLabel label = null; // 显示信息的标签
private JButton [] button = null; // 启动平台默认程序的按钮
private Desktop desktop = null; // 本操作平台的桌面系统实例
private JTextField text = null; // 显示文件地址的TextField
private JButton b = null; // 浏览文件的按钮
private JFileChooser fc = null; // 需要浏览文件
private File file = null; // 文件

public Desktoptest() {
super( "Java1.6.0实现调用操作平台桌面系统 ");
try {
// 将LookAndFeel设置成Windows样式
UIManager.setLookAndFeel( "com.sun.java.swing.plaf.windows.WindowsLookAndFeel ");
} catch (Exception ex) {
ex.printStackTrace();
}
fc = new JFileChooser();
pane = new JPanel();
label = new JLabel( "本操作平台不支持桌面系统 "); // 默认标签文字为不支持
pane.add(label);
button = new JButton[5];
button[0] = new JButton( "默认浏览器 ");
button[1] = new JButton( "默认邮件 ");
button[2] = new JButton( "默认程序打开文件 ");
button[3] = new JButton( "默认程序编辑文件 ");
button[4] = new JButton( "打印文件 ");
for(int i = 0; i < button.length; i++){ // 使按钮暂不可用
button[i].setEnabled(false);
}
pane.add(button[0]);
pane.add(button[1]);
text = new JTextField(30);
text.setEditable(false); // 不可编辑
b = new JButton( "浏览 "); // 使按钮暂不可用
b.setEnabled(false);
pane.add(text);
pane.add(b);
pane.add(button[2]);
pane.add(button[3]);
pane.add(button[4]);
desktop = Desktop.getDesktop(); // 返回本操作平台的桌面系统
if(desktop.isDesktopSupported()){ // 如果该操作平台支持桌面系统
this.desktop();
}
this.getContentPane().add(pane);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(400, 200);
this.setVisible(true);
}
/**
* 桌面系统
*/
private void desktop(){
label.setText( "本操作平台支持桌面系统 ");
for(int i = 0; i < button.length; i++){ // 使按钮可用
button[i].setEnabled(true);
}
b.setEnabled(true);
b.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
openFile();