예제 #1
0
 demo5() {
   f = new Frame();
   f.setSize(300, 300);
   // f.setBackground(Color.red);
   f.setLayout(null);
   s1 = new Scrollbar(Scrollbar.VERTICAL, 0, 5, 0, 260);
   s1.setBackground(Color.red);
   s1.setBounds(30, 35, 20, 255);
   s2 = new Scrollbar(Scrollbar.VERTICAL, 0, 5, 0, 260);
   s2.setBackground(Color.green);
   s2.setBounds(60, 35, 20, 255);
   s3 = new Scrollbar(Scrollbar.VERTICAL, 0, 5, 0, 260);
   s3.setBackground(Color.blue);
   s3.setBounds(90, 35, 20, 255);
   f.add(s1);
   f.add(s2);
   f.add(s3);
   s1.addAdjustmentListener(this);
   s2.addAdjustmentListener(this);
   s3.addAdjustmentListener(this);
   p1 = new Panel();
   p1.setBounds(120, 35, 170, 255);
   f.add(p1);
   f.setVisible(true);
 }
예제 #2
0
  private static void init() {
    // *** Create instructions for the user here ***
    String[] instructions = {
      "This is an AUTOMATIC test, simply wait until it is done.",
      "The result (passed or failed) will be shown in the",
      "message window below."
    };
    Sysout.createDialog();
    Sysout.printInstructions(instructions);

    Frame frame = new Frame("test for 6418028");
    frame.setLayout(new FlowLayout());
    Button btn1 = new Button("Button1");
    frame.add(btn1);
    TestButton btn2 = new TestButton("Button2");
    frame.add(btn2);
    frame.pack();
    frame.addWindowListener(
        new WindowAdapter() {
          @Override
          public void windowClosing(WindowEvent we) {
            we.getWindow().dispose();
          }
        });
    frame.setVisible(true);

    Util.waitForIdle(null);

    btn2.instrumentPeer();
    btn2.requestFocusInWindow();
    btn2.restorePeer();
    frame.dispose();
    RequestOnCompWithNullParent1.pass();
  } // End  init()
예제 #3
0
 MyF2() {
   Frame f = new Frame("graphics");
   Button b = new Button("line");
   f.add(m);
   f.add(b);
   b.addActionListener(this);
   f.setSize(400, 400);
   f.setLayout(new GridLayout(2, 1));
   f.setVisible(true);
 }
  public static void main(String s[]) {
    initParams(s);
    initAdapters();
    f = new Frame();
    final int[] modifiers = {InputEvent.SHIFT_MASK, InputEvent.CTRL_MASK};
    final String[] modifierNames = {"InputEvent.SHIFT_MASK", "InputEvent.CTRL_MASK"};
    f.setLayout(new FlowLayout());
    f.addMouseWheelListener(
        new MouseWheelListener() {
          public void mouseWheelMoved(MouseWheelEvent e) {
            System.out.println("WHEEL " + e);
          }
        });
    f.setSize(300, 300);
    f.setVisible(true);

    try {
      robot = new Robot();
      robot.delay(500);
      robot.mouseMove(
          f.getLocationOnScreen().x + f.getWidth() / 2,
          f.getLocationOnScreen().y + f.getHeight() / 2);
      if (autorun) {
        // testing buttons 1, 2, 3 only
        testPlainButtons();
        robot.delay(500);

        // testing buttons 1, 2, 3 with SHIFT, CTRL, ALT keyboard modifiers
        testButtonsWithShift();
        robot.delay(500);

        testButtonsWithControl();
        robot.delay(500);

        testButtonsWithAlt();
        robot.delay(500);
      } else {
        switch (testModifier) {
          case SHIFT:
            f.addMouseListener(adapterTest2);
            break;
          case CTRL:
            f.addMouseListener(adapterTest3);
            break;
          case ALT:
            f.addMouseListener(adapterTest4);
            break;
          default: // NONE inclusive
            f.addMouseListener(adapterTest1);
        }
      }
    } catch (Exception e) {
      throw new RuntimeException("Test failed.");
    }
  }
예제 #5
0
  public Bai2() {

    lbNumber1.setText("a =");
    lbNumber2.setText("b =");
    lbResult.setText("Kết quả:");
    txtNumber1.setText("0");
    txtNumber2.setText("0");
    txtResult.setText("0");
    btResult.setLabel("Thực hiện");
    choCalculator.add("Cộng");
    choCalculator.add("Trừ");
    choCalculator.add("Nhân");
    choCalculator.add("Chia");
    choCalculator.add("UCLN");
    choCalculator.add("BCNN");

    frMain.setBounds(100, 100, 400, 300);
    frMain.setBackground(Color.LIGHT_GRAY);
    frMain.setLayout(null);

    lbNumber1.setBounds(30, 50, 50, 20);
    lbNumber2.setBounds(30, 70, 50, 20);
    lbResult.setBounds(30, 140, 50, 20);

    choCalculator.setBounds(300, 70, 60, 20);

    btResult.setBounds(100, 100, 100, 20);

    txtNumber1.setBounds(100, 50, 150, 20);
    txtNumber2.setBounds(100, 70, 150, 20);
    txtResult.setBounds(100, 140, 150, 20);

    frMain.add(lbNumber1);
    frMain.add(lbNumber2);
    frMain.add(lbResult);
    frMain.add(txtNumber1);
    frMain.add(txtNumber2);
    frMain.add(txtResult);
    frMain.add(btResult);
    frMain.add(choCalculator);

    btResult.addActionListener(new ProcessButton());

    frMain.addWindowListener(
        new WindowAdapter() {
          public void windowsClosing(WindowEvent evt) {
            System.exit(0);
          }
        });
  }
예제 #6
0
 public void start() {
   // Get things going.  Request focus, set size, et cetera
   setSize(200, 200);
   setVisible(true);
   validate();
   Frame f = new Frame("Set action for Robot here.");
   f.setLayout(new FlowLayout());
   f.add(buttonNumber);
   f.add(pressOn);
   f.add(releaseOn);
   f.add(clickOn);
   f.add(target);
   f.pack();
   f.setVisible(true);
 } // start()
예제 #7
0
 public static void main(String[] args) {
   Frame f = new Frame();
   f.setLocation(300, 200);
   f.setSize(200, 200);
   f.setLayout(null); // 取消布局管理器
   bt.addMouseListener(new MouseMove()); // 注册鼠标事件监听器
   bt.setBackground(Color.cyan);
   bt.setBounds(new Rectangle(45, 100, 90, 30));
   f.add(bt);
   f.pack();
   f.addWindowListener(
       new WindowAdapter() { // 关闭窗口
         public void windowClosing(WindowEvent e) {
           System.exit(0);
         }
       });
   f.setVisible(true); // 设置窗体可见
 }
예제 #8
0
 public void go() {
   f = new Frame("This is a FileDialog Test");
   f.addWindowListener(
       new WindowAdapter() {
         public void windowClosing(WindowEvent e) {
           System.exit(0); // 종료하기
         }
       });
   f.setLayout(new FlowLayout());
   bOpen = new Button("Open");
   bOpen.addActionListener(this);
   bSave = new Button("Save");
   bSave.addActionListener(this);
   // 열기 다이얼로그 박스만들기
   fdOpen = new FileDialog(f, "I'm a Open Dialog", FileDialog.LOAD);
   // 저장 다이얼로그 박스 만들기
   fdSave = new FileDialog(f, "I'm a Save Dialog", FileDialog.SAVE);
   f.add(bOpen);
   f.add(bSave);
   f.setSize(200, 200);
   f.setVisible(true);
 }
예제 #9
0
  void init() {
    mainFrame = new Frame();
    mainFrame.setBounds(400, 500, 800, 600);
    mainFrame.setLayout(new FlowLayout());
    mainFrame.setResizable(false);

    upPanel = new Panel();
    downPanel = new Panel();
    addressTextField = new TextField(75);
    gotoButton = new Button("转到");
    contentTextArea = new TextArea(30, 82);

    upPanel.add(addressTextField);
    upPanel.add(gotoButton);
    downPanel.add(contentTextArea);

    mainFrame.add(upPanel);
    mainFrame.add(downPanel);

    addEvent();

    mainFrame.setVisible(true);
  }
예제 #10
0
  public static void main(String[] args) {

    Frame AFrame = new Frame("Frame with components");

    Label lblOne = new Label("This is a label");
    Button btn1 = new Button("This is a button");
    TextField tf1 = new TextField();
    TextArea ta1 = new TextArea(12, 40);

    tf1.setText("This is a textbox");
    ta1.setText("Number of columns in this textarea: " + ta1.getColumns());

    // the add() method of the Frame class is
    // used to add components to the frame
    AFrame.add(lblOne);
    AFrame.add(btn1);
    AFrame.add(tf1);
    AFrame.add(ta1);

    AFrame.setSize(450, 300);
    AFrame.setLayout(new FlowLayout());
    AFrame.setVisible(true);
    AFrame.addWindowListener(new demo());
  }
예제 #11
0
  OuterEventDemo(String s) {
    f = new Frame(s);
    f.addWindowListener(new WindowsEventListner());
    b = new Button("OK");
    b1 = new Button("CANCEL");
    b.setBounds(20, 100, 40, 40);
    b1.setBounds(20, 180, 40, 40);
    f.add(b);
    f.add(b1);

    b.addMouseListener(new MouseEventListener(this));
    b1.addMouseListener(new MouseEventListener(this));
    Outer o = new Outer(this);
    b.addActionListener(o);
    b1.addActionListener(o);

    tf = new TextField();
    tf.setBounds(20, 40, 100, 40);
    f.add(tf);
    tf.addKeyListener(new KeyEventListener());
    f.setLayout(null);
    f.setSize(400, 400);
    f.setVisible(true);
  }
예제 #12
0
  public TestXEmbedServer(boolean manual) {

    // Enable testing extensions in XEmbed server
    System.setProperty("sun.awt.xembed.testing", "true");

    f = new Frame("Main frame");
    f.addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            synchronized (TestXEmbedServer.this) {
              TestXEmbedServer.this.notifyAll();
            }
            dummy.dispose();
            f.dispose();
          }
        });

    f.setLayout(new BorderLayout());

    Container bcont = new Container();

    toFocus = new Button("Click to focus server");
    final TextField tf = new TextField(20);
    tf.setName("0");
    DragSource ds = new DragSource();
    final DragSourceListener dsl =
        new DragSourceAdapter() {
          public void dragDropEnd(DragSourceDropEvent dsde) {}
        };
    final DragGestureListener dgl =
        new DragGestureListener() {
          public void dragGestureRecognized(DragGestureEvent dge) {
            dge.startDrag(null, new StringSelection(tf.getText()), dsl);
          }
        };
    ds.createDefaultDragGestureRecognizer(tf, DnDConstants.ACTION_COPY, dgl);

    final DropTargetListener dtl =
        new DropTargetAdapter() {
          public void drop(DropTargetDropEvent dtde) {
            dtde.acceptDrop(DnDConstants.ACTION_COPY);
            try {
              tf.setText(
                  tf.getText()
                      + (String) dtde.getTransferable().getTransferData(DataFlavor.stringFlavor));
            } catch (Exception e) {
            }
          }
        };
    final DropTarget dt = new DropTarget(tf, dtl);

    Button b_add = new Button("Add client");
    b_add.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            addClient();
          }
        });
    Button b_remove = new Button("Remove client");
    b_remove.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            if (clientCont.getComponentCount() != 0) {
              clientCont.remove(clientCont.getComponentCount() - 1);
            }
          }
        });
    b_close = new JButton("Close modal dialog");
    b_close.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            modal_d.dispose();
          }
        });
    b_modal = new Button("Show modal dialog");
    b_modal.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            modal_d = new JDialog(f, "Modal dialog", true);
            modal_d.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
            modal_d.setBounds(0, 100, 200, 50);
            modal_d.getContentPane().add(b_close);
            modal_d.validate();
            modal_d.show();
          }
        });

    bcont.add(tf);
    bcont.add(toFocus);
    bcont.add(b_add);
    bcont.add(b_remove);
    bcont.add(b_modal);
    if (manual) {
      Button pass = new Button("Pass");
      pass.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              passed = true;
              synchronized (TestXEmbedServer.this) {
                TestXEmbedServer.this.notifyAll();
              }
            }
          });
      bcont.add(pass);
      Button fail = new Button("Fail");
      fail.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              passed = false;
              synchronized (TestXEmbedServer.this) {
                TestXEmbedServer.this.notifyAll();
              }
            }
          });
      bcont.add(fail);
    }
    b_modal.setName("2");
    bcont.setLayout(new FlowLayout());
    f.add(bcont, BorderLayout.NORTH);

    clientCont = Box.createVerticalBox();
    f.add(clientCont, BorderLayout.CENTER);

    dummy = new JFrame("Dummy");
    dummy.getContentPane().add(new JButton("Button"));
    dummy.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    dummy.setBounds(0, VERTICAL_POSITION, 100, 100);
    dummy.setVisible(true);

    f.setBounds(300, VERTICAL_POSITION, 800, 300);
    f.setVisible(true);
  }
예제 #13
0
  /**
   *   Handles when aides cover each other. They must tell
   *   us who they're covering so that that poor person
   *   doesn't get a missed shift. This of course means i
   *   have to work on MyHours some more... If they select
   *   a valid userid to cover for makes the appropriate
   *   entry in AIDELOG.
   *
   *   @param An SaoWorker who is covering someone else
   */
  public void WhoRUCovering(final SaoWorker w)
  {
    int i = 0;
    int h = bd.getHours();
    int m = bd.getMinutes();
    if (((m >= 20) && (m < 30)) || ((m >= 50) && (m < 60)))
    {
      if (m < 30) { m = m + 10; }
      else { m = m + 10 - 60; h = h + 1; }      
    }
    int dopp = bd.getDoPP();
    if (dopp > 7) { dopp = dopp - 7; }
    String slotid = bd.getSlot(h, m, dopp);
    String q = "select * from AIDESCHED where " + slotid + "=1";
    final String[] userids = {"", "", "", "", "", "", "", "", "", ""};
    final BatSQL bSQL = new BatSQL();
    ResultSet rs = bSQL.query(q);
    
    try
    {
      boolean more = rs.next();
      if (more) //because there might be only one person for this slot
      {
        while (more)
        {
          userids[i] = rs.getString(1);
          i++;
          more = rs.next();
        }
      } //end of if more
    } //end of try
    catch (SQLException ex)
    {
      System.out.println("!*******SQLException caught*******!");
      System.out.println("WhoRUCovering");
      while (ex != null)
      {
        System.out.println ("SQLState: " + ex.getSQLState ());
        System.out.println ("Message:  " + ex.getMessage ());
        System.out.println ("Vendor:   " + ex.getErrorCode ());
        ex = ex.getNextException ();
        System.out.println ("");
      }
      System.exit(0);
    } //end catching SQLExceptions
    catch (java.lang.Exception ex)
    {
      System.out.println("!*******Exception caught*******!");
      System.out.println("WhoRUCovering");      
      System.exit(0);
    } //end catching other Exceptions
    
    final Frame coverF = new Frame("Covering?");
    final Panel     p  = new Panel();
    final Panel  btnP  = new Panel();
    final List  coverL = new List();
    Button    ok = new Button("Cover");
    Button   nok = new Button("Cancel");
    final int i2 = i;
    
    ok.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e)
      {
        String id = coverL.getSelectedItem();
        BatSQL bS = new BatSQL();
        String a = "insert into aidelog values ('C', \"" + id + "\", \"" + bd.getDate() + "\", " + bd.getStringHours() + bd.getStringMinutes() + ", 'I')";
        bS.update(a);
        a = "update AIDEDIN set COVERING='" + id + "' where USERID='" + w.getUserID() + "'";
        bS.update(a);
        bS.disconnect();
        coverF.dispose();
      }
    });
    nok.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e)
      {
        coverF.dispose();
      }
    });
    
    btnP.setLayout(new FlowLayout());
    btnP.add(ok);
    btnP.add(nok);
    
    p.setLayout(new BorderLayout());
    p.add(new Label("Who are you covering for?"), BorderLayout.NORTH);
    int j;
    for (j = 0; j <= i; j++)
    {
      coverL.add(userids[j]);
    }
    p.add(coverL, BorderLayout.CENTER);
    p.add(btnP, BorderLayout.SOUTH);
    
    coverL.select(0);
    
    coverF.setLayout(new FlowLayout());
    coverF.add(p);    
    coverF.pack();
    coverF.setLocation(200, 200);
    coverF.show();

  } //end of WhoRUCovering