@Override public void run() { // TODO Auto-generated method stub while (true) { try { Thread.sleep(100); } catch (Exception e) { // TODO: handle exception } // 判断每一粒子弹和每一辆敌人的坦克都是否有重合(击中) for (int i = 0; i < hero.bombs.size(); i++) { // 取出每个子弹 Bomb myBomb = hero.bombs.get(i); // 子弹必须得存活才有判断的意义 if (myBomb.isLive) { for (int j = 0; j < ets.size(); j++) { // 取出每辆坦克 EnemyTank et = ets.get(j); if (et.isLive) { this.isHit(myBomb, et); } } } } this.repaint(); } }
// keyboard discovery code private void _mapKey(char charCode, int keyindex, boolean shift, boolean altgraph) { log("_mapKey: " + charCode); // if character is not in map, add it if (!charMap.containsKey(new Integer(charCode))) { log("Notified: " + (char) charCode); KeyEvent event = new KeyEvent( applet(), 0, 0, (shift ? KeyEvent.SHIFT_MASK : 0) + (altgraph ? KeyEvent.ALT_GRAPH_MASK : 0), ((Integer) vkKeys.get(keyindex)).intValue(), (char) charCode); charMap.put(new Integer(charCode), event); log("Mapped char " + (char) charCode + " to KeyEvent " + event); if (((char) charCode) >= 'a' && ((char) charCode) <= 'z') { // put shifted version of a-z in automatically int uppercharCode = (int) Character.toUpperCase((char) charCode); event = new KeyEvent( applet(), 0, 0, KeyEvent.SHIFT_MASK + (altgraph ? KeyEvent.ALT_GRAPH_MASK : 0), ((Integer) vkKeys.get(keyindex)).intValue(), (char) uppercharCode); charMap.put(new Integer(uppercharCode), event); log("Mapped char " + (char) uppercharCode + " to KeyEvent " + event); } } }
// This method is called when a request has been made to close a client connection public synchronized void disconnectClient(ClientConnection clientConnection) { // Ensures this connection exists (a necessary check when this is being called from outside of a // clientConnection) if (clientConnection != null && clientConnection.isConnected() && clientSocketList.get(clientSocketList.indexOf(clientConnection)) != null) { // Send the client a message telling it to close its socket clientConnection.xmitMessage(ClientConnection.QUIT); // Then close that socket...the user really doesn't have a choice. We're just asking to be // nice. clientSocketList.get(clientSocketList.indexOf(clientConnection)).closeSocket(); parent.updateStatusBox( clientSocketList.indexOf(clientConnection) + " " + "Forcing disconnection of client " + clientConnection.id + " on port " + port + "..."); } else { // If this thread is NOT connected, it may be stuck, so let's send an interrupt to wake it up clientThreadList.get(clientSocketList.indexOf(clientConnection)).interrupt(); parent.updateStatusBox("Closing listen socket on port " + port + "..."); } }
public int submit() { String newName = produktgruppeFormular.nameField.getText(); if (isProdGrAlreadyKnown(newName)) { // not allowed: changing name to one that is already registered in DB JOptionPane.showMessageDialog( this, "Fehler: Produktgruppe '" + newName + "' bereits vorhanden!", "Info", JOptionPane.INFORMATION_MESSAGE); produktgruppeFormular.nameField.setText(""); return 0; } Integer parentProdGrID = produktgruppeFormular.parentProdGrIDs.get( produktgruppeFormular.parentProdGrBox.getSelectedIndex()); Vector<Integer> idsNew = produktgruppeFormular.idsOfNewProdGr(parentProdGrID); Integer topID = idsNew.get(0); Integer subID = idsNew.get(1); Integer subsubID = idsNew.get(2); Integer mwstID = produktgruppeFormular.mwstIDs.get(produktgruppeFormular.mwstBox.getSelectedIndex()); Integer pfandID = produktgruppeFormular.pfandIDs.get(produktgruppeFormular.pfandBox.getSelectedIndex()); return insertNewProdGr(topID, subID, subsubID, newName, mwstID, pfandID); }
// ParserListener methods public void noteEvent(Note note) { if (layer >= staves) { return; } // System.out.println(note.getMusicString() + " " + note.getMillisDuration() + " " + // note.getDecimalDuration()); Vector<Chord> currChords = chords[layer]; Iterator<NotePanel> currNote = currNotes[layer]; if (!currNote.hasNext()) { System.err.println("Received noteEvent, but no PostScript notes are left"); return; } if (note.getMillisDuration() > 0) { NotePanel notePanel = currNote.next(); // time the last chord ended long tempTime = 0; for (int i = currChords.size() - 1; i >= 0; --i) { if (!currChords.get(i).isTie()) { tempTime = currChords.get(i).getTime() + currChords.get(i).getDuration(); break; } } if (notePanel.isTie) { Chord chord = new Chord(); // for each note in the last chord, set the next note as a tied note for (int i = 0; i < currChords.lastElement().size(); ++i) { notePanel.setTie(true).setTime(Math.min(tempTime, time - 1)).setTempo(tempo); chord.addNote(notePanel); notePanel = currNote.next(); } currChords.add(chord); } while (notePanel.isRest) { notePanel .setTime(Math.min(tempTime, time - 1)) // hack, in case the rest should be trimmed .setTempo(tempo); tempTime += notePanel.getDuration(); Chord chord = new Chord(notePanel); currChords.add(chord); // System.out.println("REST: " + notePanel.getMusicString() + " " + // notePanel.getDuration()); notePanel = currNote.next(); } notePanel.setNote(note).setTime(time).setTempo(tempo); if (currChords.isEmpty() || currChords.lastElement().getTime() != time) { Chord chord = new Chord(notePanel); currChords.add(chord); } else { currChords.lastElement().addNote(notePanel); } } }
/** * Show a dialog for printing the current drawing. * * @param fff the parent frame which will be used for dialogs and message boxes. * @param CCr the CircuitPanel containing the drawing to be exported. */ public void printDrawing(JFrame fff, CircuitPanel CCr) { cc = CCr; DialogPrint dp = new DialogPrint(fff); dp.setMirror(printMirror); dp.setFit(printFitToPage); dp.setBW(printBlackWhite); dp.setLandscape(printLandscape); dp.setVisible(true); // Get some information about the printing options. printMirror = dp.getMirror(); printFitToPage = dp.getFit(); printLandscape = dp.getLandscape(); printBlackWhite = dp.getBW(); Vector<LayerDesc> ol = cc.dmp.getLayers(); if (dp.shouldPrint()) { if (printBlackWhite) { Vector<LayerDesc> v = new Vector<LayerDesc>(); // Here we create an alternative array of layers in // which all colors are pitch black. This may be // useful for PCB's. for (int i = 0; i < LayerDesc.MAX_LAYERS; ++i) v.add( new LayerDesc( new ColorSwing(Color.black), ((LayerDesc) ol.get(i)).getVisible(), "B/W", ((LayerDesc) ol.get(i)).getAlpha())); cc.dmp.setLayers(v); } PrinterJob job = PrinterJob.getPrinterJob(); job.setPrintable(this); boolean ok = job.printDialog(); if (ok) { try { PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet(); // Set the correct printing orientation. if (printLandscape) { aset.add(OrientationRequested.LANDSCAPE); } else { aset.add(OrientationRequested.PORTRAIT); } job.print(aset); } catch (PrinterException ex) { // The job did not successfully complete JOptionPane.showMessageDialog(fff, Globals.messages.getString("Print_uncomplete")); } } cc.dmp.setLayers(ol); } }
/** * Establishes combo box editor for 'from onramp' column. * * @param clmn */ private void setUpToOnrampColumn() { JComboBox combo = new JComboBox(); Vector<AbstractNetworkElement> nes = ((AbstractControllerComplex) controller).getMyMonitor().getSuccessors(); for (int i = 0; i < nes.size(); i++) if ((nes.get(i).getType() & TypesHWC.MASK_LINK) > 0) combo.addItem(nes.get(i)); TableColumn clmn = zonetab.getColumnModel().getColumn(3); clmn.setCellEditor(new DefaultCellEditor(combo)); clmn.setCellRenderer(new DefaultTableCellRenderer()); return; }
@SuppressWarnings("unchecked") private void exportBtnActionPerformed(java.awt.event.ActionEvent evt) { toggle(false); JFileChooser fc = new JFileChooser(); String path = FileUtils.getUserDirectoryPath() + File.separator + treeViewNode.getText() + ".csv"; fc.setSelectedFile(new File(path)); fc.showSaveDialog(this); File target = fc.getSelectedFile(); int row = model.getRowCount(); try { boolean written; try (FileOutputStream fos = new FileOutputStream(target)) { while (--row > -1) { Vector v = (Vector) model.getDataVector().get(row); for (int i = 0; i < v.size(); i++) { if (v.get(i).toString().contains(",")) { v.set(i, ST.format("\"<%1>\"", v.get(i))); } } String line = ST.format("<%1:{ x |, <x>}>", v).substring(2); fos.write(line.getBytes(CHARSET)); fos.write(Character.LINE_SEPARATOR); } written = true; } if (written) { LogEmitter.factory .get() .emit( this, Core.ALERT.INFO, ST.format("<%1> hosts written to <%2>", model.getRowCount(), target.getPath())); } else { LogEmitter.factory .get() .emit(this, Core.ALERT.DANGER, ST.format("Failed to export <%1>", target.getPath())); } } catch (FileNotFoundException ex) { Logger.getLogger(ConnectionDialog.class.getName()).log(Level.SEVERE, null, ex); LogEmitter.factory .get() .emit(this, Core.ALERT.DANGER, ST.format("Failed to export <%1>", target.getPath())); } catch (IOException ex) { Logger.getLogger(ConnectionDialog.class.getName()).log(Level.SEVERE, null, ex); LogEmitter.factory .get() .emit(this, Core.ALERT.DANGER, ST.format("Failed to export <%1>", target.getPath())); } toggle(true); }
public void testBallCatch() { for (int i = 0; i < balls.size(); i++) { if (bucket.contains(balls.get(i))) { if (balls.get(i).isGood()) points++; else lives--; balls.remove(i); i--; } else if (balls.get(i).getLocation().getY() >= HEIGHT + Ball.RADIUS) { if (balls.get(i).isGood()) lives--; balls.remove(i); i--; } } }
public void paint(Graphics g) { super.paint(g); // 画出我的坦克 g.fillRect(0, 0, 400, 300); // 确定区域为400 300 背景为黑色值 // 使用画坦克方法画出坦克 this.drawTank(hero.getX(), hero.getY(), g, hero.getDirect(), 0); // 画出敌人的坦克 for (int i = 0; i < ets.size(); i++) { this.drawTank(ets.get(i).getX(), ets.get(i).getY(), g, ets.get(i).getDirect(), 1); } }
public void nick_name(String msg) { try { String name = msg.substring(13); this.setName(name); Vector v = father.onlineList; boolean isRepeatedName = false; int size = v.size(); for (int i = 0; i < size; i++) { ServerAgentThread tempSat = (ServerAgentThread) v.get(i); if (tempSat.getName().equals(name)) { isRepeatedName = true; break; } } if (isRepeatedName == true) { dout.writeUTF("<#NAME_REPEATED#>"); din.close(); dout.close(); sc.close(); flag = false; } else { v.add(this); father.refreshList(); String nickListMsg = ""; StringBuilder nickListMsgSb = new StringBuilder(); size = v.size(); for (int i = 0; i < size; i++) { ServerAgentThread tempSat = (ServerAgentThread) v.get(i); nickListMsgSb.append("!"); nickListMsgSb.append(tempSat.getName()); } nickListMsgSb.append("<#NICK_LIST#>"); nickListMsg = nickListMsgSb.toString(); Vector tempv = father.onlineList; size = tempv.size(); for (int i = 0; i < size; i++) { ServerAgentThread tempSat = (ServerAgentThread) tempv.get(i); tempSat.dout.writeUTF(nickListMsg); if (tempSat != this) { tempSat.dout.writeUTF("<#MSG#>" + this.getName() + "is now online...."); } } } } catch (IOException e) { e.printStackTrace(); } }
private void moveUpAndDownPage(boolean _up) { int index = tabbedPanel.getSelectedIndex(); if (index < 0) return; Editor page = pageList.get(index); if (page == null) return; if (_up) { if (index == 0) return; pageList.removeElementAt(index); pageList.insertElementAt(page, index - 1); tabbedPanel.removeTabAt(index); tabbedPanel.insertTab( page.isActive() ? page.getName() : page.getName() + " (D)", null, page.getComponent(), tooltip, index - 1); } else { if (index == (pageList.size() - 1)) return; pageList.removeElementAt(index); pageList.insertElementAt(page, index + 1); tabbedPanel.removeTabAt(index); tabbedPanel.insertTab( page.isActive() ? page.getName() : page.getName() + " (D)", null, page.getComponent(), tooltip, index + 1); } tabbedPanel.setSelectedComponent(page.getComponent()); changed = true; }
public void setValueAt(Object value, int row, int col) { if (rowData.size() > row && row >= 0) { Object[] data = (Object[]) rowData.get(row); data[col] = value; } fireTableCellUpdated(row, col); }
/** * Gets the tile with <b>local</b> id <code>i</code>. * * @param i local id of tile * @return A tile with local id <code>i</code> or <code>null</code> if no tile exists with that id */ public Tile getTile(int i) { try { return tiles.get(i); } catch (ArrayIndexOutOfBoundsException a) { } return null; }
public void paintComponent(Graphics g) { g.setColor(new Color(96, 96, 96)); image.paintIcon(this, g, 1, 1); FontMetrics fm = g.getFontMetrics(); String[] args = {jEdit.getVersion()}; String version = jEdit.getProperty("about.version", args); g.drawString(version, (getWidth() - fm.stringWidth(version)) / 2, getHeight() - 5); g = g.create((getWidth() - maxWidth) / 2, TOP, maxWidth, getHeight() - TOP - BOTTOM); int height = fm.getHeight(); int firstLine = scrollPosition / height; int firstLineOffset = height - scrollPosition % height; int lines = (getHeight() - TOP - BOTTOM) / height; int y = firstLineOffset; for (int i = 0; i <= lines; i++) { if (i + firstLine >= 0 && i + firstLine < text.size()) { String line = (String) text.get(i + firstLine); g.drawString(line, (maxWidth - fm.stringWidth(line)) / 2, y); } y += fm.getHeight(); } }
// 重写paint方法 public void paint(Graphics g) { super.paint(g); // float lineWidth = 3.0f; // ((Graphics2D)g).setStroke(new BasicStroke(lineWidth)); // 将坦克的活动区域填充为默认黑色 g.fillRect(0, 0, 800, 600); this.drawTank(hero.getX(), hero.getY(), g, hero.getDirection(), 1); for (int i = 0; i < hero.bombs.size(); i++) { Bomb myBomb = hero.bombs.get(i); // 画出一颗子弹 if (myBomb != null && myBomb.isLive == true) { // float lineWidth = 2.0f; // ((Graphics2D) g).setStroke(new BasicStroke(lineWidth));//设置线条为粗线 g.draw3DRect(myBomb.x, myBomb.y, 2, 2, true); } if (myBomb.isLive == false) { hero.bombs.remove(myBomb); } } // 画出爆炸 for (int i = 0; i < baozhas.size(); i++) { BaoZha bz = baozhas.get(i); System.out.println("baozhas.size()= " + baozhas.size()); if (bz.life > 5) { g.drawImage(image3, bz.x, bz.y, 30, 30, this); } else if (bz.life > 3) { g.drawImage(image2, bz.x, bz.y, 30, 30, this); } else { g.drawImage(image1, bz.x, bz.y, 30, 30, this); } bz.liftDown(); if (bz.life == 0) { baozhas.remove(bz); } } // 画出敌人的坦克 for (int i = 0; i < ets.size(); i++) { EnemyTank et = ets.get(i); if (et.isLive) { this.drawTank(et.getX(), et.getY(), g, et.getDirection(), 0); } } }
/** * Not all editors are capable of displaying new entries. This whips through and removes all * editors that can't. */ private void trimNonNewEntryEditors() { int size = activeEditors.size(); for (int i = size - 1; i >= 0; i--) { if (((DataSink) activeEditors.get(i)).canCreateEntry() == false) { remove(i); } } suggestTableEditor(); // use table editor as default for new entries... }
/* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ public boolean yaEsta(String nombre) { boolean siOno = false; for (int a = 0; a < vectorJugadores.size(); a++) { if (nombre.equals(vectorJugadores.get(a))) { siOno = true; break; } } return siOno; }
/** * Returns the WhiteboardFrame associated with the Contact. * * @param c contact * @return WhiteboardFrame with the Contact or null (if nothing found) */ private WhiteboardFrame getWhiteboardFrame(WhiteboardSession session) { WhiteboardFrame whiteboardFrame = null; for (int i = 0; i < wbFrames.size(); i++) { whiteboardFrame = (WhiteboardFrame) wbFrames.get(i); if (whiteboardFrame.getWhiteboardSession().equals(session)) return whiteboardFrame; } return null; }
private void renameCurrentPage(String _name) { int index = tabbedPanel.getSelectedIndex(); if (index < 0) return; _name = getUniqueName(_name); // Gonzalo 070128 tabbedPanel.setTitleAt(index, _name); Editor page = pageList.get(index); page.setName(_name); if (!page.isActive()) tabbedPanel.setTitleAt(index, page.getName() + " (D)"); changed = true; }
public void run() { if (telephony == null) return; Call createdCall = null; if (contacts != null) { Contact contact = (Contact) contacts.get(0); // NOTE: The multi user call is not yet implemented! // We just get the first contact and create a call for him. try { createdCall = telephony.createCall(contact); } catch (OperationFailedException e) { logger.error("The call could not be created: " + e); callPanel.getParticipantPanel(contact.getDisplayName()).setState(e.getMessage()); removeCallPanelWait(callPanel); } // If the call is successfully created we set the created // Call instance to the already existing CallPanel and we // add this call to the active calls. if (createdCall != null) { callPanel.setCall(createdCall, GuiCallParticipantRecord.OUTGOING_CALL); activeCalls.put(createdCall, callPanel); } } else { try { createdCall = telephony.createCall(stringContact); } catch (ParseException e) { logger.error("The call could not be created: " + e); callPanel.getParticipantPanel(stringContact).setState(e.getMessage()); removeCallPanelWait(callPanel); } catch (OperationFailedException e) { logger.error("The call could not be created: " + e); callPanel.getParticipantPanel(stringContact).setState(e.getMessage()); removeCallPanelWait(callPanel); } // If the call is successfully created we set the created // Call instance to the already existing CallPanel and we // add this call to the active calls. if (createdCall != null) { callPanel.setCall(createdCall, GuiCallParticipantRecord.OUTGOING_CALL); activeCalls.put(createdCall, callPanel); } } }
protected void fireChangeListeners() { if (changeListeners == null) return; for (int a = 0; a < changeListeners.size(); a++) { ChangeListener l = (ChangeListener) changeListeners.get(a); try { l.stateChanged(new ChangeEvent(this)); } catch (RuntimeException e) { e.printStackTrace(); } } }
/** * Returns the WhiteboardFrame associated with the Contact. * * @param c contact * @return WhiteboardFrame with the Contact or null (if nothing found) */ private WhiteboardFrame getWhiteboardFrame(Contact contact) { WhiteboardFrame whiteboardFrame = null; for (int i = 0; i < wbFrames.size(); i++) { whiteboardFrame = (WhiteboardFrame) wbFrames.get(i); if (whiteboardFrame.getContact() != null && whiteboardFrame.getContact().equals(contact)) return whiteboardFrame; } return null; }
public Object getValueAt(int rowIndex, int columnIndex) { if (timeList != null) { if (rowIndex < timeList.size()) { JCTimeObject ctObj = (JCTimeObject) timeList.get(rowIndex); if (columnIndex == 0) { return ctObj.toString(); } } } return null; }
/** If a purpose written pluggable editor is available, switch to that, */ public boolean suggestPluggableEditor() { for (int i = activeEditors.size() - 1; i >= 0; i--) { // try to set to the first 'user written' pluggable editor // that can be found... PluggableEditor ed = (PluggableEditor) activeEditors.get(i); if ((ed != templateDisplay) && (ed != tableDisplay)) { setCurrentEditor(ed); return true; } } return false; }
public DataSet loadDataSet(Vector<Integer> data) { int i; int j; double tempdata[] = new double[2 * data.size()]; for (i = j = 0; i < data.size(); i++, j += 2) { tempdata[j] = i; tempdata[j + 1] = data.get(i); } return loadDataSet(tempdata, data.size()); }
private void copyPage() { int index = tabbedPanel.getSelectedIndex(); if (index < 0) return; Editor page = pageList.get(index); if (page == null) return; addPage( typeOfPage(page), this.getUniqueName(page.getName()), page.saveStringBuffer().toString(), true); changed = true; }
public void draw(Graphics g) { g.setColor(Color.BLACK); g.drawString("Points: " + points, 10, 20); g.drawString("Lives: " + lives, 10, 30); if (lives <= 0) { g.setColor(Color.RED); g.drawString("You Lose", WIDTH / 2 - 20, HEIGHT / 2); } for (int i = 0; i < balls.size(); i++) balls.get(i).draw(g); bucket.draw(g); }
public void client_leave(String msg) { try { Vector tempv = father.onlineList; tempv.remove(this); int size = tempv.size(); String nl = "<#NICK_LIST#>"; for (int i = 0; i < size; i++) { ServerAgentThread tempSat = (ServerAgentThread) tempv.get(i); tempSat.dout.writeUTF("<#MSG#>" + this.getName() + "is offline...."); nl = nl + "|" + tempSat.getName(); } for (int i = 0; i < size; i++) { ServerAgentThread tempSat = (ServerAgentThread) tempv.get(i); tempSat.dout.writeUTF(nl); } this.flag = false; father.refreshList(); } catch (IOException e) { e.printStackTrace(); } }
private void toggleCurrentPage() { int index = tabbedPanel.getSelectedIndex(); if (index < 0) return; Editor page = pageList.get(index); if (page.isActive()) { page.setActive(false); tabbedPanel.setTitleAt(index, page.getName() + " (D)"); } else { page.setActive(true); tabbedPanel.setTitleAt(index, page.getName()); } changed = true; ejs.getModelEditor().getVariablesEditor().updateControlValues(false); }