Example #1
0
  public void launchCalc() {
    f.add(tf, BorderLayout.NORTH);
    p2 = new Panel();
    p2.setLayout(new GridLayout(4, 5));
    p2.add(b1);
    p2.add(b2);
    p2.add(b3);
    p2.add(b18);
    p2.add(b10);
    p2.add(b6);
    p2.add(b7);
    p2.add(b8);
    p2.add(b19);
    p2.add(b4);
    p2.add(b11);
    p2.add(b12);
    p2.add(b13);
    p2.add(b14);
    p2.add(b9);
    p2.add(b16);
    p2.add(b17);
    p2.add(b20);
    p2.add(b15);
    p2.add(b5);

    f.add(p2, BorderLayout.CENTER);
    f.pack();
    f.setSize(250, 200);
    f.setVisible(true);
  }
    public void mouseClicked(MouseEvent ev) {
      Window w = (Window) ev.getSource();
      Frame f = null;

      if (w instanceof Frame) {
        f = (Frame) w;
      } else {
        return;
      }

      Point convertedPoint = SwingUtilities.convertPoint(w, ev.getPoint(), getTitlePane());

      int state = f.getExtendedState();
      if (getTitlePane() != null && getTitlePane().contains(convertedPoint)) {
        if ((ev.getClickCount() % 2) == 0 && ((ev.getModifiers() & InputEvent.BUTTON1_MASK) != 0)) {
          if (f.isResizable()) {
            if ((state & Frame.MAXIMIZED_BOTH) != 0) {
              f.setExtendedState(state & ~Frame.MAXIMIZED_BOTH);
            } else {
              f.setExtendedState(state | Frame.MAXIMIZED_BOTH);
            }
            return;
          }
        }
      }
    }
Example #3
0
 public static void main(String[] args) {
   try {
     if (args.length != 1) throw new IllegalArgumentException("Wrong number of arguments");
     FileReader in = new FileReader(args[0]);
     HardcopyWriter out = null;
     Frame f = new Frame("PrintFile: " + args[0]);
     f.setSize(200, 50);
     f.show();
     try {
       out = new HardcopyWriter(f, args[0], 10, .75, .75, .75, .75);
     } catch (HardcopyWriter.PrintCanceledException e) {
       System.exit(0);
     }
     f.setVisible(false);
     char[] buffer = new char[4096];
     int numchars;
     while ((numchars = in.read(buffer)) != -1) out.write(buffer, 0, numchars);
     out.close();
   } catch (Exception e) {
     System.err.println(e);
     System.err.println("Usage: java HardcopyWriter$PrintFile <filename>");
     System.exit(1);
   }
   System.exit(0);
 }
Example #4
0
  /**
   * Creates a new connection to the specified host of specified type. <br>
   * <br>
   * type: Type of connection to create <br>
   * destination: Host to connect to (in "host:port" or "host" syntax)
   */
  public Connection(java.net.InetAddress host, int port, PluginContext ctx)
      throws MessagingNetworkException, java.io.IOException {
    if (TRAKTOR_USED) {
      if (traktorConnectionDown) throw new IOException("network is down");

      traktor = new Frame("" + host + ":" + port + " - Traktor");
      final Checkbox c = new Checkbox("break this & ALL future connections");
      c.setState(traktorConnectionDown);
      c.addItemListener(
          new ItemListener() {
            public void itemStateChanged(ItemEvent e) {
              traktorConnectionDown = c.getState();
              try {
                if (traktorConnectionDown) closeSocket();
              } catch (Exception ex) {
              }
            }
          });
      traktor.add(c);
      traktor.setSize(100, 50);
      traktor.setLocation(230, 450);
      traktor.setVisible(true);
    } else {
      traktor = null;
    }
  }
Example #5
0
    @Override
    public void actionPerformed(ActionEvent e) {
      Frame frame = getFrame();
      JFileChooser chooser = new JFileChooser();
      int ret = chooser.showOpenDialog(frame);

      if (ret != JFileChooser.APPROVE_OPTION) {
        return;
      }

      File f = chooser.getSelectedFile();
      if (f.isFile() && f.canRead()) {
        Document oldDoc = getEditor().getDocument();
        if (oldDoc != null) {
          oldDoc.removeUndoableEditListener(undoHandler);
        }
        if (elementTreePanel != null) {
          elementTreePanel.setEditor(null);
        }
        getEditor().setDocument(new PlainDocument());
        frame.setTitle(f.getName());
        Thread loader = new FileLoader(f, editor.getDocument());
        loader.start();
      } else {
        JOptionPane.showMessageDialog(
            getFrame(),
            "Could not open file: " + f,
            "Error opening file",
            JOptionPane.ERROR_MESSAGE);
      }
    }
Example #6
0
  public void addClient() {
    client =
        new Canvas() {
          public void paint(Graphics g) {
            super.paint(g);
          }
        };
    client.setBackground(new Color(30, 220, 40));
    clientCont.add(client);
    clientCont.validate();
    final ComponentAccessor acc = AWTAccessor.getComponentAccessor();
    WindowIDProvider pid = (WindowIDProvider) acc.getPeer(client);
    log.fine("Added XEmbed server(Canvas) with X window ID " + pid.getWindow());
    Rectangle toFocusBounds = toFocus.getBounds();
    toFocusBounds.setLocation(toFocus.getLocationOnScreen());
    f.validate();

    // KDE doesn't accept clicks on title as activation - click below title
    Rectangle fbounds = f.getBounds();
    fbounds.y += f.getInsets().top;
    fbounds.height -= f.getInsets().top;

    Process proc =
        startClient(
            new Rectangle[] {
              fbounds,
              dummy.getBounds(),
              toFocusBounds,
              new Rectangle(b_modal.getLocationOnScreen(), b_modal.getSize()),
              new Rectangle(10, 130, 20, 20)
            },
            pid.getWindow());
    new ClientWatcher(client, proc, clientCont).start();
  }
    public void mouseMoved(MouseEvent ev) {
      JRootPane root = getRootPane();

      if (root.getWindowDecorationStyle() == JRootPane.NONE) {
        return;
      }

      Window w = (Window) ev.getSource();

      Frame f = null;
      Dialog d = null;

      if (w instanceof Frame) {
        f = (Frame) w;
      } else if (w instanceof Dialog) {
        d = (Dialog) w;
      }

      // Update the cursor
      int cursor = getCursor(calculateCorner(w, ev.getX(), ev.getY()));

      if (cursor != 0
          && ((f != null && (f.isResizable() && (f.getExtendedState() & Frame.MAXIMIZED_BOTH) == 0))
              || (d != null && d.isResizable()))) {
        w.setCursor(Cursor.getPredefinedCursor(cursor));
      } else {
        w.setCursor(lastCursor);
      }
    }
Example #8
0
 public static void main(String[] args) {
   // TODO 自动生成的方法存根
   int pause = 5;
   int grid = 8;
   Frame f = new ColorBoxes2(pause, grid);
   f.setSize(500, 400);
   f.setVisible(true);
 }
Example #9
0
 public static void main(String[] args) {
   Frame f = new Frame("Test");
   Button b = new Button("Press me!");
   Monitor bh = new Monitor();
   b.addActionListener(bh);
   f.add(b, BorderLayout.CENTER);
   f.pack();
   f.setVisible(true);
 }
  public static void main(String args[]) {
    Frame f = new SampleFrame("File Dialog Demo");
    f.setVisible(true);
    f.setSize(200, 200);

    FileDialog fd = new FileDialog(f, "File Dialog");

    fd.setVisible(true);
  }
Example #11
0
 public static void main(String[] args) {
   Frame f = new Frame("Viewer");
   Viewer view = new Viewer();
   f.addWindowListener(view);
   f.add(view);
   f.setSize(300, 300);
   view.init();
   view.start();
   f.setVisible(true);
 }
Example #12
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);
 }
Example #13
0
 // set the frame on the center of bildschirm
 private static void setFrameCenter(Frame f, boolean flag) {
   // f.getToolkit();
   //	Dimension screen=f.getToolkit().getDefaultToolkit().getScreenSize();//获取屏幕尺寸对象
   Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); // 获取屏幕尺寸对象
   Dimension myframe = f.getSize(); // 获取当前窗体的尺寸对象
   int w = (screen.width - myframe.width) / 2; // 水平位置
   int h = (screen.height - myframe.width) / 2; // 垂直位置
   f.setLocation(w, h);
   f.setResizable(flag);
 }
  /** Method declaration */
  private void initGUI() {

    Panel pQuery = new Panel();
    Panel pCommand = new Panel();

    pResult = new Panel();

    pQuery.setLayout(new BorderLayout());
    pCommand.setLayout(new BorderLayout());
    pResult.setLayout(new BorderLayout());

    Font fFont = new Font("Dialog", Font.PLAIN, 12);

    txtCommand = new TextArea(5, 40);

    txtCommand.addKeyListener(this);

    txtResult = new TextArea(20, 40);

    txtCommand.setFont(fFont);
    txtResult.setFont(new Font("Courier", Font.PLAIN, 12));

    butExecute = new Button("Execute");
    butClear = new Button("Clear");

    butExecute.addActionListener(this);
    butClear.addActionListener(this);
    pCommand.add("East", butExecute);
    pCommand.add("West", butClear);
    pCommand.add("Center", txtCommand);

    gResult = new Grid();

    setLayout(new BorderLayout());
    pResult.add("Center", gResult);
    pQuery.add("North", pCommand);
    pQuery.add("Center", pResult);
    fMain.add("Center", pQuery);

    tTree = new Tree();

    // (ulrivo): screen with less than 640 width
    Dimension d = Toolkit.getDefaultToolkit().getScreenSize();

    if (d.width >= 640) {
      tTree.setMinimumSize(new Dimension(200, 100));
    } else {
      tTree.setMinimumSize(new Dimension(80, 100));
    }

    gResult.setMinimumSize(new Dimension(200, 300));
    fMain.add("West", tTree);
    doLayout();
    fMain.pack();
  }
Example #15
0
 /**
  * Centre the dialog box in the frame. This must be called after the size has been established,
  * i.e. after the buttons etc. are arranged and pack() is called
  */
 public void centreInFrame() {
   Dimension frame_size = parent.getSize();
   Point frame_location = parent.getLocation();
   int centre_x = frame_location.x + frame_size.width / 2;
   int centre_y = frame_location.y + frame_size.height / 2;
   ;
   int xloc = centre_x - this.getSize().width / 2;
   int yloc = centre_y - this.getSize().height / 2;
   this.setLocation(new Point(xloc, yloc));
   this.requestFocus();
 }
Example #16
0
 public static void main(String[] args) {
   Frame f = new ToeTestNew();
   f.addWindowListener(
       new WindowAdapter() {
         public void windowClosing(WindowEvent e) {
           System.exit(0);
         }
       });
   f.setSize(200, 100);
   f.setVisible(true);
 }
 // test BUTTON1, 2 and 3 without any modifiers keys
 public static void testPlainButtons() {
   System.out.println("Testing buttons without modifiers.");
   f.addMouseListener(adapterTest1);
   for (int button : mouseButtons) {
     robot.mousePress(button);
     robot.delay(100);
     robot.mouseRelease(button);
   }
   robot.delay(1000);
   f.removeMouseListener(adapterTest1);
 }
Example #18
0
 private boolean ignoreArrowKeys(ImagePlus imp) {
   Frame frame = WindowManager.getFrontWindow();
   String title = frame.getTitle();
   if (title != null && title.equals("ROI Manager")) return true;
   // Control Panel?
   if (frame != null && frame instanceof javax.swing.JFrame) return true;
   ImageWindow win = imp.getWindow();
   // LOCI Data Browser window?
   if (imp.getStackSize() > 1 && win != null && win.getClass().getName().startsWith("loci"))
     return true;
   return false;
 }
Example #19
0
 public static void main(String[] args) {
   // TODO 自动生成的方法存根
   Frame f = new DynamicEvents();
   f.addWindowListener(
       new WindowAdapter() {
         public void windowClosing(WindowEvent e) {
           System.exit(0);
         }
       });
   f.setSize(300, 200);
   f.show();
 }
 public void init() {
   // 以匿名内部类的形式来创建事件监听器对象
   f.addWindowListener(
       new WindowAdapter() {
         public void windowClosing(WindowEvent e) {
           ta.append("用户试图关闭窗口!\n");
           System.exit(0);
         }
       });
   f.add(ta);
   f.pack();
   f.setVisible(true);
 }
  private void restore() {
    Frame frame = getFrame();

    if (frame == null) {
      return;
    }

    if ((myState & Frame.ICONIFIED) != 0) {
      frame.setExtendedState(myState & ~Frame.ICONIFIED);
    } else {
      frame.setExtendedState(myState & ~Frame.MAXIMIZED_BOTH);
    }
  }
Example #22
0
 public KeyOptionDialog(Frame parent) {
   this.setTitle("Keyboard Setting");
   this.setModal(true);
   this.setResizable(false);
   // this.setSize(230, 284);
   this.setBounds((int) parent.getX() + 20, (int) parent.getY() + 75, 230, 200);
   ls.setLanguage(gameconfigure.getLanguage());
   try {
     jbInit();
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
 // test BUTTON1, 2 and 3 with ALT key
 public static void testButtonsWithAlt() {
   System.out.println("Testing buttons with ALT modifier.");
   f.addMouseListener(adapterTest4);
   for (int button : mouseButtons) {
     robot.keyPress(KeyEvent.VK_ALT);
     robot.mousePress(button);
     robot.delay(100);
     robot.mouseRelease(button);
     robot.keyRelease(KeyEvent.VK_ALT);
   }
   robot.delay(1000);
   f.removeMouseListener(adapterTest4);
 }
Example #24
0
 public static void main(String args[]) {
   Frame F = new Frame();
   Mouse1 P = new Mouse1(args[0]);
   F.add(P, BorderLayout.CENTER);
   F.setSize(500, 200);
   F.setVisible(true);
   F.addWindowListener(
       new WindowAdapter() {
         public void windowClosing(WindowEvent e) {
           System.exit(0);
         }
       });
 }
Example #25
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);
          }
        });
  }
Example #26
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()
Example #27
0
    public void actionPerformed(ActionEvent e) {
      Frame frame = getFrame();
      JFileChooser chooser = new JFileChooser();
      int ret = chooser.showSaveDialog(frame);

      if (ret != JFileChooser.APPROVE_OPTION) {
        return;
      }

      File f = chooser.getSelectedFile();
      frame.setTitle(f.getName());
      Thread saver = new FileSaver(f, editor.getDocument());
      saver.start();
    }
Example #28
0
 public static void main(String[] args) {
   Counterl applet = new Counterl();
   Frame aFrame = new Frame("Counter1");
   aFrame.addWindowListener(
       new WindowAdapter() {
         public void windowClosing(WindowEvent e) {
           System.exit(0);
         }
       });
   aFrame.add(applet, BorderLayout.CENTER);
   aFrame.setSize(300, 200);
   applet.init();
   applet.start();
   aFrame.setVisible(true);
 }
Example #29
0
 public void run() {
   try {
     uglyjoglhack();
     if (state == null)
       throw (new RuntimeException("State applier is still null after redraw"));
     synchronized (drawfun) {
       drawfun.notifyAll();
     }
     while (true) {
       long then = System.currentTimeMillis();
       int waited = 0;
       synchronized (drawfun) {
         while ((curdraw = bufdraw) == null) drawfun.wait();
         bufdraw = null;
         drawfun.notifyAll();
         waited += System.currentTimeMillis() - then;
       }
       CPUProfile.Frame curf = null;
       if (Config.profile) curdraw.pf = curf = rprof.new Frame();
       uglyjoglhack();
       if (curf != null) {
         curf.tick("aux");
         curf.fin();
       }
       long now = System.currentTimeMillis();
       waited += now - curdraw.doneat;
       ridle = (ridle * 0.95) + (((double) waited / ((double) (now - then))) * 0.05);
       curdraw = null;
     }
   } catch (InterruptedException e) {
     return;
   }
 }
 public void dispose(boolean toDispose) {
   if (toDispose) {
     super.dispose();
     frame.toFront();
   }
   if (client != null) client.dialogDismissed(this);
 }