这个小程序可以实现自动阅读我的文章,爽歪歪。
界面截图
代码
watch.java(main)
public class watch {
public static void main(String arg[]){
new Windows();
}
}
Windows.java
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class Windows implements ActionListener{
JFrame jfrm = new JFrame();
JPanel jp_total = new JPanel(new BorderLayout());//边界布局
JPanel jp_1 = new JPanel();
JLabel lab = new JLabel("浏览数量:",JLabel.CENTER);
JTextField jxf = new JTextField(10);//文本框长度为10
JButton jbtn = new JButton("开始");//查找按钮
public Windows(){
jfrm.setVisible(true);//窗体可见
jfrm.setTitle("😀");//窗口标题
jfrm.setSize(200,100);//设置了一个长为200,高为100的框图。
jfrm.setLocation(240,135);//设置一个左上角顶点在(240,135)的窗体。
jfrm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//关闭窗口的时候退出程序
jfrm.add(jp_total);
jp_total.add(jp_1);
//jp_1.add(lab);
//jp_1.add(jxf);
jp_1.add(jbtn);
jbtn.addActionListener(this);
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
Object eventSource = e.getSource();
// TODO Auto-generated method stub
if(eventSource == jbtn)//开始
{
System.out.print("开始\n");
new Webpage();
}
}
}
Webpage.java
import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.KeyEvent;
public class Webpage {
public Webpage(){
Robot robot;
String url[] = new String[] {
"https://blog.csdn.net/qq_44544908/article/details/122890893?spm=1001.2014.3001.5502",
"https://blog.csdn.net/qq_44544908/article/details/122912321?spm=1001.2014.3001.5502",
"https://blog.csdn.net/qq_44544908/article/details/122916490?spm=1001.2014.3001.5502",
"https://blog.csdn.net/qq_44544908/article/details/122916590?spm=1001.2014.3001.5502",
"https://blog.csdn.net/qq_44544908/article/details/122917216?spm=1001.2014.3001.5502",
"https://blog.csdn.net/qq_44544908/article/details/123036846?spm=1001.2014.3001.5502",
"https://blog.csdn.net/qq_44544908/article/details/123051234?spm=1001.2014.3001.5502",
"https://blog.csdn.net/qq_44544908/article/details/123315928?spm=1001.2014.3001.5502",
"https://blog.csdn.net/qq_44544908/article/details/123340477?spm=1001.2014.3001.5502",
"https://blog.csdn.net/qq_44544908/article/details/123425214?spm=1001.2014.3001.5502",
"https://blog.csdn.net/qq_44544908/article/details/123426799?spm=1001.2014.3001.5502",
"https://blog.csdn.net/qq_44544908/article/details/123561949?spm=1001.2014.3001.5502",
"https://blog.csdn.net/qq_44544908/article/details/123595635?spm=1001.2014.3001.5502",
"https://blog.csdn.net/qq_44544908/article/details/123604651?spm=1001.2014.3001.5502",
"https://blog.csdn.net/qq_44544908/article/details/123748935?spm=1001.2014.3001.5502",
"https://blog.csdn.net/qq_44544908/article/details/123810079?spm=1001.2014.3001.5502",
"https://blog.csdn.net/qq_44544908/article/details/123911643?spm=1001.2014.3001.5502",
"https://blog.csdn.net/qq_44544908/article/details/123947747?spm=1001.2014.3001.5502",
"https://blog.csdn.net/qq_44544908/article/details/123989015?spm=1001.2014.3001.5502",
"https://blog.csdn.net/qq_44544908/article/details/124004005?spm=1001.2014.3001.5502",
"https://blog.csdn.net/qq_44544908/article/details/124003987?spm=1001.2014.3001.5502"
};
try {
for(int i = 0; i < url.length;i++) {
String Url = url[i];
System.out.print(Url+"\n");
java.net.URI uri = java.net.URI.create(Url);
// 获取当前系统桌面扩展
java.awt.Desktop dp = java.awt.Desktop.getDesktop();
if (dp.isSupported(java.awt.Desktop.Action.BROWSE)) {
dp.browse(uri);// 获取系统默认浏览器打开链接
}
try {
Thread.sleep(500);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
robot = new Robot();
robot.keyPress(KeyEvent.VK_CONTROL); //按下ctrl
robot.keyPress(KeyEvent.VK_W); //按下w
robot.keyRelease(KeyEvent.VK_W); //松开w
robot.keyRelease(KeyEvent.VK_CONTROL); //松开ctrl
} catch (AWTException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
} catch (java.lang.NullPointerException e) {
// 此为uri为空时抛出异常
e.printStackTrace();
} catch (java.io.IOException e) {
// 此为无法获取系统默认浏览器
e.printStackTrace();
}
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/104992.html