示例#1
0
 /** Executes to start fight animation. */
 private void fight() {
   int result1, result2;
   try {
     // gets counts of hits for each search
     result1 = control.getNumberOfArticles(searchText.getText());
     result2 = control.getNumberOfArticles(searchText2.getText());
     // writes the html file
     Util.generateFight(result1, result2);
     // loads it in the browser
     browser.setUrl(new File("articlefight/articlefight.html").getAbsolutePath());
   } catch (ControlException e) {
   }
 }
示例#2
0
  private Composite getFightPane(Composite parent) {
    // creates the composite to eventually return
    Composite composite = new Composite(parent, SWT.NONE);
    // sets its layout
    FormLayout layout = new FormLayout();
    FormData data;
    layout.spacing = 5;
    composite.setLayout(layout);
    // Let's create some controls!
    // search button
    final Button fightButton = new Button(composite, SWT.PUSH);
    fightButton.setText("Fight!");
    try {
      fightButton.setImage(new Image(null, new FileInputStream("images/search.png")));
    } catch (Exception e) {

    }
    fightButton.setToolTipText("Click here to see how many articles contain each search term");

    data = new FormData();
    data.top = new FormAttachment(0, 0);
    data.left = new FormAttachment(50, -50);
    data.width = 100;
    data.height = 30;
    fightButton.setLayoutData(data);
    // search text
    searchText = new Text(composite, SWT.SINGLE | SWT.BORDER);
    data = new FormData();
    data.top = new FormAttachment(0, 0);
    data.right = new FormAttachment(fightButton, 0);
    data.width = 150;
    data.height = 24;
    searchText.setLayoutData(data);
    // second search text
    searchText2 = new Text(composite, SWT.SINGLE | SWT.BORDER);
    data = new FormData();
    data.top = new FormAttachment(0, 0);
    data.left = new FormAttachment(fightButton, 0);
    data.width = 150;
    data.height = 24;
    searchText2.setLayoutData(data);
    // label
    label = new Label(composite, SWT.CENTER);
    label.setText("Enter two terms and click 'Fight!'");
    label.setFont(new Font(Display.getCurrent(), "", 16, SWT.BOLD));
    data = new FormData();
    data.left = new FormAttachment(0, 0);
    data.right = new FormAttachment(100, 0);
    data.top = new FormAttachment(fightButton, 5);
    label.setLayoutData(data);
    // browser
    browser = new Browser(composite, SWT.BORDER);
    data = new FormData();
    data.left = new FormAttachment(50, -275);
    data.right = new FormAttachment(50, 275);
    data.top = new FormAttachment(label, 5);
    // data.bottom = new FormAttachment(100,0);
    data.height = 520;
    data.width = 550;
    browser.setLayoutData(data);
    // sets browser home page
    browser.setUrl("http://www.rssoap.com");
    // adds click listener to start animation
    fightButton.addMouseListener(
        new MouseListener() {
          public void mouseUp(MouseEvent e) {}

          public void mouseDown(MouseEvent e) {
            fight();
          }

          public void mouseDoubleClick(MouseEvent e) {}
        });
    return composite;
  }