Exemple #1
0
    void add(Target t) {
      SocketChannel sc = null;
      try {

        sc = SocketChannel.open();
        sc.configureBlocking(false);

        boolean connected = sc.connect(t.address);

        t.channel = sc;
        t.connectStart = System.currentTimeMillis();

        if (connected) {
          t.connectFinish = t.connectStart;
          sc.close();
          printer.add(t);
        } else {
          synchronized (pending) {
            pending.add(t);
          }

          sel.wakeup();
        }
      } catch (IOException x) {
        if (sc != null) {
          try {
            sc.close();
          } catch (IOException xx) {
          }
        }
        t.failure = x;
        printer.add(t);
      }
    }
Exemple #2
0
  public void run() {
    while (true) {
      try {
        for (Target q : targets) // Target Cycling
        {
          q.move(); // Target Movement
          //            			if(targets.get(i).getY() < 0 || targets.get(i).getY() > 490) // Target
          // Zones
          //                    	{
          //                        	targets.get(i).bounceX(); // Target Bouncing
          //                    	}
        }

        //        			for(int i = 0; i < regions.size(); i++) // Region Cycling
        //        			{
        //        				regions.get(i).move() // Region Movement
        //        				if(regions.get(i).getY() < 0 || regions.get(i).getY() > 490) // Region Zones
        //                    	{
        //                        	regions.get(i).bounceX(); // Region Bouncing
        //                    	}
        //        			}
        repaint();
        t.sleep(timeStep);
      } catch (InterruptedException e) {
      }
    }
  }
Exemple #3
0
  public ShowComp() throws InterruptedException, IOException {
    super("CONNECTED COMPUTERS");
    int x = 0, d = 20;
    mb = new JMenuBar();
    File = new JMenu("File");
    mb.add(File);
    exit = new JMenuItem("Exit");
    exit.addActionListener(this);
    File.add(exit);
    ta = new JTextArea();
    ta.setBounds(20, 30, 315, 470);
    ta.setEditable(false);
    add(ta);

    setJMenuBar(mb);

    sel = new JLabel("The connected computers are..");
    sel.setBounds(15, 5, 300, 30);
    add(sel);
    b1 = new JButton("<< BACK");
    b1.setBounds(140, 510, 100, 30);
    b1.setToolTipText("Back to main page");
    b1.addActionListener(this);
    add(b1);
    setLayout(null);
    while (x < 360) {
      x = x + d;
      setBounds(675, 50, x, 600);
      this.show();
    }
    // setVisible(true);
    String s = "192.168.0.", temp = null;
    Printer printer = new Printer();
    printer.start();
    Connector connector = new Connector(printer);
    connector.start();

    LinkedList targets = new LinkedList();
    for (int i = 1; i <= 255; i++) {
      temp = s + Integer.toString(i);
      Target t = new Target(temp);
      targets.add(t);
      connector.add(t);
    }
    Thread.sleep(2000);
    connector.shutdown();
    connector.join();

    for (Iterator i = targets.iterator(); i.hasNext(); ) {
      Target t = (Target) i.next();
      if (!t.shown) t.show();
    }

    setDefaultCloseOperation(DISPOSE_ON_CLOSE);
  }
Exemple #4
0
 public void run() {
   try {
     for (; ; ) {
       Target t = null;
       synchronized (pending) {
         while (pending.size() == 0) pending.wait();
         t = (Target) pending.removeFirst();
       }
       t.show();
     }
   } catch (InterruptedException x) {
     return;
   }
 }
Exemple #5
0
    void processPendingTargets() throws IOException {
      synchronized (pending) {
        while (pending.size() > 0) {
          Target t = (Target) pending.removeFirst();
          try {

            t.channel.register(sel, SelectionKey.OP_CONNECT, t);

          } catch (IOException x) {

            t.channel.close();
            t.failure = x;
            printer.add(t);
          }
        }
      }
    }
Exemple #6
0
    void processSelectedKeys() throws IOException {
      for (Iterator i = sel.selectedKeys().iterator(); i.hasNext(); ) {

        SelectionKey sk = (SelectionKey) i.next();
        i.remove();

        Target t = (Target) sk.attachment();
        SocketChannel sc = (SocketChannel) sk.channel();

        try {
          if (sc.finishConnect()) {
            sk.cancel();
            t.connectFinish = System.currentTimeMillis();
            sc.close();
            printer.add(t);
          }
        } catch (IOException x) {
          sc.close();
          t.failure = x;
          printer.add(t);
        }
      }
    }
Exemple #7
0
  public void paint(Graphics g) {

    g.setColor(Color.white); // Background flushing
    g.fillRect(0, 0, 800, 800);

    g.setColor(Color.red);
    for (Target a : targets) // Target painting
    {
      if (a.getImageType() == "clay_pigeon.gif")
        g.drawImage(target1, a.getX(), a.getY(), a.getSize(), a.getSize(), this);
      if (a.getImageType() == "Disc1.gif")
        g.drawImage(target2, a.getX(), a.getY(), a.getSize(), a.getSize(), this);
    }

    //    	g.setColor(Color.red);
    //    	for(int i = 0; i < regions.size(); i++) // Region painting
    //    	{
    //    		g.fillRect(regions.get(i).getX(), regions.get(i).getY(), regions.get(i).getW(),
    // regions.get(i).getH());
    //    	}

  }