主页面类(包装成了一个exe程序)
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
/**
* 脚本的主页面
* @author Serendipity
*/
public class Client extends JFrame implements ActionListener {
private JButton JStart; //定义程序开始按钮
private JButton JOver; //定义关闭客户端按钮
private JLabel Title; //定义客户端标题
private JTextField Note; //写一些废话
public Client(){
super("挂机专用"); //定义软件标题:挂机
this.setSize(600,500); // 定义软件边框大小
this.setLocation(600,300); //定义软件运行时初始位置
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); //当关闭这个窗口时,软件停止运行
Txt();
Button();
}
//写一些文字
public void Txt(){
Title = new JLabel("蒸汽机给爷爬");
this.add(Title);
Title.setBounds(200,50,200,100);
Title.setFont(new Font("宋体",Font.BOLD,25));
Note = new JTextField("因为按键精灵有广告,所以就自己做了一个 by:宁宁宁酱");
this.add(Note);
Note.setBounds(100,200,500,30);
Note.setFont(new Font("宋体",Font.BOLD,15));
Note.setEditable(false);
Note.setBorder(null);
}
//定义按钮
public void Button(){
setLayout(null);
JStart = new JButton("开始");
this.add(JStart);
JStart.setBounds(40,250,160,50);
JStart.setFont(new Font("宋体", Font.BOLD,20));
JStart.addActionListener(this); //键盘监听
JOver = new JButton("关闭");
this.add(JOver);
JOver.setBounds(380,250,160,50); //定义按钮位置,外汇经纪商买卖价http://www.fx61.com/quotesbuy.html
JOver.setFont(new Font("宋体", Font.BOLD,20));
JOver.addActionListener(this); //键盘监听
this.setVisible(true);
}
/**
* Invoked when an action occurs.
*
* @param e
*/
@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource() == JStart) {
this.dispose();
try {
Circulation circulation = new Circulation();
} catch (AWTException ex) {
ex.printStackTrace();
}
}
if(e.getSource() == JOver){
System.exit(0);
}
}
}
下面是核心,Robot类,让电脑按空格,中间设置了延迟
import java.awt.*;
import java.awt.event.KeyEvent;
/**
* 定义让电脑自动按下空格
* @author Serendipity
*/
public class Script {
Robot robot = new Robot();
public Script() throws AWTException {
robot.keyPress(KeyEvent.VK_SPACE);
robot.keyRelease(KeyEvent.VK_SPACE);
robot.delay(100);
}
}
循环
import java.awt.*;
/**
* 定义循环结构
* @author Serendipity
*/
public class Circulation {
private boolean flag = true;
public Circulation() throws AWTException {
while(flag){
Script script = new Script();
}
}
}
启动
/**
* 运行启动
* @author Serendipity
*/
public class Menu {
public static void main(String[] args){
Client client = new Client();
}
}
|
|