public static void startMainThread(String s, String s1, String s2) { boolean flag = false; String s3 = s; Frame frame = new Frame("Minecraft"); Canvas canvas = new Canvas(); frame.setLayout(new BorderLayout()); frame.add(canvas, "Center"); canvas.setPreferredSize(new Dimension(854, 480)); frame.pack(); frame.setLocationRelativeTo(null); MinecraftImpl minecraftimpl = new MinecraftImpl(frame, canvas, null, 854, 480, flag, frame); Thread thread = new Thread(minecraftimpl, "Minecraft main thread"); thread.setPriority(10); minecraftimpl.minecraftUri = "www.minecraft.net"; if (s3 != null && s1 != null) { minecraftimpl.session = new Session(s3, s1); } else { minecraftimpl.session = new Session( (new StringBuilder()) .append("Player") .append(System.currentTimeMillis() % 1000L) .toString(), ""); } if (s2 != null) { String as[] = s2.split(":"); minecraftimpl.setServer(as[0], Integer.parseInt(as[1])); } frame.setVisible(true); frame.addWindowListener(new GameWindowListener(minecraftimpl, thread)); thread.start(); }
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()
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 static void main(String[] args) { for (int i = 0; i < 100; i++) { Frame f = new Frame(); f.pack(); f.dispose(); } Vector garbage = new Vector(); while (true) { try { garbage.add(new byte[1000]); } catch (OutOfMemoryError e) { break; } } garbage = null; Vector<WeakReference<Window>> windowList = (Vector<WeakReference<Window>>) AppContext.getAppContext().get(Window.class); if (windowList != null && !windowList.isEmpty()) { throw new RuntimeException("Test FAILED: Window list is not empty: " + windowList.size()); } System.out.println("Test PASSED"); }
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); }
/** 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(); }
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); }
public static void main(String[] args) { Frame f = new Frame("测试窗口"); // 设置Frame容器使用FlowLayout布局管理器 f.setLayout(new FlowLayout(FlowLayout.LEFT, 20, 5)); // 向窗口中添加10个按钮 for (int i = 0; i < 10; i++) { f.add(new Button("按钮" + i)); } // 设置窗口为最佳大小 f.pack(); // 将窗口显示出来(Frame对象默认处于隐藏状态) f.setVisible(true); }
// This is where things get started public static void main(String args[]) { // Create a new frame to hold the canvas and put it up. Frame fm = new Frame(); Animate b = new Animate(); // Make it visible and set size b.setVisible(true); b.setSize(300, 300); System.out.println("Here we go"); // Add the canvas to the frame and make it show fm.add("Center", b); fm.pack(); fm.show(); }
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()
public static void main(String[] args) { Frame f = new Frame("测试窗口"); // 设置Frame容器使用BorderLayout布局管理器 f.setLayout(new BorderLayout(30, 5)); f.add(new Button("南"), SOUTH); f.add(new Button("北"), NORTH); // 默认添加到中间 f.add(new Button("中")); f.add(new Button("东"), EAST); f.add(new Button("西"), WEST); // 设置窗口为最佳大小 f.pack(); // 将窗口显示出来(Frame对象默认处于隐藏状态) f.setVisible(true); }
public static void main(String[] args) { Frame f = new JFrame("YAY it Works"); f.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent we) { System.exit(0); } }); JApplet applet = new midapp(); ((RootPaneContainer) f).getContentPane().add("Center", applet); f.add(p2, BorderLayout.EAST); applet.init(); f.pack(); f.setSize(new Dimension(653, 437)); f.setVisible(true); }
public void init() { horizontal.add(new Button("水平按钮一")); horizontal.add(Box.createHorizontalGlue()); horizontal.add(new Button("水平按钮二")); // 水平方向不可拉伸的间距,其宽度为10px horizontal.add(Box.createHorizontalStrut(10)); horizontal.add(new Button("水平按钮三")); vertical.add(new Button("垂直按钮一")); vertical.add(Box.createVerticalGlue()); vertical.add(new Button("垂直按钮二")); // 垂直方向不可拉伸的间距,其高度为10px vertical.add(Box.createVerticalStrut(10)); vertical.add(new Button("垂直按钮三")); f.add(horizontal, BorderLayout.NORTH); f.add(vertical); f.pack(); f.setVisible(true); }
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); // 设置窗体可见 }
/** * Sets the Control for this model and initializes the control's values. * * @param control */ public void setControl(Control control) { if (control instanceof SimControl) { this.control = (SimulationControl) control; } else { this.control = new ShadowControl(control); } super.control = control; mainFrame = null; if (control != null) { if (control instanceof MainFrame) { mainFrame = ((MainFrame) control).getMainFrame(); } control.setLockValues(true); resetAnimation(); control.setLockValues(false); if (control instanceof Frame) { ((Frame) control).pack(); } } }
public void init() { b1.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { d1.setVisible(true); System.out.println(d1.getDirectory() + d1.getFile()); } }); b2.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { d2.setVisible(true); System.out.println(d2.getDirectory() + d2.getFile()); } }); frame.add(b1); frame.add(b2, BorderLayout.SOUTH); frame.pack(); frame.setVisible(true); }
public void init() { Panel p = new Panel(); p.add(btCopy); p.add(btPaste); btCopy.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { // 将一个多行文本域里的字符串封装成StringSelection对象 StringSelection contents = new StringSelection(jtaCopyTo.getText()); // 将StringSelection对象放入剪贴板 clipboard.setContents(contents, null); } }); btPaste.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { // 如果剪贴板中包含stringFlavor内容 if (clipboard.isDataFlavorAvailable(DataFlavor.stringFlavor)) { try { // 取出剪贴板中stringFlavor内容 String content = (String) clipboard.getData(DataFlavor.stringFlavor); jtaPaste.append(content); } catch (Exception e) { e.printStackTrace(); } } } }); // 创建一个水平排列的Box容器 Box box = new Box(BoxLayout.X_AXIS); // 将两个多行文本域放在Box容器中 box.add(jtaCopyTo); box.add(jtaPaste); // 将按钮所在Panel、Box容器添加到Frame窗口中 f.add(p, BorderLayout.SOUTH); f.add(box, BorderLayout.CENTER); f.pack(); f.setVisible(true); }
public static void main(String args[]) { ColorPanel colorPanel = new ColorPanel(false); DrawPanel drawPanel = new DrawPanel(colorPanel); Frame f = new Frame("Paint"); f.addWindowListener( new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { System.exit(0); } }); Panel panel = new Panel(); panel.setLayout(new BorderLayout()); panel.add(colorPanel, BorderLayout.WEST); panel.add(drawPanel, BorderLayout.CENTER); f.add(panel); f.pack(); f.setVisible(true); }
/* Constructor : generate the Frame. */ public Interface() { frame = new Frame(); // Validate frames that have preset sizes // Pack frames that have useful preferred size info, e.g. from their layout if (packFrame) { frame.pack(); } else { frame.validate(); } // Center the window Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension frameSize = frame.getSize(); if (frameSize.height > screenSize.height) { frameSize.height = screenSize.height; } if (frameSize.width > screenSize.width) { frameSize.width = screenSize.width; } frame.setLocation( (screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2); frame.setVisible(true); };
/** * 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
/** * Method declaration * * @param ev */ public void actionPerformed(ActionEvent ev) { String s = ev.getActionCommand(); if (s == null) { if (ev.getSource() instanceof MenuItem) { MenuItem i; s = ((MenuItem) ev.getSource()).getLabel(); } } if (s.equals("Execute")) { execute(); } else if (s.equals("Exit")) { windowClosing(null); } else if (s.equals("Transfer")) { Transfer.work(null); } else if (s.equals("Dump")) { Transfer.work(new String[] {"-d"}); /* NB - 26052002 Restore is not implemented yet in the transfer tool */ /* } else if (s.equals("Restore")) { Transfer.work(new String[]{"-r"}); */ } else if (s.equals("Logging on")) { jdbcSystem.setLogToSystem(true); } else if (s.equals("Logging off")) { jdbcSystem.setLogToSystem(false); } else if (s.equals("Refresh Tree")) { refreshTree(); } else if (s.startsWith("#")) { int i = Integer.parseInt(s.substring(1)); txtCommand.setText(sRecent[i]); } else if (s.equals("Connect...")) { connect(ConnectionDialog.createConnection(fMain, "Connect")); refreshTree(); } else if (s.equals("Results in Grid")) { iResult = 0; pResult.removeAll(); pResult.add("Center", gResult); pResult.doLayout(); } else if (s.equals("Open Script...")) { FileDialog f = new FileDialog(fMain, "Open Script", FileDialog.LOAD); // (ulrivo): set default directory if set from command line if (defDirectory != null) { f.setDirectory(defDirectory); } f.show(); String file = f.getFile(); if (file != null) { txtCommand.setText(DatabaseManagerCommon.readFile(f.getDirectory() + file)); } } else if (s.equals("Save Script...")) { FileDialog f = new FileDialog(fMain, "Save Script", FileDialog.SAVE); // (ulrivo): set default directory if set from command line if (defDirectory != null) { f.setDirectory(defDirectory); } f.show(); String file = f.getFile(); if (file != null) { DatabaseManagerCommon.writeFile(f.getDirectory() + file, txtCommand.getText()); } } else if (s.equals("Save Result...")) { FileDialog f = new FileDialog(fMain, "Save Result", FileDialog.SAVE); // (ulrivo): set default directory if set from command line if (defDirectory != null) { f.setDirectory(defDirectory); } f.show(); String file = f.getFile(); if (file != null) { showResultInText(); DatabaseManagerCommon.writeFile(f.getDirectory() + file, txtResult.getText()); } } else if (s.equals("Results in Text")) { iResult = 1; pResult.removeAll(); pResult.add("Center", txtResult); pResult.doLayout(); showResultInText(); } else if (s.equals("AutoCommit on")) { try { cConn.setAutoCommit(true); } catch (SQLException e) { } } else if (s.equals("AutoCommit off")) { try { cConn.setAutoCommit(false); } catch (SQLException e) { } } else if (s.equals("Enlarge Tree")) { Dimension d = tTree.getMinimumSize(); d.width += 20; tTree.setMinimumSize(d); fMain.pack(); } else if (s.equals("Shrink Tree")) { Dimension d = tTree.getMinimumSize(); d.width -= 20; if (d.width >= 0) { tTree.setMinimumSize(d); } fMain.pack(); } else if (s.equals("Enlarge Command")) { txtCommand.setRows(txtCommand.getRows() + 1); fMain.pack(); } else if (s.equals("Shrink Command")) { int i = txtCommand.getRows() - 1; txtCommand.setRows(i < 1 ? 1 : i); fMain.pack(); } else if (s.equals("Commit")) { try { cConn.commit(); } catch (SQLException e) { } } else if (s.equals("Insert test data")) { insertTestData(); } else if (s.equals("Rollback")) { try { cConn.rollback(); } catch (SQLException e) { } } else if (s.equals("Disable MaxRows")) { try { sStatement.setMaxRows(0); } catch (SQLException e) { } } else if (s.equals("Set MaxRows to 100")) { try { sStatement.setMaxRows(100); } catch (SQLException e) { } } else if (s.equals("SELECT")) { showHelp(DatabaseManagerCommon.selectHelp); } else if (s.equals("INSERT")) { showHelp(DatabaseManagerCommon.insertHelp); } else if (s.equals("UPDATE")) { showHelp(DatabaseManagerCommon.updateHelp); } else if (s.equals("DELETE")) { showHelp(DatabaseManagerCommon.deleteHelp); } else if (s.equals("CREATE TABLE")) { showHelp(DatabaseManagerCommon.createTableHelp); } else if (s.equals("DROP TABLE")) { showHelp(DatabaseManagerCommon.dropTableHelp); } else if (s.equals("CREATE INDEX")) { showHelp(DatabaseManagerCommon.createIndexHelp); } else if (s.equals("DROP INDEX")) { showHelp(DatabaseManagerCommon.dropIndexHelp); } else if (s.equals("CHECKPOINT")) { showHelp(DatabaseManagerCommon.checkpointHelp); } else if (s.equals("SCRIPT")) { showHelp(DatabaseManagerCommon.scriptHelp); } else if (s.equals("SHUTDOWN")) { showHelp(DatabaseManagerCommon.shutdownHelp); } else if (s.equals("SET")) { showHelp(DatabaseManagerCommon.setHelp); } else if (s.equals("Test Script")) { showHelp(DatabaseManagerCommon.testHelp); } }
public void run(String arg) { GenericDialog gd = new GenericDialog("Options"); double sfreq = 20000.0; gd.addNumericField("Sampling Frequency?", sfreq, 1, 10, null); String[] psfchoice = {"3D Gaussian", "Gaus-Lorentz^2", "2D Gaussian"}; gd.addChoice("PSF Type?", psfchoice, psfchoice[0]); String[] filetypechoice = { "Confocor 3 raw", "Short binary trajectory", "PlotWindow trajectory", "Ascii Text File" }; gd.addChoice("File Type?", filetypechoice, filetypechoice[0]); boolean ch2green = true; gd.addCheckbox("Ch2 is green?", ch2green); gd.showDialog(); if (gd.wasCanceled()) { return; } sfreq = gd.getNextNumber(); int psfflag = gd.getNextChoiceIndex(); int fileflag = gd.getNextChoiceIndex(); ch2green = gd.getNextBoolean(); int nfiles = 0; Object[] histograms = null; int xmax = 0; int ymax = 0; String[] names = null; if (fileflag < 2) { jdataio ioclass = new jdataio(); File[] filearray = ioclass.openfiles(OpenDialog.getDefaultDirectory(), IJ.getInstance()); if (filearray.length == 0) { return; } String dir = filearray[0].getAbsolutePath(); int sepindex = dir.lastIndexOf(File.separator); String newdir = dir.substring(0, sepindex + 1); OpenDialog.setDefaultDirectory(newdir); nfiles = filearray.length / 2; if (nfiles > 25) { nfiles = 25; } histograms = new Object[nfiles]; names = organize_c3_files(filearray); for (int i = 0; i < nfiles; i++) { try { int length1 = (int) (((double) filearray[2 * i].length() - 128.0) / 4.0); int length2 = (int) (((double) filearray[2 * i + 1].length() - 128.0) / 4.0); int length3 = (int) (((double) filearray[2 * i].length()) / 2.0); int length4 = (int) (((double) filearray[2 * i + 1].length()) / 2.0); InputStream instream = new BufferedInputStream(new FileInputStream(filearray[2 * i])); InputStream instream2 = new BufferedInputStream(new FileInputStream(filearray[2 * i + 1])); if (fileflag == 0) { int[] pmdata = new int[length1]; int[] pmdata2 = new int[length2]; if (!ioclass.skipstreambytes(instream, 128)) { showioerror(); instream.close(); return; } if (!ioclass.skipstreambytes(instream2, 128)) { showioerror(); instream2.close(); return; } if (!ioclass.readintelintfile(instream, length1, pmdata)) { showioerror(); instream.close(); return; } if (!ioclass.readintelintfile(instream2, length2, pmdata2)) { showioerror(); instream2.close(); return; } if (ch2green) { histograms[i] = (new pmodeconvert()).pm2pch(pmdata2, pmdata, sfreq, 20000000); } else { histograms[i] = (new pmodeconvert()).pm2pch(pmdata, pmdata2, sfreq, 20000000); } } else { float[] tmdata = new float[length3]; float[] tmdata2 = new float[length4]; if (!ioclass.readintelshortfile(instream, length3, tmdata)) { showioerror(); instream.close(); return; } if (!ioclass.readintelshortfile(instream2, length4, tmdata2)) { showioerror(); instream2.close(); return; } if (ch2green) { histograms[i] = (new pmodeconvert()).create_2Dhistogram(tmdata2, tmdata); } else { histograms[i] = (new pmodeconvert()).create_2Dhistogram(tmdata, tmdata2); } } if (((float[][]) histograms[i]).length > xmax) { xmax = ((float[][]) histograms[i]).length; } if (((float[][]) histograms[i])[0].length > ymax) { ymax = ((float[][]) histograms[i])[0].length; } instream.close(); instream2.close(); } catch (IOException e) { showioerror(); return; } } } else { if (fileflag == 2) { ImageWindow iw = WindowManager.getCurrentWindow(); float[][] trajectories = (float[][]) jutils.runPW4VoidMethod(iw, "getYValues"); float[][] tempxvals = (float[][]) jutils.runPW4VoidMethod(iw, "getXValues"); sfreq = 1.0 / ((double) tempxvals[0][1]); nfiles = trajectories.length / 2; if (nfiles > 25) { nfiles = 25; } names = new String[nfiles + 1]; names[nfiles] = "avg"; histograms = new Object[nfiles]; for (int i = 0; i < nfiles; i++) { names[i] = "trajectory " + (i + 1); if (ch2green) { histograms[i] = (new pmodeconvert()) .create_2Dhistogram(trajectories[2 * i + 1], trajectories[2 * i]); } else { histograms[i] = (new pmodeconvert()) .create_2Dhistogram(trajectories[2 * i], trajectories[2 * i + 1]); } if (((float[][]) histograms[i]).length > xmax) { xmax = ((float[][]) histograms[i]).length; } if (((float[][]) histograms[i])[0].length > ymax) { ymax = ((float[][]) histograms[i])[0].length; } } } else { // here we read tab delimited lines from files jdataio ioclass = new jdataio(); File[] filearray = ioclass.openfiles(OpenDialog.getDefaultDirectory(), IJ.getInstance()); if (filearray.length == 0) { return; } String dir = filearray[0].getAbsolutePath(); int sepindex = dir.lastIndexOf(File.separator); String newdir = dir.substring(0, sepindex + 1); OpenDialog.setDefaultDirectory(newdir); nfiles = filearray.length; if (nfiles > 25) { nfiles = 25; } histograms = new Object[nfiles]; names = new String[nfiles + 1]; names[nfiles] = "avg"; for (int i = 0; i < nfiles; i++) { try { names[i] = filearray[i].getName(); BufferedReader d = new BufferedReader(new FileReader(filearray[i])); String[] lines = new String[256]; int counter = 0; do { lines[counter] = d.readLine(); counter++; } while ((lines[counter - 1] != null && lines[counter - 1] != "") && counter < 256); int numcolumns = 0; for (int j = 0; j < counter - 1; j++) { int temp = getncolumns(lines[j]); if (temp > numcolumns) { numcolumns = temp; } } float[][] temphist2 = null; if (ch2green) { temphist2 = new float[numcolumns][counter - 1]; } else { temphist2 = new float[counter - 1][numcolumns]; } for (int k = 0; k < counter - 1; k++) { float[] temp = tab_delim2float(lines[k]); for (int j = 0; j < numcolumns; j++) { if (ch2green) { temphist2[j][k] = temp[j]; } else { temphist2[k][j] = temp[j]; } } } histograms[i] = temphist2; d.close(); } catch (IOException e) { showioerror(); return; } } for (int i = 0; i < nfiles; i++) { if (((float[][]) histograms[i]).length > xmax) { xmax = ((float[][]) histograms[i]).length; } if (((float[][]) histograms[i])[0].length > ymax) { ymax = ((float[][]) histograms[i])[0].length; } } } } // note that here x is green and y is red float[][][] pch = new float[nfiles][xmax][ymax]; for (int i = 0; i < nfiles; i++) { for (int j = 0; j < ((float[][]) histograms[i]).length; j++) { for (int k = 0; k < ((float[][]) histograms[i])[j].length; k++) { pch[i][j][k] = ((float[][]) histograms[i])[j][k]; } } } final PCH2DFitWindow cw = new PCH2DFitWindow(); cw.init(names, pch, psfflag); final Frame f = new Frame("PCH 2D Analysis"); f.setLocation(10, 10); f.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { f.dispose(); } }); f.add(cw); f.pack(); f.setResizable(false); Insets ins = f.getInsets(); cw.totalSize.height = PCH2DFitWindow.H + ins.bottom + ins.top + 65; cw.totalSize.width = PCH2DFitWindow.WR + ins.left + ins.right; f.setSize(cw.totalSize); f.setVisible(true); cw.requestFocus(); }
public static void main(String[] args) { cg1Canvas T = new cg1Canvas(300, 300); T.setColor(1.0f, 1.0f, 1.0f); T.clear(); float quad1x[] = new float[4]; float quad1y[] = new float[4]; quad1x[0] = 20; quad1x[1] = 20; quad1x[2] = 40; quad1x[3] = 40; quad1y[0] = 20; quad1y[1] = 40; quad1y[2] = 40; quad1y[3] = 20; float quad2x[] = new float[4]; float quad2y[] = new float[4]; quad2x[0] = 80; quad2x[1] = 80; quad2x[2] = 60; quad2x[3] = 60; quad2y[0] = 60; quad2y[1] = 100; quad2y[2] = 100; quad2y[3] = 60; float quad3x[] = new float[4]; float quad3y[] = new float[4]; quad3x[0] = 20; quad3x[1] = 50; quad3x[2] = 50; quad3x[3] = 20; quad3y[0] = 60; quad3y[1] = 60; quad3y[2] = 50; quad3y[3] = 50; float quad4x[] = new float[4]; float quad4y[] = new float[4]; quad4x[0] = 44; quad4x[1] = 60; quad4x[2] = 60; quad4x[3] = 44; quad4y[0] = 22; quad4y[1] = 22; quad4y[2] = 46; quad4y[3] = 46; float pent1x[] = new float[5]; float pent1y[] = new float[5]; pent1x[0] = 80; pent1x[1] = 90; pent1x[2] = 110; pent1x[3] = 100; pent1x[4] = 80; pent1y[0] = 20; pent1y[1] = 10; pent1y[2] = 20; pent1y[3] = 50; pent1y[4] = 40; float hept1x[] = new float[7]; float hept1y[] = new float[7]; hept1x[0] = 120; hept1x[1] = 140; hept1x[2] = 160; hept1x[3] = 160; hept1x[4] = 140; hept1x[5] = 120; hept1x[6] = 110; hept1y[0] = 70; hept1y[1] = 70; hept1y[2] = 80; hept1y[3] = 100; hept1y[4] = 110; hept1y[5] = 100; hept1y[6] = 90; float wx[] = new float[50]; float wy[] = new float[50]; int wl; /* * first polygon: entirely within region */ wl = 0; wl = T.clipPolygon(4, quad1x, quad1y, wx, wy, 10, 10, 50, 50); T.setColor(1.0f, 0.0f, 0.0f); /* red */ T.printLoop(4, quad1x, quad1y); T.printPoly(wl, wx, wy); /* * second polygon: entirely outside region */ wl = 0; wl = T.clipPolygon(4, quad2x, quad2y, wx, wy, 10, 10, 50, 50); /* shouldn't draw anything! */ if (wl > 0) { T.setColor(0.0f, 1.0f, 0.0f); /* green */ T.printLoop(4, quad2x, quad2y); T.printPoly(wl, wx, wy); } // /* * third polygon: halfway outside on left */ wl = 0; wl = T.clipPolygon(4, quad3x, quad3y, wx, wy, 30, 10, 70, 80); T.setColor(0.0f, 0.0f, 1.0f); /* blue */ T.printLoop(4, quad3x, quad3y); T.printPoly(wl, wx, wy); /* * fourth polygon: part outside on right */ wl = 0; wl = T.clipPolygon(4, quad4x, quad4y, wx, wy, 10, 10, 50, 50); T.setColor(1.0f, 0.0f, 1.0f); /* magenta */ T.printLoop(4, quad4x, quad4y); T.printPoly(wl, wx, wy); /* * fifth polygon: enclosing */ wl = 0; wl = T.clipPolygon(5, pent1x, pent1y, wx, wy, 90, 20, 100, 30); T.setColor(0.5f, 0.5f, 1.0f); /* reddish-greenish-blue ? */ T.printLoop(5, pent1x, pent1y); T.printPoly(wl, wx, wy); /* * sixth polygon: outside on left and bottom */ wl = 0; wl = T.clipPolygon(5, pent1x, pent1y, wx, wy, 90, 34, 120, 60); T.setColor(1.0f, 0.5f, 1.0f); /* red-greenish-blue ? */ T.printLoop(5, pent1x, pent1y); T.printPoly(wl, wx, wy); /* * seventh polygon: outside on top, right, and bottom */ wl = 0; wl = T.clipPolygon(7, hept1x, hept1y, wx, wy, 90, 80, 130, 110); T.setColor(0.0f, 0.0f, 0.0f); /* black */ T.printLoop(7, hept1x, hept1y); T.printPoly(wl, wx, wy); Frame f = new Frame("clip Test"); f.add("Center", T); f.pack(); f.setResizable(false); f.setVisible(true); }
public static void main(String[] args) { Frame f = new AllComponents("AWT Demo"); f.pack(); f.show(); }