/** Method declaration Adjust this method for large strings...ie multi megabtypes. */ void execute() { String sCmd = null; if (4096 <= ifHuge.length()) { sCmd = ifHuge; } else { sCmd = txtCommand.getText(); } if (sCmd.startsWith("-->>>TEST<<<--")) { testPerformance(); return; } String g[] = new String[1]; lTime = System.currentTimeMillis(); try { sStatement.execute(sCmd); lTime = System.currentTimeMillis() - lTime; int r = sStatement.getUpdateCount(); if (r == -1) { formatResultSet(sStatement.getResultSet()); } else { g[0] = "update count"; gResult.setHead(g); g[0] = String.valueOf(r); gResult.addRow(g); } addToRecent(txtCommand.getText()); } catch (SQLException e) { lTime = System.currentTimeMillis() - lTime; g[0] = "SQL Error"; gResult.setHead(g); String s = e.getMessage(); s += " / Error Code: " + e.getErrorCode(); s += " / State: " + e.getSQLState(); g[0] = s; gResult.addRow(g); } updateResult(); System.gc(); }
public void startScan(String mode) { pathfindStart = System.currentTimeMillis(); if (!gridSet) { grid.clearScan(); tracing = false; if (grid.scanStart(mode)) { gridSet = true; } } }
/** Update the status of the GUI based on any changes in the game object. */ private void updateStatus() { if (game.donePlacingShips()) { // Kill the ship highlight and disable the vertical/horizontal buttons. humanGrid.setHoverShape(null); hButton.setEnabled(false); vButton.setEnabled(false); } else { int len = game.placingLength(); boolean horiz = game.placingHorizontal(); humanGrid.setHoverShape(new Dimension(horiz ? len : 1, horiz ? 1 : len)); } message.setText(game.getStatus()); repaint(); }
private void setMouseAction() { addMouseListener( new MouseAdapter() { @Override public void mousePressed(MouseEvent arg0) { if (SwingUtilities.isLeftMouseButton(arg0)) { NewGrid.this.mousePressed(arg0.getX(), arg0.getY()); } else { rotate = !rotate; NewGrid.this.mouseMoved(arg0.getX(), arg0.getY()); } notifyObservers(); } @Override public void mouseExited(MouseEvent arg0) { restore(Cell.DEAD, Cell.WATER); notifyObservers(); } }); super.addMouseMotionListener( new MouseMotionAdapter() { @Override public void mouseMoved(MouseEvent arg0) { NewGrid.this.mouseMoved(arg0.getX(), arg0.getY()); } }); }
@Override protected void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D gfx = (Graphics2D) g; gfx.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); // Clear screen gfx.setColor(Constants.BACKGROUND_COLOR); gfx.fillRect(0, 0, getWidth(), getHeight()); // Render next frame grid.draw(gfx); // Trace path line if (tracing) { gfx.setColor(Constants.PATH_COLOR); gfx.setStroke(new BasicStroke(2)); for (int i = 1; i < pathLine.size(); i++) { Coordinate p = pathLine.get(i - 1); Coordinate n = pathLine.get(i); gfx.drawLine( (Constants.TILESIZE + Constants.MARGIN) * p.x + (Constants.TILESIZE / 2) + Constants.MARGIN, (Constants.TILESIZE + Constants.MARGIN) * p.y + (Constants.TILESIZE / 2) + Constants.MARGIN, (Constants.TILESIZE + Constants.MARGIN) * n.x + (Constants.TILESIZE / 2) + Constants.MARGIN, (Constants.TILESIZE + Constants.MARGIN) * n.y + (Constants.TILESIZE / 2) + Constants.MARGIN); } } }
/** * Method declaration * * @param r */ void formatResultSet(ResultSet r) { if (r == null) { String g[] = new String[1]; g[0] = "Result"; gResult.setHead(g); g[0] = "(empty)"; gResult.addRow(g); return; } try { ResultSetMetaData m = r.getMetaData(); int col = m.getColumnCount(); String h[] = new String[col]; for (int i = 1; i <= col; i++) { h[i - 1] = m.getColumnLabel(i); } gResult.setHead(h); while (r.next()) { for (int i = 1; i <= col; i++) { h[i - 1] = r.getString(i); if (r.wasNull()) { h[i - 1] = "(null)"; } } gResult.addRow(h); } r.close(); } catch (SQLException e) { } }
/** Method declaration */ private void initGUI() { Panel pQuery = new Panel(); Panel pCommand = new Panel(); pResult = new Panel(); pQuery.setLayout(new BorderLayout()); pCommand.setLayout(new BorderLayout()); pResult.setLayout(new BorderLayout()); Font fFont = new Font("Dialog", Font.PLAIN, 12); txtCommand = new TextArea(5, 40); txtCommand.addKeyListener(this); txtResult = new TextArea(20, 40); txtCommand.setFont(fFont); txtResult.setFont(new Font("Courier", Font.PLAIN, 12)); butExecute = new Button("Execute"); butClear = new Button("Clear"); butExecute.addActionListener(this); butClear.addActionListener(this); pCommand.add("East", butExecute); pCommand.add("West", butClear); pCommand.add("Center", txtCommand); gResult = new Grid(); setLayout(new BorderLayout()); pResult.add("Center", gResult); pQuery.add("North", pCommand); pQuery.add("Center", pResult); fMain.add("Center", pQuery); tTree = new Tree(); // (ulrivo): screen with less than 640 width Dimension d = Toolkit.getDefaultToolkit().getScreenSize(); if (d.width >= 640) { tTree.setMinimumSize(new Dimension(200, 100)); } else { tTree.setMinimumSize(new Dimension(80, 100)); } gResult.setMinimumSize(new Dimension(200, 300)); fMain.add("West", tTree); doLayout(); fMain.pack(); }
public void actionPerformed(ActionEvent e) { if (e.getSource().equals(save)) new GridSaver(grid, fileName()); if (e.getSource().equals(load)) { GridLoader gl = new GridLoader(grid, fileName()); try { grid.setMap(gl.read()); } catch (IOException ioex) { System.out.println("File load Failed ioex"); } } parent.getParent().refresh(); }
/** Method declaration */ void updateResult() { if (iResult == 0) { // in case 'help' has removed the grid if (bHelp) { pResult.removeAll(); pResult.add("Center", gResult); pResult.doLayout(); bHelp = false; } gResult.update(); gResult.repaint(); } else { showResultInText(); } txtCommand.selectAll(); txtCommand.requestFocus(); }
public void run() { long start, end, sleepTime; while (running) { start = System.currentTimeMillis(); if (gridSet) { grid.scanStep(); } repaint(); end = System.currentTimeMillis(); // Sleep to match FPS limit sleepTime = (1000 / framerate) - (end - start); if (sleepTime > 0) { try { Thread.sleep(sleepTime); } catch (InterruptedException e) { thread.interrupt(); } } } }
/** Method declaration */ void showResultInText() { String col[] = gResult.getHead(); int width = col.length; int size[] = new int[width]; Vector data = gResult.getData(); String row[]; int height = data.size(); for (int i = 0; i < width; i++) { size[i] = col[i].length(); } for (int i = 0; i < height; i++) { row = (String[]) data.elementAt(i); for (int j = 0; j < width; j++) { int l = row[j].length(); if (l > size[j]) { size[j] = l; } } } StringBuffer b = new StringBuffer(); for (int i = 0; i < width; i++) { b.append(col[i]); for (int l = col[i].length(); l <= size[i]; l++) { b.append(' '); } } b.append(NL); for (int i = 0; i < width; i++) { for (int l = 0; l < size[i]; l++) { b.append('-'); } b.append(' '); } b.append(NL); for (int i = 0; i < height; i++) { row = (String[]) data.elementAt(i); for (int j = 0; j < width; j++) { b.append(row[j]); for (int l = row[j].length(); l <= size[j]; l++) { b.append(' '); } } b.append(NL); } b.append(NL + height + " row(s) in " + lTime + " ms"); txtResult.setText(b.toString()); }
/** Method declaration */ void testPerformance() { String all = txtCommand.getText(); StringBuffer b = new StringBuffer(); long total = 0; for (int i = 0; i < all.length(); i++) { char c = all.charAt(i); if (c != '\n') { b.append(c); } } all = b.toString(); String g[] = new String[4]; g[0] = "ms"; g[1] = "count"; g[2] = "sql"; g[3] = "error"; gResult.setHead(g); int max = 1; lTime = System.currentTimeMillis() - lTime; while (!all.equals("")) { int i = all.indexOf(';'); String sql; if (i != -1) { sql = all.substring(0, i); all = all.substring(i + 1); } else { sql = all; all = ""; } if (sql.startsWith("--#")) { max = Integer.parseInt(sql.substring(3)); continue; } else if (sql.startsWith("--")) { continue; } g[2] = sql; long l = 0; try { l = DatabaseManagerCommon.testStatement(sStatement, sql, max); total += l; g[0] = String.valueOf(l); g[1] = String.valueOf(max); g[3] = ""; } catch (SQLException e) { g[0] = g[1] = "n/a"; g[3] = e.toString(); } gResult.addRow(g); System.out.println(l + " ms : " + sql); } g[0] = "" + total; g[1] = "total"; g[2] = ""; gResult.addRow(g); lTime = System.currentTimeMillis() - lTime; updateResult(); }
public void autoSetting() { super.autoSetting(); notifyObservers(); }
private void majgrid1(Player player) { gridtest = new Grid(); gridtest = player.getGridJoueur(); ShipType type = ShipType.AIRCRAFT_CARRIER; Ship ship = new Ship(type); Orientation orient = Orientation.HORIZONTAL; for (int i = 0; i < 10; i++) // ligne { for (int j = 0; j < 10; j++) // colonne { if (gridtest.getCell(i, j) instanceof OceanCell) { tabbout1[i][j].setIcon(iconeau); } // else if(gridtest.getCell(i, j) instanceof TouchOceanCell) // { // tabbout1[i][j].setIcon(iconeautouch); // } // else if(gridtest.getCell(i, j) instanceof TouchOceanCell) // { // tabbout1[i][j].setIcon(icondebristouch); // } else if (gridtest.getCell(i, j) instanceof ShipCell) { ship = ((ShipCell) gridtest.getCell(i, j)).getShip(); int size = ship.getSize(); orient = ((ShipCell) gridtest.getCell(i, j)).getOrient(); if (orient.isHorizontal()) { if (ship.getSize() == 2) { tabbout1[i][j].setIcon(iconsub1h); tabbout1[i][j + 1].setIcon(iconsub2h); tabbout1[i][j + 2].setIcon(iconsub3h); j = j + 2; } else if (ship.getSize() == 3) // battleship { tabbout1[i][j].setIcon(iconbattle1h); tabbout1[i][j + 1].setIcon(iconbattle2h); tabbout1[i][j + 2].setIcon(iconbattle3h); tabbout1[i][j + 3].setIcon(iconbattle4h); j = j + 3; } else { tabbout1[i][j].setIcon(iconair1h); tabbout1[i][j + 1].setIcon(iconair2h); tabbout1[i][j + 2].setIcon(iconair3h); tabbout1[i][j + 3].setIcon(iconair4h); tabbout1[i][j + 4].setIcon(iconair5h); j = j + 4; } } } } for (int i2 = 0; i2 < 10; i2++) // ligne { for (int j2 = 0; j2 < 10; j2++) // colonne { if (gridtest.getCell(i2, j2) instanceof ShipCell) { ship = ((ShipCell) gridtest.getCell(i2, j2)).getShip(); orient = ((ShipCell) gridtest.getCell(i2, j2)).getOrient(); if (!orient.isHorizontal()) { if (ship.getSize() == 2) { tabbout1[i2][j2].setIcon(iconsub1v); tabbout1[i2 + 1][j2].setIcon(iconsub2v); tabbout1[i2 + 2][j2].setIcon(iconsub3v); i2 = i2 + 2; } else if (ship.getSize() == 3) // battleship { tabbout1[i2][j2].setIcon(iconbattle1v); tabbout1[i2 + 1][j2].setIcon(iconbattle2v); tabbout1[i2 + 2][j2].setIcon(iconbattle3v); tabbout1[i2 + 3][j2].setIcon(iconbattle4v); i2 = i2 + 3; } else { tabbout1[i2][j2].setIcon(iconair1v); tabbout1[i2 + 1][j2].setIcon(iconair2v); tabbout1[i2 + 2][j2].setIcon(iconair3v); tabbout1[i2 + 3][j2].setIcon(iconair4v); tabbout1[i2 + 4][j2].setIcon(iconair5v); i2 = i2 + 4; } } } } } } }
public void clear() { if (!gridSet) { grid.clearAll(); tracing = false; } }