Пример #1
0
 /** Applet starts here */
 public void start() {
   JPanel p = new JPanel();
   add(p);
   p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
   startButton = new JButton("Blue-Gold algorithm demonstration");
   p.add(startButton);
   startButton.addActionListener(
       new java.awt.event.ActionListener() {
         public void actionPerformed(java.awt.event.ActionEvent e) {
           startDemo();
         }
       });
 }
Пример #2
0
    public BGnodePanel(
        NodeID nid,
        java.util.List<SingleProducer> producers,
        java.util.List<SingleConsumer> consumers,
        ScatterGather sg) {
      this.nid = nid;

      this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
      buttons = new JPanel();
      buttons.setLayout(new GridLayout(2, Math.max(consumers.size(), producers.size())));
      this.add(buttons);
      this.add(new JSeparator());

      JPanel p1 = new JPanel();
      p1.setLayout(new FlowLayout());
      this.add(p1);

      blueButton = new JButton("Blue");
      p1.add(blueButton);
      blueLabel = new JLabel("   ");
      setBlueOn(false);
      p1.add(blueLabel);

      goldButton = new JButton("Gold");
      p1.add(goldButton);
      goldLabel = new JLabel("   ");
      setGoldOn(false);
      p1.add(goldLabel);

      engine =
          new BlueGoldExtendedEngine(nid, sg, producers, consumers) {
            public void setBlueLightOn(boolean f) {
              setBlueOn(f);
            }

            public boolean getBlueLightOn() {
              return blueOn;
            }

            public void setBlueLightBlink(int dwell) {
              setBlueBlink(dwell);
            }

            public void setGoldLightOn(boolean f) {
              setGoldOn(f);
            }

            public boolean getGoldLightOn() {
              return goldOn;
            }

            public void setGoldLightBlink(int dwell) {
              setGoldBlink(dwell);
            }
          };

      sg.register(engine);

      blueButton.addMouseListener(
          new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent e) {
              blueTime = System.currentTimeMillis();
            }

            public void mouseReleased(java.awt.event.MouseEvent e) {
              if (System.currentTimeMillis() - blueTime < 2000) engine.blueClick();
              else longBluePress();
            }
          });

      goldButton.addMouseListener(
          new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent e) {
              goldTime = System.currentTimeMillis();
            }

            public void mouseReleased(java.awt.event.MouseEvent e) {
              if (System.currentTimeMillis() - goldTime < 2000) engine.goldClick();
              else longGoldPress();
            }
          });
    }