TA的每日心情 | 开心 2021-3-12 23:18 |
---|
签到天数: 2 天 [LV.1]初来乍到
|
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class RobotDemo extends JFrame implements ActionListener{
RobotDemo(String title){
super(title);
addWindowListener(new WindowAdapter(){
public void windowCloseing(WindowEvent e){
System.exit(0);
}
});
JPanel p=new JPanel();
JButton b=new JButton("Press Me");
b.addActionListener(this);
p.add(b);
getContentPane().add(p);
setSize(175,100);
setVisible(true);
}
public void actionPerformed(ActionEvent e){
try{
Runtime.getRuntime().exec("c:\windows\Notepad.exe");//打开记事本
}catch(java.io.IOException e1){
System.out.println(e1);
}
try{
Thread.sleep(1000);
}catch(InterruptedException e2){}
try{
Robot r=new Robot();
int keys[]={
KeyEvent.VK_T,
KeyEvent.VK_E,
KeyEvent.VK_X,
KeyEvent.VK_T,
KeyEvent.VK_ENTER};
for(int i=0;i<keys.length;i++){
r.keyPress(keys);
r.keyRelease(keys);
}//在记事本中输入text后,回车换行
Toolkit tk=Toolkit.getDefaultToolkit();
Dimension dim=tk.getScreenSize();
r.mouseMove(dim.width/2,dim.height/2);//鼠标移到屏幕中心
}catch(AWTException e3){}
}
public static void main(String args[]){
new RobotDemo("Robot Demo");
}
} |
|