MainFrame.java
上传用户:hainatieta
上传日期:2019-07-13
资源大小:1076k
文件大小:6k
- package cn.seejava.lei2;
- import java.awt.Button;
- import java.awt.Toolkit;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.awt.event.WindowAdapter;
- import java.awt.event.WindowEvent;
- import java.io.BufferedReader;
- import java.io.FileReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import javax.swing.JButton;
- import javax.swing.JFrame;
- public class MainFrame extends JFrame implements ActionListener{
- public static final int width = 260;
- public static final int height = 150;
- JButton b1;
- Button b2;
- //File f = new File("config.ini");
- public MainFrame(){
- this.setBounds((getScreenWidth()-width)/2,(getScreenHeight()-height)/2,width,height);
- this.setTitle("CF刷雷者 CT13专版");
- b1 = new JButton("启动程序");
- b1.setBounds(50,15,150,40);
- b2 = new Button("参数设置");
- b2.setBounds(150, 78, 80, 30);
- this.setLayout(null);
- this.setResizable(false);
- this.add(b1);
- this.add(b2);
- b1.addActionListener(this);
- b2.addActionListener(this);
- this.setVisible(true);
- this.addWindowListener(new WinMoniter());
- }
- @Override
- public void actionPerformed(ActionEvent e) {
- // TODO Auto-generated method stub
- if(e.getActionCommand().equals("参数设置")){
- SetFrame mf = new SetFrame();
- }
- if(e.getActionCommand().equals("启动程序")){
- //应用配置文件 启动程序
- b1.setText("停止");
- b2.disable();
- applyConfig();
- }
- if(e.getActionCommand().equals("停止")){
- ReadyOwner.programeOn = false;
- overE2G();
- b1.setText("启动程序");
- b2.enable();
- }
- }
- private int getScreenWidth(){
- return Toolkit.getDefaultToolkit().getScreenSize().width;
- }
- private int getScreenHeight(){
- return Toolkit.getDefaultToolkit().getScreenSize().height;
- }
-
-
- public void applyConfig(){
- Moniter.programeOn = true;
- //先读取配置文件
- if(SetFrame.f.exists()){
- //直接加载
- try {
- FileReader fr = new FileReader(SetFrame.f);
- BufferedReader br = new BufferedReader(fr);
- String conf = null;
- if((conf=br.readLine())!=null){
- String str[] = conf.split(",");
- for(int i=0;i<str.length;i++){
- switch(i){
- case 0:
- if(Integer.parseInt(str[i])==0){
- //不需要自动准备
- ReadyOwner.autoReady = false;
- }else{
- ReadyOwner.autoReady = true;
- }
- break;
- case 1:
- if(Integer.parseInt(str[i])==0){
- //自动自杀
- ReadyOwner.noStop = false;
- }else{
- ReadyOwner.noStop = true;
- }
- break;
- case 2:
- if(Integer.parseInt(str[i])==0){
- ReadyOwner.changeTeam = false;
- }else{
- ReadyOwner.changeTeam = true;
- }
- break;
- case 3:
- if(Integer.parseInt(str[i])==0){
-
- ReadyOwner.sayF5 = false;
- }else{
- ReadyOwner.sayF5 = true;
- }
- break;
- case 4:
- if(Integer.parseInt(str[i])==0){
- ReadyOwner.autoStart = false;
- //this.add("one",cbg);
- }else{
- ReadyOwner.autoStart = true;
- }
- //cbg.add(jc5);
- break;
- case 5:
- switch(Integer.parseInt(str[i])){
- case 10:
- ReadyOwner.penum = 10;
- break;
- case 11:
- ReadyOwner.penum = 11 ;
- break;
- case 12:
- ReadyOwner.penum = 12 ;
- break;
- case 13:
- ReadyOwner.penum = 13 ;
- break;
- case 14:
- ReadyOwner.penum = 14 ;
- break;
- }
- break;
- case 6:
- switch(Integer.parseInt(str[i])){
- case 1:
- //不使用代理
- break;
- case 2:
- GoldHelp gh = new GoldHelp(1);
- Thread t1 = new Thread(gh);
- t1.start();
- //电信代理一
- break;
- case 3:
- GoldHelp gh1 = new GoldHelp(2);
- Thread t2 = new Thread(gh1);
- t2.start();
- //电信代理二
- break;
- }
- break;
- case 7:
- if(Integer.parseInt(str[i])==0){
- //三分钟OUT
- ReadyOwner.threeOut = false;
- }else{
- ReadyOwner.threeOut = true;
- }
- break;
- case 8:
- if(Integer.parseInt(str[i])==0){
- //自动快速加入
- ReadyOwner.fastJoin = false;
- }else{
- ReadyOwner.fastJoin = true;
- }
- }
- }
- }else{
- SetFrame.createConfig(SetFrame.defConfig);
- applyConfig();
- //JOptionPane.showMessageDialog(null, "加载配置文件出错");
- }
- } catch (NumberFormatException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
-
- }else{
- SetFrame.createConfig(SetFrame.defConfig);
- applyConfig();
- }
-
- }
- public void overE2G(){
- try {
- Process pro = Runtime.getRuntime().exec("cmd /c tasklist");
- BufferedReader br = new BufferedReader(new InputStreamReader(pro.getInputStream()));
- String task = "";
-
- while((task=br.readLine())!=null){
- if(task.indexOf("Easy2Game.exe")!=-1){
- Runtime.getRuntime().exec("taskkill /F /IM easy2game.exe");
- }
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- class WinMoniter extends WindowAdapter{
-
- @Override
- public void windowClosing(WindowEvent arg0) {
- overE2G();
- System.exit(0);
- }
-
- }
- }