public void launchFrame() { add(panCircle, BorderLayout.CENTER); // add Circle panel add(panButtons, BorderLayout.SOUTH); // add Buttons panel panCircle.setLayout(new BorderLayout()); panCircle.addMouseListener( new MouseListener() { @Override public void mouseClicked(MouseEvent e) { // считываем клик мышки и перерисовываем X = e.getX(); Y = e.getY(); // R = Integer.parseInt(textFieldR.getText()); ovalnew[num][0] = e.getX(); ovalnew[num][1] = e.getY(); ovalnew[num][2] = Integer.parseInt(textFieldR.getText()); num++; if (num == 6) { num = 0; } panCircle.repaint(); panCircle.repaint(); } @Override public void mousePressed(MouseEvent e) { // TODO Auto-generated method stub } @Override public void mouseReleased(MouseEvent e) { // TODO Auto-generated method stub } @Override public void mouseEntered(MouseEvent e) { // TODO Auto-generated method stub } @Override public void mouseExited(MouseEvent e) { // TODO Auto-generated method stub } }); panButtons.setSize(40, 300); // buttons panel size panButtons.setLayout(new GridLayout(1, 4)); // 1x4 cell panButtons.add(textFieldX); // add textFieldX panButtons.add(textFieldY); // add textFieldY panButtons.add(textFieldR); // add textFieldR panButtons.add(okButton); // add Ok Button okButton.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { X = Integer.parseInt(textFieldX.getText()); Y = Integer.parseInt(textFieldY.getText()); R = Integer.parseInt(textFieldR.getText()); ovalnew[num][0] = Integer.parseInt(textFieldX.getText()); ovalnew[num][1] = Integer.parseInt(textFieldY.getText()); ovalnew[num][2] = Integer.parseInt(textFieldR.getText()); num++; if (num == 6) { num = 0; } panCircle.repaint(); // тут заполнять массив } }); setVisible(true); setSize(300, 300); // frame size setTitle("Half-Random Circle"); // title addWindowListener(this); }
/** * If 'applet' is not null, creates a new ImageJ frame that runs as an applet. If 'mode' is * ImageJ.EMBEDDED and 'applet is null, creates an embedded (non-standalone) version of ImageJ. */ public ImageJ(java.applet.Applet applet, int mode) { super("ImageJ"); embedded = applet == null && (mode == EMBEDDED || mode == NO_SHOW); this.applet = applet; String err1 = Prefs.load(this, applet); if (IJ.isLinux()) { backgroundColor = new Color(240, 240, 240); setBackground(backgroundColor); } Menus m = new Menus(this, applet); String err2 = m.addMenuBar(); m.installPopupMenu(this); setLayout(new GridLayout(2, 1)); // Tool bar toolbar = new Toolbar(); toolbar.addKeyListener(this); add(toolbar); // Status bar statusBar = new Panel(); statusBar.setLayout(new BorderLayout()); statusBar.setForeground(Color.black); statusBar.setBackground(backgroundColor); statusLine = new Label(); statusLine.setFont(SansSerif12); statusLine.addKeyListener(this); statusLine.addMouseListener(this); statusBar.add("Center", statusLine); progressBar = new ProgressBar(120, 20); progressBar.addKeyListener(this); progressBar.addMouseListener(this); statusBar.add("East", progressBar); statusBar.setSize(toolbar.getPreferredSize()); add(statusBar); IJ.init(this, applet); addKeyListener(this); addWindowListener(this); setFocusTraversalKeysEnabled(false); Point loc = getPreferredLocation(); Dimension tbSize = toolbar.getPreferredSize(); int ijWidth = tbSize.width + 10; int ijHeight = 100; setCursor(Cursor.getDefaultCursor()); // work-around for JDK 1.1.8 bug if (mode != NO_SHOW) { if (IJ.isWindows()) try { setIcon(); } catch (Exception e) { } setBounds(loc.x, loc.y, ijWidth, ijHeight); // needed for pack to work setLocation(loc.x, loc.y); pack(); setResizable(!(IJ.isMacintosh() || IJ.isWindows())); // make resizable on Linux show(); } if (err1 != null) IJ.error(err1); if (err2 != null) { IJ.error(err2); IJ.runPlugIn("ij.plugin.ClassChecker", ""); } m.installStartupMacroSet(); if (IJ.isMacintosh() && applet == null) { Object qh = null; qh = IJ.runPlugIn("MacAdapter", ""); if (qh == null) IJ.runPlugIn("QuitHandler", ""); } if (applet == null) IJ.runPlugIn("ij.plugin.DragAndDrop", ""); String str = m.getMacroCount() == 1 ? " macro" : " macros"; IJ.showStatus(version() + m.getPluginCount() + " commands; " + m.getMacroCount() + str); // if (applet==null && !embedded && Prefs.runSocketListener) // new SocketListener(); configureProxy(); if (applet == null) loadCursors(); }
public MyFrame() { super("My Dialer"); GridLayout gl = new GridLayout(7, 1, 2, 2); setLayout(gl); Panel displayPanel = new Panel(); Panel padPanel = new Panel(); Panel padPanel1 = new Panel(); Panel padPanel2 = new Panel(); Panel padPanel3 = new Panel(); Panel padPanel4 = new Panel(); Panel butPanel = new Panel(); Panel dialingPanel = new Panel(); tfPhoneNumber = new TextField(20); displayPanel.add(tfPhoneNumber); // padPanel.setLayout(new GridLayout(4,3,2,2)); int i; for (i = 0; i < 9; i++) { dialPad[i] = new Button(Integer.toString(i + 1)); } dialPad[9] = new Button("*"); dialPad[10] = new Button("0"); dialPad[11] = new Button("#"); MyMouseAdapter ma = new MyMouseAdapter(); for (i = 0; i < 12; i++) { dialPad[i].setForeground(Color.blue); dialPad[i].addMouseListener(ma); dialPad[i].setPreferredSize(new Dimension(25, 25)); // dialPad[i].setSize(35,35); // padPanel.add(dialPad[i]); } // Try flow layout as grid layout does not give set button size. for (i = 0; i < 3; i++) { padPanel1.add(dialPad[i]); } for (i = 3; i < 6; i++) { padPanel2.add(dialPad[i]); } for (i = 6; i < 9; i++) { padPanel3.add(dialPad[i]); } for (i = 9; i < 12; i++) { padPanel4.add(dialPad[i]); } tfDialing = new TextField(20); dialingPanel.add(tfDialing); dialButton = new Button("Dial"); cancelButton = new Button("Cancel/Erase"); tfDialing.setEditable(false); dialButton.setSize(40, 20); cancelButton.setSize(40, 20); dialButton.addMouseListener(ma); dialButton.setForeground(Color.blue); cancelButton.setForeground(Color.blue); cancelButton.addMouseListener(ma); butPanel.add(dialButton); butPanel.add(cancelButton); displayPanel.setSize(250, 40); padPanel1.setSize(250, 40); padPanel2.setSize(180, 40); padPanel3.setSize(180, 40); padPanel4.setSize(180, 40); butPanel.setSize(250, 25); dialingPanel.setSize(250, 20); // Add Panels to Frame add(displayPanel); // add(padPanel); add(padPanel1); add(padPanel2); add(padPanel3); add(padPanel4); add(butPanel); add(dialingPanel); // MyMouseAdapter ma = new MyMouseAdapter(); // button.addMouseListener(ma); setSize(250, 250); setVisible(true); }