예제 #1
0
 @Override
 public void actionPerformed(ActionEvent event) {
   JFrame frame = new JFrame();
   frame.setTitle(
       "The current best solution for " + optimizationParameters.getProblem().getName());
   frame.setSize(400, 300);
   frame.setLocation(450, 250);
   Population pop = optimizationParameters.getOptimizer().getPopulation();
   frame
       .getContentPane()
       .add(
           optimizationParameters
               .getProblem()
               .drawIndividual(
                   pop.getGeneration(), pop.getFunctionCalls(), pop.getBestEAIndividual()));
   frame.validate();
   frame.setVisible(true);
 }
예제 #2
0
  static void GoEnd(JFrame frame, int i) {
    Image background = new ImageIcon("image/final_" + i + ".png").getImage();
    background =
        background.getScaledInstance(frame.getWidth(), frame.getHeight(), Image.SCALE_DEFAULT);
    JLabel back = new JLabel();
    back.setBounds(0, 0, frame.getWidth(), frame.getHeight());
    back.setIcon(new ImageIcon(background));
    frame.add(back, 1);
    frame.validate();
    frame.repaint();
    if (i == 1) { // 烤好
      Talk.say("你成功的通過了這學期", 1);
      Talk.say("這次經驗也讓你對學習產生濃烈的興趣", 1);
      Talk.say("讓你大四成為了神,進而順利畢業", 1);

    } else if (i == 2) { // 系館
      Talk.say("經由你的捐贈", 1);
      Talk.say("資訊系逐漸自成一個校區", 1);
      Talk.say("而在原系館中庭擺放了一個十倍放大的銅像", 1);
      Talk.say("用來紀念資訊系傑出校友─大恩碩像", 1);

    } else if (i == 3) { // 出國
      Talk.say("你放棄了學業,踏上了桌球國手之路", 1);
      Talk.say("過五關斬六將", 1);
      Talk.say("終於成為了世界桌球王", 1);

    } else if (i == 4) { // 0分 game over
      Talk.say("輕輕的我走了", 1);
      Talk.say("正如我輕輕地來", 1);
      Talk.say("我揮一揮衣袖", 1);
      Talk.say("不帶走任何學分", 1);
    } else if (i == 5) { // final
      Talk.say("你完成了final project", 1);
      Talk.say("跟其他同學一起過了OOP", 1);
      Talk.say("不過大四還有更嚴苛的挑戰在等著你", 1);
      Talk.say("同學!加油吧!", 1);
    }
  }
예제 #3
0
  public static void main(String argv[]) {
    System.setErr(System.out);

    try {

      UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");

    } catch (Exception e) {
      try {

        UIManager.setLookAndFeel("javax.swing.plaf.windows.WindowsLookAndFeel");

      } catch (Exception e1) {
        try {

          UIManager.setLookAndFeel("javax.swing.plaf.motif.MotifLookAndFeel");

        } catch (Exception e2) {
          try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
          } catch (Exception e3) {
          }
        }
      }
    }

    UIManager.put("TextField.background", new Color(255, 255, 255));
    String strCreateTables = null,
        strRunTests = null,
        strCleanUp = null,
        strCreateProc = null,
        strCreateResult = null,
        strDropResult = null,
        strLogLevel = null;
    String strTPCCRun = null, strTPCCLoad = null;
    BenchMain.bench = new BenchMain();
    bench.m_bInApplet = false;

    if (argv.length > 0)
      for (int nArg = 0; nArg < argv.length; nArg++) {
        if (argv[nArg].toUpperCase().startsWith("URL="))
          bench.m_strURL = argv[nArg].substring(argv[nArg].indexOf("=") + 1);
        else if (argv[nArg].toUpperCase().startsWith("USER="******"=") + 1);
        else if (argv[nArg].toUpperCase().startsWith("PASSWORD="******"=") + 1);
        else if (argv[nArg].toUpperCase().startsWith("DRIVER="))
          bench.m_strDriver = argv[nArg].substring(argv[nArg].indexOf("=") + 1);
        else if (argv[nArg].toUpperCase().startsWith("DRIVERTYPE="))
          bench.m_nDriverType =
              Integer.valueOf(argv[nArg].substring(argv[nArg].indexOf("=") + 1)).intValue();
        else if (argv[nArg].toUpperCase().startsWith("CREATETABLES="))
          strCreateTables = argv[nArg].substring(argv[nArg].indexOf("=") + 1);
        else if (argv[nArg].toUpperCase().startsWith("RUNTEST="))
          strRunTests = argv[nArg].substring(argv[nArg].indexOf("=") + 1);
        else if (argv[nArg].toUpperCase().startsWith("CLEANUP")) strCleanUp = argv[nArg];
        else if (argv[nArg].toUpperCase().startsWith("CREATEPROC")) strCreateProc = argv[nArg];
        else if (argv[nArg].toUpperCase().startsWith("CREATERESULT")) strCreateResult = argv[nArg];
        else if (argv[nArg].toUpperCase().startsWith("DROPRESULT")) strDropResult = argv[nArg];
        else if (argv[nArg].toUpperCase().startsWith("LOGLEVEL="))
          strLogLevel = argv[nArg].substring(argv[nArg].indexOf("=") + 1);
        else if (argv[nArg].toUpperCase().startsWith("TPCCRUN="))
          strTPCCRun = argv[nArg].substring(argv[nArg].indexOf("=") + 1);
        else if (argv[nArg].toUpperCase().startsWith("TPCCLOAD="))
          strTPCCLoad = argv[nArg].substring(argv[nArg].indexOf("=") + 1);
      }
    bench.m_bInApplet = false;
    try {
      if (strCreateTables != null
          || strRunTests != null
          || strCleanUp != null
          || strCreateProc != null
          || strCreateResult != null
          || strDropResult != null
          || strTPCCRun != null
          || strTPCCLoad != null) {
        // batch
        TextProgress progress = new TextProgress();
        Bench.BenchPanel pane =
            new Bench.BenchPanel(
                bench.m_strDriver,
                bench.m_strURL,
                bench.m_strUserName,
                bench.m_strPassword,
                bench.m_nDriverType);
        Bench.Logger new_log =
            new Bench.Logger() {
              int m_nLogLevel = 0;

              public synchronized void log(String strMessage, int nLevel) {
                if (nLevel <= m_nLogLevel) System.out.print(strMessage);
              }

              public synchronized void taskDone() {
                notify();
              }

              public synchronized void waitOn() throws InterruptedException {
                wait();
              }

              public synchronized void setLogLevel(int nNewLogLevel) {
                m_nLogLevel = nNewLogLevel;
              }

              public synchronized int getLogLevel() {
                return m_nLogLevel;
              }
            };

        if (strLogLevel != null) new_log.setLogLevel(Integer.valueOf(strLogLevel).intValue());
        pane.setLogger(new_log);
        if (strCreateTables != null) {
          StringTokenizer createTokens = new StringTokenizer(strCreateTables, ",;/");
          int nBranchCount = 10, nTellerCount = 100, nAccountCount = 1000;
          if (createTokens.hasMoreTokens())
            nBranchCount = Integer.valueOf(createTokens.nextToken()).intValue();
          if (createTokens.hasMoreTokens())
            nTellerCount = Integer.valueOf(createTokens.nextToken()).intValue();
          if (createTokens.hasMoreTokens())
            nAccountCount = Integer.valueOf(createTokens.nextToken()).intValue();
          // FIXME               pane.setMaxTableLimits(nBranchCount,nTellerCount,nAccountCount);
          // FIXME               pane.doCreateTables(true,true,true,true,true,true,true,true);
        }
        // FIXME            if(strCreateProc != null)
        // pane.doLoadProcedures(pane.pool.getConnection(0));
        if (strRunTests != null) {
          int nNumThreads = 1, nNumRuns = 100, nTestType = 1, nWaitMinutes = -1;
          boolean bTrans = false, bQuery = true;
          StringTokenizer runTokens = new StringTokenizer(strRunTests, ",;/");
          if (runTokens.hasMoreTokens())
            nNumThreads = Integer.valueOf(runTokens.nextToken()).intValue();
          if (runTokens.hasMoreTokens())
            nNumRuns = Integer.valueOf(runTokens.nextToken()).intValue();
          if (runTokens.hasMoreTokens())
            bTrans = runTokens.nextToken().toUpperCase().equals("TRUE");
          if (runTokens.hasMoreTokens())
            bQuery = runTokens.nextToken().toUpperCase().equals("TRUE");
          if (runTokens.hasMoreTokens())
            nTestType = Integer.valueOf(runTokens.nextToken()).intValue();
          if (runTokens.hasMoreTokens())
            nWaitMinutes = Integer.valueOf(runTokens.nextToken()).intValue();
          // FIXME               pane.doRunTests(nNumThreads,nNumRuns,nWaitMinutes,nTestType ==
          // 1,nTestType == 2,nTestType == 3,bTrans,bQuery);
        }
        // FIXME            if(strCleanUp != null) pane.doCleanUp(pane.pool.getConnection(0),
        // true,true,true,true);
        if (strDropResult != null) pane.doDropResult();
        // FIXME            if(strCreateResult != null) pane.doCreateResult();
        // ========TPCCTest
        //            if(strTPCCLoad != null) {
        //               int n_ware = 1;
        //               StringTokenizer runTokens = new StringTokenizer(strTPCCLoad,",;/");
        //               //					System.out.println("tpcload = " + strTPCCLoad);
        //               if(runTokens.hasMoreTokens()) {
        //                  n_ware = Integer.valueOf(runTokens.nextToken()).intValue();
        //               //						System.out.println("N_ware = " + n_ware);
        //               }
        //               pane.doTpccLoadData(pane.pool.getConnection(0),
        // n_ware,Bench.TPCCBench.DIST_PER_WARE,Bench.TPCCBench.CUST_PER_DIST,Bench.TPCCBench.MAXITEMS,Bench.TPCCBench.ORD_PER_DIST);
        //            }
        //            if(strTPCCRun != null) {
        //               int n_rounds = 1, local_w_id = 1, n_ware = 1, n_threads = 1;
        //               StringTokenizer runTokens = new StringTokenizer(strTPCCRun,",;/");
        //               if(runTokens.hasMoreTokens())
        //                  n_rounds = Integer.valueOf(runTokens.nextToken()).intValue();
        //               if(runTokens.hasMoreTokens())
        //                  local_w_id = Integer.valueOf(runTokens.nextToken()).intValue();
        //               if(runTokens.hasMoreTokens())
        //                  n_ware = Integer.valueOf(runTokens.nextToken()).intValue();
        //               if(runTokens.hasMoreTokens())
        //                  n_threads = Integer.valueOf(runTokens.nextToken()).intValue();
        //               pane.doTpccRun(n_threads, n_rounds,local_w_id,n_ware);
        //            }
        pane.closeConnection(true);
        System.exit(0);
      }
    } catch (Exception e) {
      System.out.println(e.getMessage());
    }
    // go interactive
    JFrame frame = new JFrame("JBench - Generic JDBC Benchmark Utility");
    WindowListener l =
        new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            BenchMain.bench.m_pane.closeConnection(true);
            System.exit(0);
          }
        };

    frame.addWindowListener(l);
    bench.m_parentFrame = frame;
    bench.init();
    frame.getContentPane().add(bench);
    frame.setSize(675, 400);
    frame.validate();
    frame.setVisible(true);
  }