00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 import java.applet.Applet;
00011 import java.util.*;
00012 import java.awt.*;
00013 import java.awt.event.*;
00014 import hr.fer.zesoi.cyclops.*;
00015
00016
00017
00025
00026 public
00027 class Simulation
00028 extends Applet
00029 implements ActionListener, ItemListener
00030 {
00032 NetworkSpacePanel network_panel;
00033
00035 Panel control_panel;
00036
00037
00038
00039
00040
00041
00042
00044 Button traceroute = new Button("Put");
00045
00047 TracerouteDialog traceroute_dialog = null;
00048
00050 Button add_line = new Button("Dodaj liniju");
00051
00053 AddLineDialog add_line_dialog = null;
00054
00056 Button delete_line = new Button("Obri\u0161i liniju");
00057
00059 DeleteLineDialog delete_line_dialog = null;
00060
00062 Button add_node = new Button("Dodaj \u010dvor");
00063
00065 AddNodeDialog add_node_dialog = null;
00066
00068 Button delete_node = new Button("Obri\u0161i \u010dvor");
00069
00071 DeleteNodeDialog delete_node_dialog = null;
00072
00074 Button start_stop_simulation = new Button("Pokreni");
00075
00077 Checkbox all_packets = new Checkbox("Svi paketi");
00078
00080 Checkbox line_capacities = new Checkbox("Kapaciteti linija");
00081
00086 public void init ()
00087 {
00088 setLayout(new BorderLayout());
00089 network_panel = new NetworkSpacePanel(this);
00090 control_panel = new Panel();
00091 network_panel.setName("Network space interface");
00092 add("Center", network_panel);
00093 add("South", control_panel);
00094
00095 control_panel.add(traceroute);
00096 control_panel.add(add_node);
00097 control_panel.add(delete_node);
00098 control_panel.add(add_line);
00099 control_panel.add(delete_line);
00100 control_panel.add(start_stop_simulation);
00101 control_panel.add(all_packets);
00102 control_panel.add(line_capacities);
00103
00104 traceroute.addActionListener(this);
00105 add_node.addActionListener(this);
00106 delete_node.addActionListener(this);
00107 add_line.addActionListener(this);
00108 delete_line.addActionListener(this);
00109 start_stop_simulation.addActionListener(this);
00110 all_packets.addItemListener(this);
00111 line_capacities.addItemListener(this);
00112
00113
00114 Node first;
00115 Node second;
00116 int i;
00117 int j;
00118 int capacity;
00119 String network = getParameter("network");
00120
00121 if (null != network)
00122 {
00123 StringTokenizer tokenizer = new StringTokenizer(network, ",");
00124 while (tokenizer.hasMoreTokens())
00125 {
00126 String connection = tokenizer.nextToken();
00127 i = connection.indexOf('-');
00128 if (0 < i)
00129 {
00130 capacity = 10;
00131 j = connection.indexOf('/');
00132 if (0 < j)
00133 {
00134 capacity = Integer.valueOf(connection.substring(j+1)).intValue();
00135 connection = connection.substring(0,j);
00136 }
00137
00138 first = network_panel.addNode(connection.substring(0, i));
00139 second = network_panel.addNode(connection.substring(i + 1));
00140 network_panel.addLine(first, second, capacity);
00141 }
00142
00143 }
00144
00145 }
00146
00147 String packets = getParameter("dummypackets");
00148
00149 if (null != packets)
00150 {
00151 i = packets.indexOf(',');
00152 if (0 < i)
00153 {
00154 int ttl = Integer.valueOf(packets.substring(i+1)).intValue();
00155 int n = Integer.valueOf(packets.substring(0,i)).intValue();
00156 network_panel.addDummyPackets(n, ttl);
00157 }
00158 }
00159 else if (null != network)
00160 {
00161 network_panel.addDummyPackets(40, -1);
00162 }
00163
00164 String route = getParameter("route");
00165
00166 if (null != route)
00167 {
00168 i = route.indexOf('-');
00169 if (0 < i)
00170 {
00171 network_panel.tracePackets(route.substring(0,i),
00172 route.substring(i+1)
00173 );
00174 }
00175 }
00176
00177 }
00178
00179
00183 public void destroy ()
00184 {
00185 network_panel.endSimulation();
00186 remove(network_panel);
00187 remove(control_panel);
00188 }
00189
00190
00194 public void start()
00195 {
00196 network_panel.start();
00197 }
00198
00199
00203 public void stop()
00204 {
00205 network_panel.stop();
00206 }
00207
00208
00212 public void actionPerformed (ActionEvent event)
00213 {
00214 Object source = event.getSource();
00215 String command = event.getActionCommand();
00216 int modifier = event.getModifiers();
00217
00218
00219 if (source == traceroute)
00220 {
00221 if (null == traceroute_dialog)
00222 {
00223 traceroute_dialog = new TracerouteDialog(this);
00224 }
00225 }
00226
00227 if (source == traceroute_dialog)
00228 {
00229 if (command.equals("OK"))
00230 {
00231 network_panel.stopSimulation();
00232 network_panel.tracePackets(traceroute_dialog.left_name,
00233 traceroute_dialog.right_name
00234 );
00235 String name = start_stop_simulation.getLabel();
00236 if (name.equals("Zaustavi"))
00237 {
00238 network_panel.startSimulation();
00239 }
00240 }
00241 traceroute_dialog = null;
00242 }
00243
00244 if (source == add_line)
00245 {
00246 if (null == add_line_dialog)
00247 {
00248 add_line_dialog = new AddLineDialog(this);
00249 }
00250 }
00251
00252 if (source == add_line_dialog)
00253 {
00254 if (command.equals("OK"))
00255 {
00256 network_panel.stopSimulation();
00257 Node first = network_panel.addNode(add_line_dialog.left_name);
00258 Node second = network_panel.addNode(add_line_dialog.right_name);
00259 network_panel.addLine(first, second, add_line_dialog.capacity);
00260 String name = start_stop_simulation.getLabel();
00261 if (name.equals("Zaustavi"))
00262 {
00263 network_panel.startSimulation();
00264 }
00265 }
00266 add_line_dialog = null;
00267 }
00268
00269 if (source == add_node)
00270 {
00271 if (null == add_node_dialog)
00272 {
00273 add_node_dialog = new AddNodeDialog(this);
00274 }
00275 }
00276
00277 if (source == add_node_dialog)
00278 {
00279 if (command.equals("OK"))
00280 {
00281 network_panel.stopSimulation();
00282 Node new_node = network_panel.addNode(add_node_dialog.node_name);
00283 String name = start_stop_simulation.getLabel();
00284 if (name.equals("Zaustavi"))
00285 {
00286 network_panel.startSimulation();
00287 }
00288 }
00289 add_node_dialog = null;
00290 }
00291
00292 if (source == delete_line)
00293 {
00294 if (null == delete_line_dialog)
00295 {
00296 delete_line_dialog = new DeleteLineDialog(this);
00297 }
00298 }
00299
00300 if (source == delete_line_dialog)
00301 {
00302 if (command.equals("OK"))
00303 {
00304 network_panel.stopSimulation();
00305 Line deleted = network_panel.deleteLine(delete_line_dialog.left_name,
00306 delete_line_dialog.right_name
00307 );
00308 String name = start_stop_simulation.getLabel();
00309 if (name.equals("Zaustavi"))
00310 {
00311 network_panel.startSimulation();
00312 }
00313 }
00314 delete_line_dialog = null;
00315 }
00316
00317 if (source == delete_node)
00318 {
00319 if (null == delete_node_dialog)
00320 {
00321 delete_node_dialog = new DeleteNodeDialog(this);
00322 }
00323 }
00324
00325 if (source == delete_node_dialog)
00326 {
00327 if (command.equals("OK"))
00328 {
00329 network_panel.stopSimulation();
00330 Node deleted = network_panel.deleteNode(delete_node_dialog.node_name);
00331 String name = start_stop_simulation.getLabel();
00332 if (name.equals("Zaustavi"))
00333 {
00334 network_panel.startSimulation();
00335 }
00336 }
00337 delete_node_dialog = null;
00338 }
00339
00340 if (source == start_stop_simulation)
00341 {
00342 String name = start_stop_simulation.getLabel();
00343 if (name.equals("Pokreni"))
00344 {
00345 start_stop_simulation.setLabel("Zaustavi");
00346 network_panel.startSimulation();
00347 }
00348 else
00349 {
00350 start_stop_simulation.setLabel("Pokreni");
00351 network_panel.stopSimulation();
00352 }
00353 }
00354 }
00355
00356
00360 public void itemStateChanged (ItemEvent event)
00361 {
00362 Object source;
00363 boolean on;
00364
00365 source = event.getSource();
00366 on = event.getStateChange() == ItemEvent.SELECTED;
00367 if (source == all_packets)
00368 {
00369 network_panel.all_packets = on;
00370 }
00371 if (source ==line_capacities)
00372 {
00373 network_panel.show_line_capacities = on;
00374 }
00375 }
00376
00377
00381 public String getAppletInfo ()
00382 {
00383 return "Cyclops simulator\nFER/SPVP 2001\nD. Vasić, T. Petković, Z. Kostanjčar";
00384 }
00385 }
00386
00387
00388
00389
00394 class NetworkSpacePanel
00395 extends Panel
00396 implements Runnable, MouseListener, MouseMotionListener
00397 {
00398
00400 CyclopsSimulator cyclops = new CyclopsSimulator();
00401
00403 Simulation simulation_applet;
00404
00406 Node currently_manipulated;
00407
00409 Thread simulator;
00410
00412 boolean all_packets;
00413
00415 boolean show_line_capacities;
00416
00420 public NetworkSpacePanel (Simulation simulation_applet)
00421 {
00422 this.simulation_applet = simulation_applet;
00423 addMouseListener(this);
00424 addMouseMotionListener(this);
00425 cyclops.start();
00426 cyclops.setName("Cyclops simulator");
00427 }
00428
00429
00437 public Node addNode (String name)
00438 {
00439 Node new_node;
00440 new_node = cyclops.findNode(name);
00441 if (new_node == null)
00442 {
00443 new_node = new Node(name);
00444 cyclops.addNode(new_node);
00445 }
00446 return new_node;
00447 }
00448
00449
00457 public Node deleteNode (String name)
00458 {
00459 Node removed_node;
00460 removed_node = cyclops.deleteNode(name);
00461 return removed_node;
00462 }
00463
00464
00470 public void addDummyPackets(int number, int time_to_live)
00471 {
00472 cyclops.addDummyPackets(number, time_to_live);
00473 }
00474
00475
00481 public void tracePackets(String start_node, String end_node)
00482 {
00483 if (!start_node.equals(end_node))
00484 {
00485 cyclops.tracePackets(start_node, end_node);
00486 }
00487 }
00488
00489
00496 public void addLine (Node first, Node second, int capacity)
00497 {
00498 Line new_line = new Line(first, second, capacity);
00499 cyclops.addLine(new_line);
00500 }
00501
00502
00509 public Line deleteLine(String first, String second)
00510 {
00511 Line deleted;
00512 deleted = cyclops.deleteLine(first, second);
00513 return deleted;
00514 }
00515
00516
00520 public void run()
00521 {
00522 Thread me;
00523
00524 me = Thread.currentThread();
00525 while (simulator == me)
00526 {
00527 repaint();
00528 try
00529 {
00530 Thread.sleep(100);
00531 }
00532 catch (InterruptedException exception)
00533 {
00534 break;
00535 }
00536 }
00537 }
00538
00539
00540 Image off_screen;
00541 Dimension off_screen_size;
00542 Graphics off_graphics;
00543
00544 final Color node_color = new Color(250, 220, 100);
00545 final Color line_color = Color.black;
00546 final Color left_packet_color = new Color(250, 200, 80);
00547 final Color right_packet_color = new Color(250, 240, 120);
00548
00553 public synchronized void update (Graphics g)
00554 {
00555 Dimension d = getSize();
00556 if ((null == off_screen) ||
00557 (d.width != off_screen_size.width) ||
00558 (d.height != off_screen_size.height)
00559 )
00560 {
00561 off_screen = createImage(d.width, d.height);
00562 off_screen_size = d;
00563 off_graphics = off_screen.getGraphics();
00564 off_graphics.setFont(getFont());
00565 }
00566 off_graphics.setColor(getBackground());
00567 off_graphics.fillRect(0, 0, d.width, d.height);
00568 FontMetrics metrics = off_graphics.getFontMetrics();
00569 cyclops.paint(off_graphics, metrics,
00570 node_color, line_color,
00571 left_packet_color, right_packet_color, Color.red,
00572 show_line_capacities, all_packets
00573 );
00574 g.drawImage(off_screen, 0, 0, null);
00575 }
00576
00577
00582 public void mouseClicked (MouseEvent event)
00583 {
00584 }
00585
00586
00591 public void mousePressed (MouseEvent event)
00592 {
00593 double best_distance = Double.MAX_VALUE;
00594 double distance;
00595 int n = cyclops.numberOfNodes();
00596 int x = event.getX();
00597 int y = event.getY();
00598 Node current_node;
00599 int i;
00600 for (i=0; i!=n; i++)
00601 {
00602 current_node = cyclops.nodeAt(i);
00603 distance = (x - current_node.getXCoordinate())
00604 * (x - current_node.getXCoordinate())
00605 + (y - current_node.getYCoordinate())
00606 * (y - current_node.getYCoordinate());
00607 if (distance < best_distance)
00608 {
00609 currently_manipulated = current_node;
00610 best_distance = distance;
00611 }
00612 }
00613 currently_manipulated.setCoordinates(x, y);
00614 repaint();
00615 event.consume();
00616 }
00617
00618
00623 public void mouseReleased (MouseEvent event)
00624 {
00625 currently_manipulated.setCoordinates(event.getX(), event.getY());
00626 currently_manipulated = null;
00627 repaint();
00628 event.consume();
00629 }
00630
00631
00636 public void mouseEntered (MouseEvent event)
00637 {
00638 }
00639
00640
00645 public void mouseExited (MouseEvent event)
00646 {
00647 }
00648
00649
00654 public void mouseDragged (MouseEvent event)
00655 {
00656 currently_manipulated.setCoordinates(event.getX(), event.getY());
00657 repaint();
00658 event.consume();
00659 }
00660
00661
00666 public void mouseMoved (MouseEvent event)
00667 {
00668 }
00669
00670
00674 public void start ()
00675 {
00676 simulator = new Thread(this);
00677 simulator.start();
00678 }
00679
00680
00684 public void stop ()
00685 {
00686 simulator = null;
00687 }
00688
00689
00693 public void startSimulation ()
00694 {
00695 cyclops.startSimulation();
00696 }
00697
00698
00702 public void stopSimulation ()
00703 {
00704 cyclops.stopSimulation();
00705 }
00706
00707
00711 public void endSimulation ()
00712 {
00713 cyclops.endSimulation();
00714 }
00715
00716 }
00717
00718
00719
00720
00726 class AddLineDialog
00727 implements ActionListener
00728 {
00729
00731 ActionListener action_listener;
00732
00734 Dialog add_line;
00735
00737 Button button_ok;
00738
00740 Button button_cancel;
00741
00743 TextField left_field;
00744
00746 String left_name;
00747
00749 TextField right_field;
00750
00752 String right_name;
00753
00755 TextField capacity_field;
00756
00758 int capacity;
00759
00761 Frame dummy;
00762
00767 public AddLineDialog (ActionListener action_listener)
00768 {
00769 this.action_listener = action_listener;
00770
00771 dummy = new Frame();
00772 add_line = new Dialog(dummy, "Dodaj liniju");
00773 button_ok = new Button("U redu");
00774 button_cancel = new Button("Odustani");
00775 left_field = new TextField("ime", 30);
00776 right_field = new TextField("ime", 30);
00777 capacity_field = new TextField("20", 30);
00778
00779 Label left_label = new Label("Lijevi \u010dvor", Label.RIGHT);
00780 Label right_label = new Label("Desni \u010dvor", Label.RIGHT);
00781 Label capacity_label = new Label("Kapacitet", Label.RIGHT);
00782
00783 add_line.setLayout(new BorderLayout());
00784 add_line.setLayout(new GridLayout(4,2));
00785 add_line.add(left_label);
00786 add_line.add(left_field);
00787 add_line.add(right_label);
00788 add_line.add(right_field);
00789 add_line.add(capacity_label);
00790 add_line.add(capacity_field);
00791 add_line.add(button_ok);
00792 add_line.add(button_cancel);
00793
00794 right_field.addActionListener(this);
00795 left_field.addActionListener(this);
00796 capacity_field.addActionListener(this);
00797 button_ok.addActionListener(this);
00798 button_cancel.addActionListener(this);
00799
00800 add_line.pack();
00801 add_line.setResizable(false);
00802 add_line.show();
00803 }
00804
00809 public void actionPerformed (ActionEvent event)
00810 {
00811 Object source = event.getSource();
00812
00813
00814 if (source == left_field)
00815 {
00816 left_name = left_field.getText();
00817 }
00818
00819 if (source == right_field)
00820 {
00821 right_name = right_field.getText();
00822 }
00823
00824 if (source == capacity_field)
00825 {
00826 capacity = Integer.valueOf(capacity_field.getText()).intValue();
00827 }
00828
00829 if (source == button_ok)
00830 {
00831 left_name = left_field.getText();
00832 right_name = right_field.getText();
00833 capacity = Integer.valueOf(capacity_field.getText()).intValue();
00834 add_line.dispose();
00835 if (left_name.equals(right_name))
00836 {
00837 action_listener.actionPerformed(new ActionEvent(this, 1, "Cancel"));
00838 }
00839 else
00840 {
00841 action_listener.actionPerformed(new ActionEvent(this, 1, "OK"));
00842 }
00843 }
00844
00845 if (source == button_cancel)
00846 {
00847 add_line.dispose();
00848 action_listener.actionPerformed(new ActionEvent(this, 0, "Cancel"));
00849 }
00850 }
00851
00852
00853 }
00854
00855
00856
00857
00862 class AddNodeDialog
00863 implements ActionListener
00864 {
00865
00867 ActionListener action_listener;
00868
00870 Dialog add_node;
00871
00873 Button button_ok;
00874
00876 Button button_cancel;
00877
00879 TextField node_field;
00880
00882 String node_name;
00883
00885 Frame dummy;
00886
00891 public AddNodeDialog (ActionListener action_listener)
00892 {
00893 this.action_listener = action_listener;
00894
00895 dummy = new Frame();
00896 add_node = new Dialog(dummy, "Dodaj \u010dvor");
00897 button_ok = new Button("U redu");
00898 button_cancel = new Button("Odustani");
00899 node_field = new TextField("ime", 30);
00900
00901 Label node_label = new Label("Ime \u010dvora", Label.RIGHT);
00902
00903 add_node.setLayout(new BorderLayout());
00904 add_node.setLayout(new GridLayout(2,2));
00905 add_node.add(node_label);
00906 add_node.add(node_field);
00907 add_node.add(button_ok);
00908 add_node.add(button_cancel);
00909
00910 node_field.addActionListener(this);
00911 button_ok.addActionListener(this);
00912 button_cancel.addActionListener(this);
00913
00914 add_node.pack();
00915 add_node.setResizable(false);
00916 add_node.show();
00917 }
00918
00923 public void actionPerformed (ActionEvent event)
00924 {
00925 Object source = event.getSource();
00926
00927
00928 if (source == node_field)
00929 {
00930 node_name = node_field.getText();
00931 }
00932
00933 if (source == button_ok)
00934 {
00935 node_name = node_field.getText();
00936 add_node.dispose();
00937 action_listener.actionPerformed(new ActionEvent(this, 1, "OK"));
00938 }
00939
00940 if (source == button_cancel)
00941 {
00942 add_node.dispose();
00943 action_listener.actionPerformed(new ActionEvent(this, 0, "Cancel"));
00944 }
00945 }
00946
00947
00948 }
00949
00950
00951
00952
00957 class DeleteLineDialog
00958 implements ActionListener
00959 {
00960
00962 ActionListener action_listener;
00963
00965 Dialog delete_line;
00966
00968 Button button_ok;
00969
00971 Button button_cancel;
00972
00974 TextField left_field;
00975
00977 String left_name;
00978
00980 TextField right_field;
00981
00983 String right_name;
00984
00986 Frame dummy;
00987
00992 public DeleteLineDialog (ActionListener action_listener)
00993 {
00994 this.action_listener = action_listener;
00995
00996 dummy = new Frame();
00997 delete_line = new Dialog(dummy, "Obri\u0161i liniju");
00998 button_ok = new Button("U redu");
00999 button_cancel = new Button("Odustani");
01000 left_field = new TextField("ime", 30);
01001 right_field = new TextField("ime", 30);
01002
01003 Label left_label = new Label("Lijevi \u010dvor", Label.RIGHT);
01004 Label right_label = new Label("Desni \u010dvor", Label.RIGHT);
01005
01006 delete_line.setLayout(new BorderLayout());
01007 delete_line.setLayout(new GridLayout(3,2));
01008 delete_line.add(left_label);
01009 delete_line.add(left_field);
01010 delete_line.add(right_label);
01011 delete_line.add(right_field);
01012 delete_line.add(button_ok);
01013 delete_line.add(button_cancel);
01014
01015 right_field.addActionListener(this);
01016 left_field.addActionListener(this);
01017 button_ok.addActionListener(this);
01018 button_cancel.addActionListener(this);
01019
01020 delete_line.pack();
01021 delete_line.setResizable(false);
01022 delete_line.show();
01023 }
01024
01029 public void actionPerformed (ActionEvent event)
01030 {
01031 Object source = event.getSource();
01032
01033
01034 if (source == left_field)
01035 {
01036 left_name = left_field.getText();
01037 }
01038
01039 if (source == right_field)
01040 {
01041 right_name = right_field.getText();
01042 }
01043
01044 if (source == button_ok)
01045 {
01046 left_name = left_field.getText();
01047 right_name = right_field.getText();
01048 delete_line.dispose();
01049 action_listener.actionPerformed(new ActionEvent(this, 1, "OK"));
01050 }
01051
01052 if (source == button_cancel)
01053 {
01054 delete_line.dispose();
01055 action_listener.actionPerformed(new ActionEvent(this, 0, "Cancel"));
01056 }
01057 }
01058
01059
01060 }
01061
01062
01063
01064
01069 class DeleteNodeDialog
01070 implements ActionListener
01071 {
01072
01074 ActionListener action_listener;
01075
01077 Dialog delete_node;
01078
01080 Button button_ok;
01081
01083 Button button_cancel;
01084
01086 TextField node_field;
01087
01089 String node_name;
01090
01092 Frame dummy;
01093
01098 public DeleteNodeDialog (ActionListener action_listener)
01099 {
01100 this.action_listener = action_listener;
01101
01102 dummy = new Frame();
01103 delete_node = new Dialog(dummy, "Obri\u0161i \u010dvor");
01104 button_ok = new Button("U redu");
01105 button_cancel = new Button("Odustani");
01106 node_field = new TextField("ime", 30);
01107
01108 Label node_label = new Label("Ime \u010dvora", Label.RIGHT);
01109
01110 delete_node.setLayout(new BorderLayout());
01111 delete_node.setLayout(new GridLayout(2,2));
01112 delete_node.add(node_label);
01113 delete_node.add(node_field);
01114 delete_node.add(button_ok);
01115 delete_node.add(button_cancel);
01116
01117 node_field.addActionListener(this);
01118 button_ok.addActionListener(this);
01119 button_cancel.addActionListener(this);
01120
01121 delete_node.pack();
01122 delete_node.setResizable(false);
01123 delete_node.show();
01124 }
01125
01130 public void actionPerformed (ActionEvent event)
01131 {
01132 Object source = event.getSource();
01133
01134
01135 if (source == node_field)
01136 {
01137 node_name = node_field.getText();
01138 }
01139
01140 if (source == button_ok)
01141 {
01142 node_name = node_field.getText();
01143 delete_node.dispose();
01144 action_listener.actionPerformed(new ActionEvent(this, 1, "OK"));
01145 }
01146
01147 if (source == button_cancel)
01148 {
01149 delete_node.dispose();
01150 action_listener.actionPerformed(new ActionEvent(this, 0, "Cancel"));
01151 }
01152 }
01153
01154
01155 }
01156
01157
01158
01159
01164 class TracerouteDialog
01165 implements ActionListener
01166 {
01167
01169 ActionListener action_listener;
01170
01172 Dialog traceroute;
01173
01175 Button button_ok;
01176
01178 Button button_cancel;
01179
01181 TextField left_field;
01182
01184 String left_name;
01185
01187 TextField right_field;
01188
01190 String right_name;
01191
01193 Frame dummy;
01194
01199 public TracerouteDialog (ActionListener action_listener)
01200 {
01201 this.action_listener = action_listener;
01202
01203 dummy = new Frame();
01204 traceroute = new Dialog(dummy, "Pra\u0107enje paketa");
01205 button_ok = new Button("U redu");
01206 button_cancel = new Button("Odustani");
01207 left_field = new TextField("ime", 30);
01208 right_field = new TextField("ime", 30);
01209
01210 Label left_label = new Label("Po\u010detni \u010dvor", Label.RIGHT);
01211 Label right_label = new Label("Kona\u010dni \u010dvor", Label.RIGHT);
01212
01213 traceroute.setLayout(new BorderLayout());
01214 traceroute.setLayout(new GridLayout(3,2));
01215 traceroute.add(left_label);
01216 traceroute.add(left_field);
01217 traceroute.add(right_label);
01218 traceroute.add(right_field);
01219 traceroute.add(button_ok);
01220 traceroute.add(button_cancel);
01221
01222 right_field.addActionListener(this);
01223 left_field.addActionListener(this);
01224 button_ok.addActionListener(this);
01225 button_cancel.addActionListener(this);
01226
01227 traceroute.pack();
01228 traceroute.setResizable(false);
01229 traceroute.show();
01230 }
01231
01236 public void actionPerformed (ActionEvent event)
01237 {
01238 Object source = event.getSource();
01239
01240
01241 if (source == left_field)
01242 {
01243 left_name = left_field.getText();
01244 }
01245
01246 if (source == right_field)
01247 {
01248 right_name = right_field.getText();
01249 }
01250
01251 if (source == button_ok)
01252 {
01253 left_name = left_field.getText();
01254 right_name = right_field.getText();
01255 traceroute.dispose();
01256 action_listener.actionPerformed(new ActionEvent(this, 1, "OK"));
01257 }
01258
01259 if (source == button_cancel)
01260 {
01261 traceroute.dispose();
01262 action_listener.actionPerformed(new ActionEvent(this, 0, "Cancel"));
01263 }
01264 }
01265
01266
01267 }
01268
01269
01270
01271
01272