private void drawLadder() { int width = (int) (frameSize.getWidth() / player); int height = (int) (frameSize.getHeight()); for (int i = 0; i < player; i++) { draw.gImg.drawLine( width * i + width / 2, 0, width * i + width / 2, (int) frameSize.getHeight() - 50); } for (int i = 0; i < ladderMap.length; i++) for (int j = 0; j < ladderMap[i].length - 1; j++) { if (ladderMap[i][j] == 1) { draw.gImg.drawLine( width * j + width / 2, (int) ((frameSize.getHeight() - 80) / 10 * i + frameSize.getHeight() * 0.02), width * (j + 1) + width / 2, (int) ((frameSize.getHeight() - 80) / 10 * i + frameSize.getHeight() * 0.02)); // draw.gImg.drawLine((int)(frameSize.getWidth()/player*j+frameSize.getWidth()/player/2), // (int)((frameSize.getHeight()-80)/10*i+frameSize.getHeight()*0.02), // (int)(frameSize.getWidth()/player*(j+1)+frameSize.getWidth()/player/2), // (int)((frameSize.getHeight()-80)/10*i+frameSize.getHeight()*0.02)); } } draw.repaint(); }
public void actionPerformed(ActionEvent event) { if (d.again) { initTree(tree); d.again = false; } if (event.getSource() == send) { String c1 = attachment1.getText(); String c2 = attachment2.getText(); String c3 = valueOfArc.getText(); if (c1.matches(regularExpression) && c2.matches(regularExpression) && c3.matches(regularExpression)) { int s1 = Integer.parseInt(c1); int s2 = Integer.parseInt(c2); int value = Integer.parseInt(c3); if (s1 <= d.getNumberOfNodes() && s2 <= d.getNumberOfNodes() && s1 != s2) { Arc a = new Arc(s1, s2, value); boolean already = false; int emplacement = 0; int i = 0; while (tree[i] != null && i < tree.length) { if ((tree[i].getNode1() == a.getNode1() || tree[i].getNode1() == a.getNode2()) && (tree[i].getNode2() == a.getNode1() || tree[i].getNode2() == a.getNode2())) { emplacement = i; already = true; } i++; } if (!already) { tree[d.getNumberOfArc()] = a; d.addArc(a, d.getNumberOfArc()); } else { tree[emplacement].setCost(value); d.modifArc(emplacement, value); } d.repaint(); } } } else if (event.getSource() == step) { if (tree[0] != null) { if (d.getCpt() == 0) { if (d.getChoice().equals("Kruskal")) { k = new Kruskal(tree, d.getNumberOfNodes(), d.getNumberOfArc()); d.finalTree = k.tree; } d.end = true; } if (d.finalTree[d.getCpt()] != null) { d.setCpt(d.getCpt() + 1); } d.repaint(); } } }