Exemplo n.º 1
0
 public static void main(String[] args) {
   Frame f = new Frame("thread");
   f.setLayout(null);
   f.setBounds(300,60,300,200); f.setVisible(true);
   f.add(new MyTextArea(150,0,Thread.NORM_PRIORITY));
   f.add(new MyTextArea(0,0,Thread.MAX_PRIORITY));
 }  
Exemplo n.º 2
0
 public void init() {
   f.setLayout(null);
   b1.setBounds(20, 30, 90, 28);
   f.add(b1);
   b2.setBounds(50, 45, 120, 35);
   f.add(b2);
   f.setBounds(50, 50, 200, 100);
   f.setVisible(true);
 }
Exemplo n.º 3
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);
          }
        });
  }
Exemplo n.º 4
0
  public void start() {
    Toolkit.getDefaultToolkit()
        .addAWTEventListener(
            new AWTEventListener() {
              public void eventDispatched(AWTEvent e) {
                System.out.println(e.toString());
              }
            },
            FocusEvent.FOCUS_EVENT_MASK
                | WindowEvent.WINDOW_FOCUS_EVENT_MASK
                | WindowEvent.WINDOW_EVENT_MASK);

    frame = new Frame("Frame");
    frame.setName("Frame-owner");
    frame.setBounds(100, 0, 100, 100);
    dialog = new Dialog(frame, "Dialog");
    dialog.setName("Dialog-owner");
    dialog.setBounds(100, 0, 100, 100);

    window1 = new Window(frame);
    window1.setName("1st child");
    window1.setBounds(100, 300, 100, 100);
    window2 = new Window(window1);
    window2.setName("2nd child");
    window2.setBounds(100, 500, 100, 100);

    test1(frame, window1);
    test2(frame, window1, window2);
    test3(frame, window1, window2);

    window1 = new Window(dialog);
    window1.setBounds(100, 300, 100, 100);
    window1.setName("1st child");
    window2 = new Window(window1);
    window2.setName("2nd child");
    window2.setBounds(100, 500, 100, 100);

    test1(dialog, window1);
    test2(dialog, window1, window2);
    test3(dialog, window1, window2);

    System.out.println("Test passed.");
  }
Exemplo n.º 5
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);
  }
Exemplo n.º 6
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);
  }