校赛送气球程序1.1版
来源:互联网 发布:淘宝主宝贝副宝贝意思 编辑:程序博客网 时间:2024/06/04 00:22
在忙碌了一个下午。。。好吧,其实就一个小时差不多。。。
下午主要在搞python的重写。。。期待吧,哈哈,我要做一个用wxPython写的具有登录查阅代码能力的“送气球程序”。。。目测刚刚实现了登录功能,剩下的抓取页面之类的,又得去重翻RE模块的知识了。。。求别混乱。。最担心把linux的万用符和正则表达式弄乱了。。。好悲催
言归正传,原本打算重构整个代码的(表示今年3月份写的代码,现在来看就有点吃力了。。。终于知道重构有多重要了!!!!!)然后发现好烦。。。刚好python学的有点多了,所以,果断决定结束java版的发布了~~~好悠哉,吼吼~
好吧,献上源代码。也可以直接点击此处下载。
下午主要在搞python的重写。。。期待吧,哈哈,我要做一个用wxPython写的具有登录查阅代码能力的“送气球程序”。。。目测刚刚实现了登录功能,剩下的抓取页面之类的,又得去重翻RE模块的知识了。。。求别混乱。。最担心把linux的万用符和正则表达式弄乱了。。。好悲催
言归正传,原本打算重构整个代码的(表示今年3月份写的代码,现在来看就有点吃力了。。。终于知道重构有多重要了!!!!!)然后发现好烦。。。刚好python学的有点多了,所以,果断决定结束java版的发布了~~~好悠哉,吼吼~
好吧,献上源代码。也可以直接点击此处下载。
为毛源代码多了好多import。。。。因为队友说,jdk版本更新了,你就完蛋了,哈哈~果断不能直接就 import * 的说~
import java.awt.Button;import java.awt.Checkbox;import java.awt.Color;import java.awt.FlowLayout;import java.awt.Font;import java.awt.Frame;import java.awt.Label;import java.awt.Menu;import java.awt.MenuBar;import java.awt.MenuItem;import java.awt.TextArea;import java.awt.TextField;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.ItemEvent;import java.awt.event.ItemListener;import java.awt.event.WindowAdapter;import java.awt.event.WindowEvent;import java.io.BufferedReader;import java.io.File;import java.io.FileNotFoundException;import java.io.FileReader;import java.io.FileWriter;import java.io.IOException;import java.io.InputStreamReader;import java.io.PrintWriter;import java.net.MalformedURLException;import java.net.URL;import java.util.Arrays;import java.util.logging.Level;import java.util.logging.Logger;import javax.swing.JPopupMenu;class InShe { int num; private String str[]; InShe() { str = new String[200]; num = 0; } public void setM(String str, int c) { this.str[c] = str; } public String getM(int c) { return str[c]; } public int To(String st) { int i; for (i = 0; i < num; i++) { if (str[i].compareTo(st) == 0) { return i; } } str[num] = st; num++; SaveMap(); return num - 1; } public void SaveMap() {//sava map.txt over. PrintWriter pw = null; try { pw = new PrintWriter(new FileWriter("map.txt")); for (int i = 0; i < num; i++) { pw.println(str[i] + " " + i); } } catch (IOException ex) { System.out.println("Error in SaveMap!"); } finally { pw.close(); } }}class Catch extends Frame { InShe Is; static boolean stop, isset; static boolean stuAC[][][] = new boolean[200][20][2];//stuAC[][][0]==true-> AC stuAC[][][1]==true sended. static String seaid = new String("user_id=");//search the user_id static String seapr = new String("problem_id=");//search the problem_id static int col; Button bgt, bcl, bur, cnl; Label lur, lac; TextArea tf; TextField tur, tb, cnt_user, cnt_id, cnt_c; String urlName = new String("http://10.7.18.82/JudgeOnline/status?contest_id=1136&result=0"); MenuBar mb; MenuItem mire, mihp; Menu mu; // Checkbox cb; Label cl; // JPopupMenu pop; Catch() { super("Balloon Robot"); stop = true; isset = false; Is = new InShe(); cb = new Checkbox(); cl = new Label("AUTO"); lur = new Label("Enter your web:"); lac = new Label("The List of AC"); tur = new TextField(urlName, 50); cnt_user = new TextField("", 12); cnt_id = new TextField("", 4); cnt_c = new TextField("", 4); tur.selectAll(); tf = new TextArea(25, 70); tb = new TextField("1000", 4); bgt = new Button("Get"); bcl = new Button("Balloon"); bur = new Button("Set"); cnl = new Button("Cancel"); cnt_c.setForeground(Color.WHITE); createMenu();//I'm so lazy...and it is 1:22 now . I just want to sleep. setLayout(new FlowLayout()); //add web name add(lur); add(tur); add(bur); add(cnl); //add cnt add(new Label("Current sending|User:")); add(cnt_user); add(new Label("Problem:")); add(cnt_id); add(new Label("Color:")); add(cnt_c); add(bcl); cnt_user.disable(); cnt_id.disable(); cnt_c.disable(); //add main //add(lac); add(bgt); //add(bcl); add(cl); add(tb); add(new Label("/ms")); add(cb); add(tf); //tf.hide(); tf.setFont(new Font("", 13, 15)); setVisible(true); setSize(600, 600);//change the size. //add actionListener bur.addActionListener(new Mint()); bgt.addActionListener(new Mint()); bcl.addActionListener(new Mint()); cb.addItemListener(new IL()); cnl.addActionListener(new Mint()); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) {//closing ,you should save the data.waiting... SaveData(); Is.SaveMap(); dispose(); System.exit(0); } }); } public void createMenu() {//only supply open , I'm so lazy, and I just want to sleep.quick !!! mb = new MenuBar(); mu = new Menu("File"); mire = new MenuItem("Resume"); mihp = new MenuItem("Help"); this.setMenuBar(mb); mu.add(mire); mu.add(mihp); mb.add(mu); mire.addActionListener(new MeL()); mihp.addActionListener(new MeL()); } public void SaveData() {//this is finish File fd = new File("data.txt"); PrintWriter pw = null; try { pw = new PrintWriter(new FileWriter(fd, false));// String Sa[] = tf.getText().split("\n");// for (int i = 0; i < Sa.length; i++) {// pw.println(Sa[i]);// } pw.println(tf.getText()); } catch (IOException e) { System.out.println(e.getMessage() + "Save data Error!"); } finally { pw.close(); } } public void Find(String str) {//Find the needed match string int i, j, k, user, pro = 0; int len = str.length(); for (i = 0; i < len - seaid.length(); i++) { if (str.substring(i).startsWith(seaid)) {//search user_id for (j = i + seaid.length(); j < len; j++) { if (str.charAt(j) == '>') { break; } } user = -1; String st = ""; for (j = j + 1; j < len; j++) { if (str.charAt(j) == '<') { break; } st += str.charAt(j) + ""; } if (st != null) { user = Is.To(st);//the same to map st = st + " ";//add the user_id } pro = -1; for (j = j + 1; j < len - seapr.length(); j++) {//search problem_id if (str.substring(j).startsWith(seapr)) { for (k = j + seapr.length();; k++) { if (str.charAt(k) == '>') { break; } } pro = str.charAt(k + 1) - 'A'; st += str.charAt(k + 1) + ""; break; } } if (user != -1 && pro != -1 && stuAC[user][pro][0] == false) {//Judge if there are same data. tf.append(st + "\n");//add the problem_id stuAC[user][pro][0] = true; } } } } public void GetColor(int a) throws IOException { URL url = Main.class.getClassLoader().getResource("color.txt"); BufferedReader bufer = new BufferedReader(new InputStreamReader(url.openStream(), "UTF-8")); String str; while ((str = bufer.readLine()) != null) { String sa[] = str.split("\t"); //System.out.println("***" + sa[0] + "****"); try { if (Integer.parseInt(sa[0]) == a) { str = sa[1]; break; } } catch (Exception e) { //nothing will happen! } } if (a == 0) { cnt_c.setBackground(Color.red); } else if (a == 1) { cnt_c.setBackground(Color.blue); } else if (a == 2) { cnt_c.setBackground(Color.green); } else if (a == 3) { cnt_c.setBackground(Color.yellow); } else if (a == 4) { cnt_c.setBackground(Color.black); } else if (a == 5) { cnt_c.setBackground(Color.cyan); } else if (a == 6) { cnt_c.setBackground(Color.darkGray); } else if (a == 7) { cnt_c.setBackground(Color.lightGray); } else if (a == 8) { cnt_c.setBackground(Color.magenta); } else { cnt_c.setBackground(Color.orange); } cnt_c.setText(str); } public void Get() { try { URL url = new URL(urlName); BufferedReader buf = new BufferedReader(new InputStreamReader(url.openStream())); String str; while ((str = buf.readLine()) != null) { //waiting ... I will come back and finish it. Find(str); } } catch (Exception ex) { System.out.println(ex.getClass() + " Get Error!"); } finally {//if there are some bug ,we can save the data first. SaveData(); Is.SaveMap(); } } class Mint implements ActionListener { public void actionPerformed(ActionEvent e) { if (e.getSource() == cnl) { tur.enable(); } else if (e.getSource() == bur) {//set finish~ urlName = tur.getText(); try { new URL(urlName); isset = true; } catch (MalformedURLException ex) { System.out.println("Connect failed!Check your url: " + urlName); } finally { SaveData(); } tur.disable(); } else if (!isset) { tur.setText("here input your url first!"); return; } else if (e.getSource() == bgt) {//get waiting... now is finished. Get(); } else if (e.getSource() == bcl) {//Clear finished. int __t = 0; String ac[] = tf.getText().split("\n"); tf.setText(""); for (int i = 0; i < ac.length; i++) { String two[] = ac[i].split(" +"); //System.out.println(ac[i]+"|"+two[0]+" "+two[1]); if (i == col) { stuAC[Is.To(two[0])][two[1].charAt(0) - 'A'][1] = true; cnt_user.setText(two[0]); cnt_id.setText(two[1]); try { GetColor(two[1].charAt(0) - 'A'); } catch (IOException ex) { Logger.getLogger(Catch.class.getName()).log(Level.SEVERE, null, ex); System.out.println("GetColor Error!!!"); } tf.append(ac[i] + " Sended\n"); __t = 1; } else { tf.append(ac[i] + "\n"); } } col = col + __t; SaveData(); return; } } } public void updata() { col = 0; File f = new File("data.txt"); File map = new File("map.txt"); BufferedReader bur; Main.init(); try { String str; bur = new BufferedReader(new FileReader(map)); while ((str = bur.readLine()) != null) { String cas[] = str.split(" +"); Is.setM(cas[0], Integer.parseInt(cas[1])); } bur = new BufferedReader(new FileReader(f)); tf.setText(""); while ((str = bur.readLine()) != null) { String cas[] = str.split(" +"); if (cas.length == 3) { col++; stuAC[Is.To(cas[0])][cas[1].charAt(0) - 'A'][0] = true; stuAC[Is.To(cas[0])][cas[1].charAt(0) - 'A'][1] = true; } else if (cas.length == 2) { stuAC[Is.To(cas[0])][cas[1].charAt(0) - 'A'][0] = true; } tf.append(str + "\n"); } } catch (Exception ex) { System.out.println(ex + "update Error"); } } public class MeL implements ActionListener {//I finish the open menuItem.Congratulations!!! public void actionPerformed(ActionEvent e) { if (e.getSource() == mire) { updata(); } else if (e.getSource() == mihp) { try { HelpYou helpYou = new HelpYou(); } catch (Exception ex) { Logger.getLogger(Catch.class.getName()).log(Level.SEVERE, null, ex); } } } } public class IL extends Thread implements ItemListener {//waiting to continue the thread public void itemStateChanged(ItemEvent e) { Clock c = new Clock("d"); if (cb.getState() == true) { c = new Clock(); c.start(); } else { c.Stop(); } } } class Clock extends Thread { boolean stat; Button btn; Clock() { stat = true; final Frame f = new Frame("clock"); btn = new Button("Stop"); btn.setSize(100, 200);//maybe useless! f.add(btn); btn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { stat = false; cb.setState(stat); f.dispose(); } }); f.setLayout(new FlowLayout()); f.setSize(100, 100); f.setVisible(true); } Clock(String str) { } public void run() { while (stat) { try { this.sleep(Integer.parseInt(tb.getText()));//change the time! Get(); } catch (InterruptedException ex) { System.out.println("run Error!"); } finally { SaveData(); Is.SaveMap(); } } } public void Stop() { if (this.isAlive()) { this.Stop(); } } } class HelpYou { HelpYou() throws FileNotFoundException, IOException { final Frame f = new Frame("Help you/me"); TextArea Nkn = new TextArea(40, 80); Nkn.setText(""); URL url = Main.class.getClassLoader().getResource("helpyou.txt"); BufferedReader bufer = new BufferedReader(new InputStreamReader(url.openStream())); try { String str; while ((str = bufer.readLine()) != null) { Nkn.append(str + "\n"); } } finally { bufer.close(); } f.add(Nkn); f.setLayout(new FlowLayout()); f.setSize(600, 400); f.setVisible(true); f.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) {//closing ,you should save the data.waiting... f.dispose(); } }); } }}public class Main { public static void init() { for (int i = 0; i < 200; i++) { for (int j = 0; j < 20; j++) { Arrays.fill(Catch.stuAC[i][j], 0, Catch.stuAC[i][j].length, false); } } Catch.col = 0; } public static void main(String[] args) { init(); Catch c = new Catch(); }}如有疑问,可以留言~
- 校赛送气球程序1.1版
- 校赛送气球程序1.2版
- 基于先前GUI小程序的拓展——校赛送气球机1.0版
- bnu1275 ACM--送气球 C语言版
- 日语中关于送气音和不送气音
- 日语中不送气音与送气音的用法
- 括号配对测试程序1.1版
- c程序 球
- 三维球动画程序
- raptor程序:三色球
- 校程序大赛
- 1.1程序框架
- 1.1程序的结构
- C#版五子棋程序
- 程序版吉祥三宝
- 程序版吉祥三宝:
- 程序版吉祥三宝
- 日历程序--升级版
- Shell Script中%、%%、#、##使用区别
- mysql数据迁移工具
- Android 控件之Spinner
- eclipse axis2 插件安装方法(不是 MyEclipse)
- Sql Server和Oracle的sql语句分页
- 校赛送气球程序1.1版
- Android的布局和Intent笔记和常用实例
- HTTP学习笔记之二——Web服务器
- 使用系统包DBMS_ALERT监视表
- 连接ORACLE 无监听程序
- 复制CODE小技巧
- Facebook怎样开发软件:工程师驱动的文化
- 带参数的main()函数
- HTTP学习笔记之三——Proxy代理服务器