public void itemStateChanged(ItemEvent evt) { if (evt.getSource() == farbe) { status.setText("Farbe " + farben[farbe.getSelectedIndex()] + " ausgewaehlt"); switch (farbe.getSelectedIndex()) { case 0: color = Color.blue; break; case 1: color = Color.yellow; break; case 2: color = Color.green; break; case 3: color = Color.red; break; case 4: color = Color.black; break; case 5: color = Color.white; } } else if (evt.getSource() == filled) { if (filled.getState() == true) status.setText("Ausgefuellt zeichnen"); else status.setText("Rahmen zeichnen"); } }
/** * Adds a popup menu. * * @param label the label * @param items the menu items * @param defaultItem the menu item initially selected */ public void addChoice(String label, String[] items, String defaultItem) { String label2 = label; if (label2.indexOf('_') != -1) label2 = label2.replace('_', ' '); Label theLabel = makeLabel(label2); c.gridx = 0; c.gridy = y; c.anchor = GridBagConstraints.EAST; c.gridwidth = 1; if (choice == null) { choice = new Vector(4); c.insets = getInsets(5, 0, 5, 0); } else c.insets = getInsets(0, 0, 5, 0); grid.setConstraints(theLabel, c); add(theLabel); Choice thisChoice = new Choice(); thisChoice.addKeyListener(this); thisChoice.addItemListener(this); for (int i = 0; i < items.length; i++) thisChoice.addItem(items[i]); thisChoice.select(defaultItem); c.gridx = 1; c.gridy = y; c.anchor = GridBagConstraints.WEST; grid.setConstraints(thisChoice, c); add(thisChoice); choice.addElement(thisChoice); if (Recorder.record || macro) saveLabel(thisChoice, label); y++; }
GChoicePeer(GToolkit toolkit, Choice target) { super(toolkit, target); int itemCount = target.getItemCount(); for (int i = 0; i < itemCount; i++) add(target.getItem(i), i); int selectedIndex = target.getSelectedIndex(); if (selectedIndex >= 0 && itemCount > 0) select(selectedIndex); }
public Channels() { super("Channels"); if (instance != null) { instance.toFront(); return; } WindowManager.addWindow(this); instance = this; GridBagLayout gridbag = new GridBagLayout(); GridBagConstraints c = new GridBagConstraints(); setLayout(gridbag); int y = 0; c.gridx = 0; c.gridy = y++; c.gridwidth = 1; c.fill = GridBagConstraints.BOTH; c.anchor = GridBagConstraints.CENTER; int margin = 32; if (IJ.isMacOSX()) margin = 20; c.insets = new Insets(10, margin, 10, margin); choice = new Choice(); for (int i = 0; i < modes.length; i++) choice.addItem(modes[i]); choice.select(0); choice.addItemListener(this); add(choice, c); CompositeImage ci = getImage(); int nCheckBoxes = ci != null ? ci.getNChannels() : 3; if (nCheckBoxes > CompositeImage.MAX_CHANNELS) nCheckBoxes = CompositeImage.MAX_CHANNELS; checkbox = new Checkbox[nCheckBoxes]; for (int i = 0; i < nCheckBoxes; i++) { checkbox[i] = new Checkbox("Channel " + (i + 1), true); c.insets = new Insets(0, 25, i < nCheckBoxes - 1 ? 0 : 10, 5); c.gridy = y++; add(checkbox[i], c); checkbox[i].addItemListener(this); } c.insets = new Insets(0, 15, 10, 15); c.fill = GridBagConstraints.NONE; c.gridy = y++; moreButton = new Button(moreLabel); moreButton.addActionListener(this); add(moreButton, c); update(); pm = new PopupMenu(); for (int i = 0; i < menuItems.length; i++) addPopupItem(menuItems[i]); add(pm); addKeyListener(IJ.getInstance()); // ImageJ handles keyboard shortcuts setResizable(false); pack(); if (location == null) { GUI.center(this); location = getLocation(); } else setLocation(location); show(); }
public void itemStateChanged(ItemEvent e) { System.out.println("itemStateChanged"); if (e.getSource() == ColChoice) // 预选颜色 { String name = ColChoice.getSelectedItem(); if (name == "black") { c = new Color(0, 0, 0); } else if (name == "red") { c = new Color(255, 0, 0); } else if (name == "green") { c = new Color(0, 255, 0); } else if (name == "blue") { c = new Color(0, 0, 255); } } else if (e.getSource() == SizeChoice) // 画笔大小 { String selected = SizeChoice.getSelectedItem(); if (selected == "1") { con = 1; size = new BasicStroke(con, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL); } else if (selected == "3") { con = 3; size = new BasicStroke(con, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL); } else if (selected == "5") { con = 5; size = new BasicStroke(con, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL); } else if (selected == "7") { con = 7; size = new BasicStroke(con, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL); } else if (selected == "9") { con = 9; size = new BasicStroke(con, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL); } } else if (e.getSource() == EraserChoice) // 橡皮大小 { String Esize = EraserChoice.getSelectedItem(); if (Esize == "5") { Econ = 5 * 2; } else if (Esize == "9") { Econ = 9 * 2; } else if (Esize == "13") { Econ = 13 * 2; } else if (Esize == "17") { Econ = 17 * 3; } } }
/** Returns the selected item in the next popup menu. */ public String getNextChoice() { if (choice == null) return ""; Choice thisChoice = (Choice) (choice.elementAt(choiceIndex)); String item = thisChoice.getSelectedItem(); if (macro) { String label = (String) labels.get((Object) thisChoice); item = Macro.getValue(macroOptions, label, item); if (item != null && item.startsWith("&")) // value is macro variable item = getChoiceVariable(item); } if (recorderOn) recordOption(thisChoice, item); choiceIndex++; return item; }
/** Returns the index of the selected item in the next popup menu. */ public int getNextChoiceIndex() { if (choice == null) return -1; Choice thisChoice = (Choice) (choice.elementAt(choiceIndex)); int index = thisChoice.getSelectedIndex(); if (macro) { String label = (String) labels.get((Object) thisChoice); String oldItem = thisChoice.getSelectedItem(); int oldIndex = thisChoice.getSelectedIndex(); String item = Macro.getValue(macroOptions, label, oldItem); if (item != null && item.startsWith("&")) // value is macro variable item = getChoiceVariable(item); thisChoice.select(item); index = thisChoice.getSelectedIndex(); if (index == oldIndex && !item.equals(oldItem)) { // is value a macro variable? Interpreter interp = Interpreter.getInstance(); String s = interp != null ? interp.getStringVariable(item) : null; if (s == null) IJ.error(getTitle(), "\"" + item + "\" is not a valid choice for \"" + label + "\""); else item = s; } } if (recorderOn) { int defaultIndex = ((Integer) (defaultChoiceIndexes.elementAt(choiceIndex))).intValue(); if (!(smartRecording && index == defaultIndex)) { String item = thisChoice.getSelectedItem(); if (!(item.equals("*None*") && getTitle().equals("Merge Channels"))) recordOption(thisChoice, thisChoice.getSelectedItem()); } } choiceIndex++; return index; }
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); } }); }
public void update() { CompositeImage ci = getImage(); if (ci == null || checkbox == null) return; int n = checkbox.length; int nChannels = ci.getNChannels(); if (nChannels != n && nChannels <= CompositeImage.MAX_CHANNELS) { instance = null; location = getLocation(); close(); new Channels(); return; } boolean[] active = ci.getActiveChannels(); for (int i = 0; i < checkbox.length; i++) checkbox[i].setState(active[i]); int index = 0; switch (ci.getMode()) { case IJ.COMPOSITE: index = 0; break; case IJ.COLOR: index = 1; break; case IJ.GRAYSCALE: index = 2; break; } choice.select(index); }
{ clientStatus.add("Online"); clientStatus.add("Offline"); clientStatus.add("Busy"); clientStatus.select("Offline"); clientStatus.addItemListener( new ItemListener() { public void itemStateChanged(ItemEvent e) { new Thread("icqtest/chooser control handler") { public void run() { try { if (clientStatus.getSelectedItem().equals("Online")) { if (plugin.getClientStatus(getMyLoginId()) == org.jcq2k.MessagingNetwork.STATUS_OFFLINE) login(); plugin.setClientStatus( getMyLoginId(), org.jcq2k.MessagingNetwork.STATUS_ONLINE); } else if (clientStatus.getSelectedItem().equals("Busy")) { if (plugin.getClientStatus(getMyLoginId()) == org.jcq2k.MessagingNetwork.STATUS_OFFLINE) login(); plugin.setClientStatus(getMyLoginId(), org.jcq2k.MessagingNetwork.STATUS_BUSY); } else if (clientStatus.getSelectedItem().equals("Offline")) { if (plugin.getClientStatus(getMyLoginId()) != org.jcq2k.MessagingNetwork.STATUS_OFFLINE) plugin.setClientStatus( getMyLoginId(), org.jcq2k.MessagingNetwork.STATUS_OFFLINE); } else { org.jcq2k.util.joe.Lang.ASSERT_FALSE("invalid clientStatus.getSelectedItem()"); } } catch (Throwable tr) { printException(tr); } } }.start(); } }); }
public void init() { status = new Label("", Label.CENTER); menu = new Panel(); canvas = new MyCanvas(); farbe = new Choice(); color = Color.blue; filled = new Checkbox("ausgefuellt"); namen = new String[] {"Rechteck", "Kreis", "Ellipse"}; farben = new String[] {"blau", "gelb", "gruen", "rot", "schwarz", "weiss"}; button = new Button[namen.length]; type = -1; for (int i = 0; i < namen.length; i++) { button[i] = new Button(namen[i]); button[i].addActionListener(this); menu.add(button[i]); } for (int i = 0; i < farben.length; i++) farbe.add(farben[i]); filled.addItemListener(this); farbe.addItemListener(this); canvas.addMouseListener(this); canvas.addMouseMotionListener(this); menu.add(filled); menu.add(farbe); setLayout(new BorderLayout()); setBackground(Color.lightGray); add(menu, "North"); add(canvas, "Center"); add(status, "South"); }
Panel5(web main) { setLayout(new GridLayout(3, 3)); lpm = new Checkbox("LPM"); add(lpm); cont = new Checkbox("CONT"); add(cont); cuts = new Choice(); cuts.add("Vcut 1"); cuts.add("0.05"); cuts.add("0.01"); cuts.add("1.e-3"); cuts.add("E 500"); add(cuts); scat = new Checkbox("SCAT"); add(scat); time = new Checkbox("TIME"); add(time); brem = new Choice(); brem.add("BS: KKP"); brem.add("BS: ABB"); brem.add("BS: P-S"); brem.add("BS: CSC"); add(brem); debug = new Checkbox("info", true); add(debug); inter = new Checkbox("intr"); add(inter); phnu = new Choice(); phnu.add("BB 1981"); phnu.add("BB ZEUS"); phnu.add("BB+HARD"); phnu.add("ALLM 91"); phnu.add("ALLM 97"); phnu.add("BM CKMT"); add(phnu); }
public void itemStateChanged(ItemEvent e) { beta = Double.parseDouble(betaval.getText()); updatebeta(); boolean avgchanged = false; for (int i = 0; i < ncurves; i++) { if (checkarray[i].getState() != include[i]) { avgchanged = true; if (include[i]) { include[i] = false; } else { include[i] = true; } } } if (avgchanged) { updateavg(); updatebeta(); int1array[ncurves].setText("" + (float) intensity1[ncurves]); e1array[ncurves].setText("" + (float) bright1[ncurves]); n1array[ncurves].setText("" + (float) number1[ncurves]); int2array[ncurves].setText("" + (float) intensity2[ncurves]); e2array[ncurves].setText("" + (float) bright2[ncurves]); n2array[ncurves].setText("" + (float) number2[ncurves]); eccarray[ncurves].setText("" + (float) brightcc[ncurves]); pwavg.updateSeries(avg, 0, true); float[] temp = pwavg.getLimits(); temp[4] = 1.0f; pwavg.setLimits(temp); } if (e.getSource() == dispcurvechoice) { dispcurve = dispcurvechoice.getSelectedIndex(); pwfit.updateSeries(pch[dispcurve], 0, true); pwfit.updateSeries(fit[dispcurve], 1, true); float[] temp = pwfit.getLimits(); temp[4] = 1.0f; pwfit.setLimits(temp); } }
paintboard1(String s) { super(s); addMouseMotionListener(this); addMouseListener(this); paintInfo = new Vector(); /* 各工具按钮及选择项 */ // 颜色选择 ColChoice = new Choice(); ColChoice.add("black"); ColChoice.add("red"); ColChoice.add("blue"); ColChoice.add("green"); ColChoice.addItemListener(this); // 画笔大小选择 SizeChoice = new Choice(); SizeChoice.add("1"); SizeChoice.add("3"); SizeChoice.add("5"); SizeChoice.add("7"); SizeChoice.add("9"); SizeChoice.addItemListener(this); // 橡皮大小选择 EraserChoice = new Choice(); EraserChoice.add("5"); EraserChoice.add("9"); EraserChoice.add("13"); EraserChoice.add("17"); EraserChoice.addItemListener(this); // ////////////////////////////////////////////////// toolPanel = new Panel(); clear = new Button("清除"); eraser = new Button("橡皮"); pen = new Button("画笔"); drLine = new Button("画直线"); drCircle = new Button("画圆形"); drRect = new Button("画矩形"); openPic = new Button("打开图画"); savePic = new Button("保存图画"); colchooser = new Button("显示调色板"); // 各组件事件监听 clear.addActionListener(this); eraser.addActionListener(this); pen.addActionListener(this); drLine.addActionListener(this); drCircle.addActionListener(this); drRect.addActionListener(this); openPic.addActionListener(this); savePic.addActionListener(this); colchooser.addActionListener(this); 颜色 = new Label("画笔颜色", Label.CENTER); 大小B = new Label("画笔大小", Label.CENTER); 大小E = new Label("橡皮大小", Label.CENTER); // 面板添加组件 toolPanel.add(openPic); toolPanel.add(savePic); toolPanel.add(pen); toolPanel.add(drLine); toolPanel.add(drCircle); toolPanel.add(drRect); toolPanel.add(颜色); toolPanel.add(ColChoice); toolPanel.add(大小B); toolPanel.add(SizeChoice); toolPanel.add(colchooser); toolPanel.add(eraser); toolPanel.add(大小E); toolPanel.add(EraserChoice); toolPanel.add(clear); // 工具面板到APPLET面板 add(toolPanel, BorderLayout.NORTH); setBounds(230, 50, 900, 650); setVisible(true); validate(); // dialog for save and load openPicture = new FileDialog(this, "打开图画", FileDialog.LOAD); openPicture.setVisible(false); savePicture = new FileDialog(this, "保存图画", FileDialog.SAVE); savePicture.setVisible(false); openPicture.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { openPicture.setVisible(false); } }); savePicture.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { savePicture.setVisible(false); } }); addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); }
public void actionPerformed(ActionEvent ae) { String s1 = ae.getActionCommand(); if (s1.equals("Calendar")) { // DatePicker dp=new DatePicker(f); // dp.displayDate(); // f.getContentPane().add(p); b3.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent ae) { t6.setText(new DatePicker(f).setPickedDate()); } }); } else if (s1.equals("LogOut")) { f.dispose(); start p = new start(); p.method(); } else if (s1.equals("Search")) { try { String data = t1.getSelectedItem(); Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con = DriverManager.getConnection("jdbc:odbc:raman1"); Statement stm = con.createStatement(); ResultSet rs = stm.executeQuery("select * from mprofile where Manager_Id='" + data + "' "); while (rs.next()) { String a2 = rs.getString(1); t2.setText(a2); String a3 = rs.getString(2); t3.setText(a3); String a4 = rs.getString(3); t4.setText(a4); String a5 = rs.getString(4); t5.setText(a5); String a6 = rs.getString(6); t6.setText(a6); String a7 = rs.getString(7); t7.setText(a7); String a8 = rs.getString(8); t8.setText(a8); String a9 = rs.getString(9); t9.setText(a9); String a10 = rs.getString(10); t10.setText(a10); p.add(l3); p.add(t2); p.add(l4); p.add(t3); p.add(l5); p.add(t4); p.add(l6); p.add(t5); p.add(l7); p.add(c1); p.add(c2); p.add(l8); p.add(t6); p.add(l9); p.add(t7); p.add(l10); p.add(t8); p.add(l11); p.add(t9); p.add(l12); p.add(t10); p.add(b2); p.add(b3); p.add(b4); } } catch (Exception e) { } } else if (s1.equals("Update")) { String y2 = t2.getText(); String y3 = t3.getText(); String update_id = t4.getText(); String y4 = t5.getText(); String y6 = t6.getText(); String y7 = t7.getText(); String y8 = t8.getText(); String y9 = t9.getText(); String y10 = t10.getText(); try { String y = t1.getSelectedItem(); Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con = DriverManager.getConnection("jdbc:odbc:raman1"); PreparedStatement ps = con.prepareStatement( "update mprofile set Location=? , E_Mail_Id=? ,Contact_No =?, Address=?, D_O_B=?,Gender=?, Password=?, Manager_Id=?,manager_father=?,manager_name=? where Manager_Id='" + y + "' "); ps.setString(1, y10); ps.setString(2, y9); ps.setString(3, y8); ps.setString(4, y7); ps.setString(5, y6); ps.setString(6, g); ps.setString(7, y4); ps.setString(8, update_id); ps.setString(9, y3); ps.setString(10, y2); ps.executeUpdate(); JOptionPane.showMessageDialog(p, "data has been updated"); f.dispose(); project p = new project(); p.method(); } catch (Exception e) { System.out.println(e); } } else if (s1.equals("Close")) { f.dispose(); } else { f.dispose(); project p = new project(); p.method(); } }
mupdate() { f = new JFrame("POS"); p = new Panel(); l1 = new Label("Welcome:Admin"); l2 = new Label("POINT OF SALE"); l14 = new Label("Enter Manager_Id"); l3 = new Label("Name"); l4 = new Label("Father's_Name"); l5 = new Label("Manager_Id"); l6 = new Label("Password"); l7 = new Label("Gender"); l9 = new Label("Address"); l8 = new Label("D.O.B."); l10 = new Label("Contact_No."); l11 = new Label("E-Mail_Id"); l12 = new Label("Location"); l13 = new Label( "_______________________________________________________________________________________________"); l15 = new Label( "_______________________________________________________________________________________________________________________"); cbg = new CheckboxGroup(); c1 = new Checkbox("Male", cbg, false); c2 = new Checkbox("Female", cbg, false); t11 = new TextField(); t2 = new TextField(); t3 = new TextField(); t4 = new TextField(); t5 = new TextField(); t6 = new TextField(); t7 = new TextField(); t8 = new TextField(); t9 = new TextField(); t10 = new TextField(); try { t1 = new Choice(); Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con = DriverManager.getConnection("jdbc:odbc:raman1"); Statement stm = con.createStatement(); ResultSet rs = stm.executeQuery("select * from mprofile"); while (rs.next()) { String a2 = rs.getString(3); t1.add(a2); } } catch (Exception e) { System.out.println(e); } b1 = new Button("Search"); b2 = new Button("Update"); b3 = new Button("Calendar"); b4 = new Button("Close"); b5 = new Button("Back"); b6 = new Button("Logout"); f1 = new Font("sherif", Font.BOLD | Font.ITALIC, 45); f2 = new Font("sherif", Font.BOLD | Font.ITALIC, 30); f3 = new Font("sherif", Font.BOLD | Font.ITALIC, 35); f4 = new Font("sherif", Font.BOLD, 20); f5 = new Font("sherif", Font.BOLD | Font.ITALIC, 15); f6 = new Font("sherif", Font.BOLD | Font.ITALIC, 20); l1.setFont(f5); l2.setFont(f1); l3.setFont(f6); l4.setFont(f6); l5.setFont(f6); l6.setFont(f6); l7.setFont(f6); l8.setFont(f6); l9.setFont(f6); l10.setFont(f6); l11.setFont(f6); l12.setFont(f6); l13.setFont(f6); l14.setFont(f6); b1.setFont(f6); b2.setFont(f6); b3.setFont(f6); b4.setFont(f6); b5.setFont(f6); b6.setFont(f6); }
public boolean queryOptions() { if (!okToInteractWithUser( CAN_PROCEED_ANYWAY, "Querying Options")) // Debugg.println needs to check that options set well enough to // proceed anyway return true; boolean closeWizard = false; if ((MesquiteTrunk.isMacOSXBeforeSnowLeopard()) && MesquiteDialog.currentWizard == null) { CommandRecord cRec = null; cRec = MesquiteThread.getCurrentCommandRecordDefIfNull(null); if (cRec != null) { cRec.requestEstablishWizard(true); closeWizard = true; } } MesquiteInteger buttonPressed = new MesquiteInteger(1); queryOptionsDialog = new ExtensibleDialog( containerOfModule(), "TNT Options & Locations", buttonPressed); // MesquiteTrunk.mesquiteTrunk.containerOfModule() // queryOptionsDialog.addLabel("TNT - Options and Locations"); String helpString = "This module will prepare a matrix for TNT, and ask TNT do to an analysis. A command-line version of TNT must be installed. " + "You can ask it to do a bootstrap analysis or not. " + "Mesquite will read in the trees found by TNT. "; queryOptionsDialog.appendToHelpString(helpString); queryOptionsDialog.setHelpURL(zephyrRunnerEmployer.getProgramURL()); MesquiteTabbedPanel tabbedPanel = queryOptionsDialog.addMesquiteTabbedPanel(); tabbedPanel.addPanel("TNT Program Details", true); externalProcRunner.addItemsToDialogPanel(queryOptionsDialog); Checkbox parallelCheckBox = queryOptionsDialog.addCheckBox("use PVM for parallel processing", parallel); parallelCheckBox.addItemListener(this); IntegerField slavesField = queryOptionsDialog.addIntegerField( "Number of Slaves", numSlaves, 4, 0, MesquiteInteger.infinite); IntegerField maxRamField = queryOptionsDialog.addIntegerField("mxram value", mxram, 4, 0, MesquiteInteger.infinite); tabbedPanel.addPanel("Search Options", true); Choice searchStyleChoice = null; if (bootstrapAllowed) searchStyleChoice = queryOptionsDialog.addPopUpMenu( "Type of search/resampling:", new String[] { "Regular Search", "Bootstrap", "Jackknife", "Symmetric Resampled", "Poisson Bootstrap" }, searchStyle); queryOptionsDialog.addLabel("Regular Search Commands"); searchField = queryOptionsDialog.addTextAreaSmallFont(searchArguments, 7, 80); searchScriptPathField = queryOptionsDialog.addTextField( "Path to TNT run file containing search commands", searchScriptPath, 40); Button browseSearchScriptPathButton = queryOptionsDialog.addAListenedButton("Browse...", null, this); browseSearchScriptPathButton.setActionCommand("browseSearchScript"); harvestOnlyStrictConsensusBox = queryOptionsDialog.addCheckBox("only acquire strict consensus", harvestOnlyStrictConsensus); queryOptionsDialog.addHorizontalLine(1); // Checkbox doBootstrapBox = queryOptionsDialog.addCheckBox("do bootstrapping", doBootstrap); if (bootstrapAllowed) { bootStrapRepsField = queryOptionsDialog.addIntegerField( "Resampling Replicates", bootstrapreps, 8, 0, MesquiteInteger.infinite); queryOptionsDialog.addLabel("Resampling Search Commands"); bootstrapSearchField = queryOptionsDialog.addTextAreaSmallFont(bootstrapSearchArguments, 7, 80); bootSearchScriptPathField = queryOptionsDialog.addTextField( "Path to TNT run file containing search commands for resampled", bootSearchScriptPath, 30); Button browseBootSearchScriptPathButton = queryOptionsDialog.addAListenedButton("Browse...", null, this); browseSearchScriptPathButton.setActionCommand("browseBootSearchScript"); resamplingAllConsensusTreesBox = queryOptionsDialog.addCheckBox( "allow TNT to calculate consensus tree", !resamplingAllConsensusTrees); } adjustDialogText(); queryOptionsDialog.addHorizontalLine(1); queryOptionsDialog.addNewDialogPanel(); useDefaultsButton = queryOptionsDialog.addAListenedButton("Set to Defaults", null, this); useDefaultsButton.setActionCommand("setToDefaults"); tabbedPanel.addPanel("Other Options", true); convertGapsBox = queryOptionsDialog.addCheckBox( "convert gaps to missing (to avoid gap=extra state)", convertGapsToMissing); queryOptionsDialog.addHorizontalLine(1); queryOptionsDialog.addLabel("Post-Search TNT Commands"); otherOptionsField = queryOptionsDialog.addTextAreaSmallFont(otherOptions, 7, 80); queryOptionsDialog.addHorizontalLine(1); queryOptionsDialog.addNewDialogPanel(); useDefaultsOtherOptionsButton = queryOptionsDialog.addAListenedButton("Set to Defaults", null, this); useDefaultsOtherOptionsButton.setActionCommand("setToDefaultsOtherOptions"); tabbedPanel.cleanup(); queryOptionsDialog.nullifyAddPanel(); queryOptionsDialog.completeAndShowDialog("Search", "Cancel", null, null); if (buttonPressed.getValue() == 0) { boolean infererOK = (treeInferer == null || treeInferer.optionsChosen()); if (externalProcRunner.optionsChosen() && infererOK) { if (bootstrapAllowed) { bootstrapreps = bootStrapRepsField.getValue(); bootstrapSearchArguments = bootstrapSearchField.getText(); bootSearchScriptPath = bootSearchScriptPathField.getText(); harvestOnlyStrictConsensus = harvestOnlyStrictConsensusBox.getState(); resamplingAllConsensusTrees = !resamplingAllConsensusTreesBox.getState(); searchStyle = searchStyleChoice.getSelectedIndex(); } numSlaves = slavesField.getValue(); otherOptions = otherOptionsField.getText(); convertGapsToMissing = convertGapsBox.getState(); parallel = parallelCheckBox.getState(); // doBootstrap = doBootstrapBox.getState(); searchArguments = searchField.getText(); searchScriptPath = searchScriptPathField.getText(); mxram = maxRamField.getValue(); storeRunnerPreferences(); } } queryOptionsDialog.dispose(); if (closeWizard) MesquiteDialog.closeWizard(); return (buttonPressed.getValue() == 0); }
Panel3(web main) { main.panel4 = new Panel4(main); add(main.panel4); main.panel5 = new Panel5(main); add(main.panel5); medi = new Choice(); medi.add("water"); medi.add("ice"); medi.add("salt"); medi.add("standard rock"); medi.add("frejus rock"); medi.add("iron"); medi.add("hydrogen"); medi.add("lead"); medi.add("uranium"); medi.add("air"); medi.add("mineral oil"); medi.add("antares water"); medi.select(1); add(medi); type = new Choice(); type.add("mu"); type.add("tau"); type.add("e"); type.add("mpl"); type.add("all"); add(type); romb = new Choice(); romb.add("3"); romb.add("4"); romb.add("5"); romb.select(2); add(romb); Romb = new Label("romb", Label.CENTER); add(Romb); }
private void postItemEvent(int index) { Choice c = (Choice) target; GToolkit.postEvent( new ItemEvent(c, ItemEvent.ITEM_STATE_CHANGED, c.getItem(index), ItemEvent.SELECTED)); }
/** Création de l'intérieur de la fenêtre */ private void initConteneur() { // le fond fond = getToolkit().getImage("./images/preference/bomber_fond.gif"); tracker = new MediaTracker(this); tracker.addImage(fond, 0); try { tracker.waitForID(0); } catch (Exception a) { System.out.println("Erreur lors chargement de l'image: initConteneur() Preference"); a.printStackTrace(); } // le layout manager GridBagLayout layout = new GridBagLayout(); setLayout(layout); GridBagConstraints c = new GridBagConstraints(); c.weightx = 10; c.weighty = 10; c.ipadx = 10; c.ipady = 10; c.fill = GridBagConstraints.BOTH; // label "Joueurs:" Label lbl_joueurs = new Label("Joueurs:"); lbl_joueurs.setAlignment(Label.CENTER); lbl_joueurs.setFont(new Font("SansSerif", Font.BOLD, 16)); lbl_joueurs.setBackground(Color.black); lbl_joueurs.setForeground(Color.red); c.gridx = 0; c.gridy = 0; c.gridwidth = 6; c.gridheight = 1; c.insets = new Insets(20, 10, 10, 10); c.anchor = GridBagConstraints.SOUTH; layout.setConstraints(lbl_joueurs, c); add(lbl_joueurs); // choix de couleur du joueur ayant l'identifiant 0 choix_couleur0 = new Choice(); choix_couleur0.addItem("rouge"); choix_couleur0.addItem("bleu"); choix_couleur0.addItemListener(this); choix_couleur0.setBackground(Color.red); choix_couleur0.setForeground(Color.black); c.gridx = 0; c.gridy = 1; c.gridwidth = 2; c.gridheight = 1; c.insets = new Insets(10, 10, 5, 20); c.anchor = GridBagConstraints.EAST; layout.setConstraints(choix_couleur0, c); add(choix_couleur0); // nom du joueur ayant l'identifiant 0 txt_joueur0 = new TextField(noms[0]); c.gridx = 2; c.gridy = 1; c.gridwidth = 4; c.gridheight = 1; c.insets = new Insets(10, 10, 5, 20); c.anchor = GridBagConstraints.WEST; layout.setConstraints(txt_joueur0, c); add(txt_joueur0); // choix de couleur du joueur ayant l'identifiant 1 choix_couleur1 = new Choice(); choix_couleur1.addItem("bleu"); choix_couleur1.addItem("rouge"); choix_couleur1.addItemListener(this); choix_couleur1.setBackground(Color.blue); choix_couleur1.setForeground(Color.black); c.gridx = 0; c.gridy = 2; c.gridwidth = 2; c.gridheight = 1; c.insets = new Insets(10, 10, 20, 20); c.anchor = GridBagConstraints.EAST; layout.setConstraints(choix_couleur1, c); add(choix_couleur1); // nom du joueur ayant l'identifiant 1 txt_joueur1 = new TextField(noms[1]); c.gridx = 2; c.gridy = 2; c.gridwidth = 4; c.gridheight = 1; c.insets = new Insets(10, 10, 30, 20); c.anchor = GridBagConstraints.WEST; layout.setConstraints(txt_joueur1, c); add(txt_joueur1); // label "Nombre De Vies:" Label lbl_nbvies = new Label("Nombre De Vies:"); lbl_nbvies.setAlignment(Label.CENTER); lbl_nbvies.setFont(new Font("SansSerif", Font.BOLD, 14)); lbl_nbvies.setBackground(Color.black); lbl_nbvies.setForeground(Color.yellow); c.gridx = 0; c.gridy = 4; c.gridwidth = 1; c.gridheight = 1; c.insets = new Insets(20, 10, 5, 10); c.anchor = GridBagConstraints.CENTER; layout.setConstraints(lbl_nbvies, c); add(lbl_nbvies); // un choix possible cbg_vies = new CheckboxGroup(); Checkbox cb; for (int i = 1; i <= 5; i++) { if (i == nb_vies) cb = new Checkbox("" + i, cbg_vies, true); else cb = new Checkbox("" + i, cbg_vies, false); c.gridx = i; c.gridy = 4; c.gridwidth = 1; c.gridheight = 1; c.insets = new Insets(20, 10, 5, 10); c.anchor = GridBagConstraints.CENTER; layout.setConstraints(cb, c); add(cb); } // for // label "Nombre De Victoires:" lbl_victoires = new Label(); lbl_victoires.setAlignment(Label.CENTER); lbl_victoires.setFont(new Font("SansSerif", Font.BOLD, 14)); lbl_victoires.setText("Nombre De Victoires: " + nb_victoires); lbl_victoires.setBackground(Color.black); lbl_victoires.setForeground(Color.green); c.gridx = 0; c.gridy = 6; c.gridwidth = 1; c.gridheight = 1; c.insets = new Insets(20, 10, 5, 10); c.anchor = GridBagConstraints.CENTER; layout.setConstraints(lbl_victoires, c); add(lbl_victoires); // choix du nombre de victoires entre un 1 et 9 sb_victoires = new Scrollbar(Scrollbar.HORIZONTAL, 1, 1, 1, 10); sb_victoires.setUnitIncrement(1); sb_victoires.setBlockIncrement(2); sb_victoires.addAdjustmentListener(this); sb_victoires.setValue(nb_victoires); c.gridx = 1; c.gridy = 6; c.gridwidth = 5; c.gridheight = 1; c.insets = new Insets(20, 10, 5, 10); c.anchor = GridBagConstraints.CENTER; layout.setConstraints(sb_victoires, c); add(sb_victoires); // tirage aléatoire des niveaux cb_aleatoire = new Checkbox("Niveaux Aléatoires", aleatoire); cb_aleatoire.setFont(new Font("SansSerif", Font.BOLD, 14)); cb_aleatoire.setBackground(Color.black); cb_aleatoire.setForeground(Color.magenta); c.gridx = 0; c.gridy = 8; c.gridwidth = 1; c.gridheight = 1; c.insets = new Insets(20, 12, 5, 10); c.anchor = GridBagConstraints.EAST; layout.setConstraints(cb_aleatoire, c); add(cb_aleatoire); // label "FPS:" nombre de frames par seconde lbl_fps = new Label(); lbl_fps.setAlignment(Label.CENTER); lbl_fps.setFont(new Font("SansSerif", Font.BOLD, 14)); lbl_fps.setText("FPS: " + fps); lbl_fps.setBackground(Color.black); lbl_fps.setForeground(Color.orange); c.gridx = 0; c.gridy = 10; c.gridwidth = 1; c.gridheight = 1; c.insets = new Insets(20, 10, 5, 10); c.anchor = GridBagConstraints.CENTER; layout.setConstraints(lbl_fps, c); add(lbl_fps); // choix du nombre de frames par seconde sb_fps = new Scrollbar(Scrollbar.HORIZONTAL, 1, 1, 1, 51); sb_fps.setUnitIncrement(1); sb_fps.setBlockIncrement(10); sb_fps.addAdjustmentListener(this); sb_fps.setValue(fps); c.gridx = 1; c.gridy = 10; c.gridwidth = 5; c.gridheight = 1; c.insets = new Insets(20, 10, 5, 10); c.anchor = GridBagConstraints.CENTER; layout.setConstraints(sb_fps, c); add(sb_fps); // bouton de confirmation button_ok = new Button("Ok"); c.gridx = 0; c.gridy = 12; c.gridwidth = 6; c.gridheight = 1; c.insets = new Insets(20, 5, 20, 5); c.anchor = GridBagConstraints.CENTER; layout.setConstraints(button_ok, c); add(button_ok); button_ok.addActionListener(this); } // initConteneur()
void launch() { f.setSize(800, 800); p.setLayout(null); l1.setBounds(600, 10, 150, 36); l2.setBounds(100, 30, 400, 70); l13.setBounds(2, 90, 1200, 20); l14.setBounds(80, 150, 250, 30); t1.setBounds(330, 150, 150, 30); b1.setBounds(500, 150, 100, 30); l15.setBounds(2, 200, 1200, 20); b6.setBounds(600, 50, 100, 30); l3.setBounds(100, 250, 100, 30); t2.setBounds(300, 250, 150, 30); l4.setBounds(100, 300, 150, 30); t3.setBounds(300, 300, 150, 30); l5.setBounds(100, 350, 150, 30); t4.setBounds(300, 350, 150, 30); l6.setBounds(100, 400, 100, 30); t5.setBounds(300, 400, 150, 30); l7.setBounds(100, 450, 100, 30); c1.setBounds(300, 450, 60, 30); c2.setBounds(400, 450, 60, 30); l8.setBounds(100, 500, 100, 30); t6.setBounds(300, 500, 150, 30); l9.setBounds(100, 550, 100, 30); t7.setBounds(300, 550, 150, 30); l10.setBounds(100, 600, 120, 30); t8.setBounds(300, 600, 150, 30); l11.setBounds(100, 650, 100, 30); t9.setBounds(300, 650, 150, 30); l12.setBounds(100, 700, 150, 30); t10.setBounds(300, 700, 150, 30); b2.setBounds(500, 400, 100, 30); b3.setBounds(500, 500, 100, 30); b4.setBounds(500, 600, 100, 30); b5.setBounds(650, 150, 100, 30); b1.addActionListener(this); b2.addActionListener(this); b3.addActionListener(this); b4.addActionListener(this); b5.addActionListener(this); b6.addActionListener(this); c1.addItemListener(this); c2.addItemListener(this); p.add(l1); p.add(l2); p.add(l13); p.add(l14); p.add(t1); p.add(b1); p.add(l15); p.add(b5); p.add(b6); f.add(p); f.setVisible(true); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); }
void init(String[] names1, float[][][] pch1, int psfflag1) { setLayout(null); names = names1; pch = pch1; psfflag = psfflag1; ncurves = pch.length; nparams = 11; xpts = pch[0].length; ypts = pch[0][0].length; checkarray = new Checkbox[ncurves]; include = new boolean[ncurves]; namearray = new TextField[ncurves + 1]; int1array = new TextField[ncurves + 1]; intensity1 = new double[ncurves + 1]; e1array = new TextField[ncurves + 1]; n1array = new TextField[ncurves + 1]; bright1 = new double[ncurves + 1]; number1 = new double[ncurves + 1]; int2array = new TextField[ncurves + 1]; intensity2 = new double[ncurves + 1]; e2array = new TextField[ncurves + 1]; n2array = new TextField[ncurves + 1]; bright2 = new double[ncurves + 1]; number2 = new double[ncurves + 1]; eccarray = new TextField[ncurves + 1]; brightcc = new double[ncurves + 1]; eminccarray = new TextField[ncurves + 1]; brightmincc = new double[ncurves + 1]; c2array = new TextField[ncurves + 1]; c2 = new double[ncurves + 1]; nmeas = new int[ncurves + 1]; avg = new float[xpts][ypts]; indices = new int[ncurves]; beta = 0.05; getintbright(); for (int i = 0; i < ncurves; i++) { include[i] = true; indices[i] = i; } updateavg(); int starty = 60; int startx = 10; int yinc = 25; for (int i = 0; i <= ncurves; i++) { if (i != ncurves) { checkarray[i] = new Checkbox("", include[i]); checkarray[i].setBounds(startx, starty + i * yinc, 20, 20); checkarray[i].addItemListener(this); add(checkarray[i]); } namearray[i] = new TextField(names[i]); namearray[i].setBounds(startx + 30, starty + i * yinc, 200, 20); add(namearray[i]); int1array[i] = new TextField("" + (float) intensity1[i]); int1array[i].setBounds(startx + 30 + 210, starty + i * yinc, 40, 20); add(int1array[i]); e1array[i] = new TextField("" + (float) bright1[i]); e1array[i].setBounds(startx + 30 + 210 + 50, starty + i * yinc, 40, 20); add(e1array[i]); n1array[i] = new TextField("" + (float) number1[i]); n1array[i].setBounds(startx + 30 + 210 + 50 + 50, starty + i * yinc, 40, 20); add(n1array[i]); int2array[i] = new TextField("" + (float) intensity2[i]); int2array[i].setBounds(startx + 30 + 210 + 50 + 50 + 50, starty + i * yinc, 40, 20); add(int2array[i]); e2array[i] = new TextField("" + (float) bright2[i]); e2array[i].setBounds(startx + 30 + 210 + 50 + 50 + 50 + 50, starty + i * yinc, 40, 20); add(e2array[i]); n2array[i] = new TextField("" + (float) number2[i]); n2array[i].setBounds(startx + 30 + 210 + 50 + 50 + 50 + 50 + 50, starty + i * yinc, 40, 20); add(n2array[i]); eccarray[i] = new TextField("" + (float) brightcc[i]); eccarray[i].setBounds( startx + 30 + 210 + 50 + 50 + 50 + 50 + 50 + 50, starty + i * yinc, 40, 20); add(eccarray[i]); eminccarray[i] = new TextField("" + (float) brightmincc[i]); eminccarray[i].setBounds( startx + 30 + 210 + 50 + 50 + 50 + 50 + 50 + 50 + 50, starty + i * yinc, 40, 20); add(eminccarray[i]); c2[i] = 0.0; c2array[i] = new TextField("" + (float) c2[i]); c2array[i].setBounds( startx + 30 + 210 + 50 + 50 + 50 + 50 + 50 + 50 + 50 + 50, starty + i * yinc, 80, 20); add(c2array[i]); } namelabel = new Label("Filename"); namelabel.setBounds(startx + 30, starty - 25, 100, 20); add(namelabel); intlabel = new Label("<Ig>"); intlabel.setBounds(startx + 30 + 210, starty - 25, 40, 20); add(intlabel); brightlabel = new Label("<eg>"); brightlabel.setBounds(startx + 30 + 210 + 50, starty - 25, 40, 20); add(brightlabel); nlabel = new Label("<Ng>"); nlabel.setBounds(startx + 30 + 210 + 50 + 50, starty - 25, 40, 20); add(nlabel); int2label = new Label("<Ir>"); int2label.setBounds(startx + 30 + 210 + 50 + 50 + 50, starty - 25, 40, 20); add(int2label); bright2label = new Label("<er>"); bright2label.setBounds(startx + 30 + 210 + 50 + 50 + 50 + 50, starty - 25, 40, 20); add(bright2label); n2label = new Label("<Nr>"); n2label.setBounds(startx + 30 + 210 + 50 + 50 + 50 + 50 + 50, starty - 25, 40, 20); add(n2label); brightcclabel = new Label("<ecc>"); brightcclabel.setBounds(startx + 30 + 210 + 50 + 50 + 50 + 50 + 50 + 50, starty - 25, 40, 20); add(brightcclabel); brightccminlabel = new Label("min"); brightccminlabel.setBounds( startx + 30 + 210 + 50 + 50 + 50 + 50 + 50 + 50 + 50, starty - 25, 40, 20); add(brightccminlabel); c2label = new Label("chi^2"); c2label.setBounds( startx + 30 + 210 + 50 + 50 + 50 + 50 + 50 + 50 + 50 + 50, starty - 25, 80, 20); add(c2label); int buttonsx = startx + 30 + 210 + 50 + 50 + 50 + 50 + 50 + 50 + 50 + 50 + 90; fitavgbutton = new Button("Fit Avg"); fitavgbutton.setBounds(buttonsx, starty - 25, 100, 40); fitavgbutton.addActionListener(this); add(fitavgbutton); fitglobalbutton = new Button("Fit Global"); fitglobalbutton.setBounds(buttonsx, starty - 25 + 50, 100, 40); fitglobalbutton.addActionListener(this); add(fitglobalbutton); clearparamsbutton = new Button("Reset Fit Params"); clearparamsbutton.setBounds(buttonsx, starty - 25 + 50 + 50, 100, 40); clearparamsbutton.addActionListener(this); add(clearparamsbutton); checkc2 = false; fitclass = new NLLSfit(this, 0.0001, 50, 0.1); globalfitclass = new NLLSglobalfit(this, 0.0001, 50, 0.1); pchfunc = new pch2D((int) ((double) xpts * 1.5), (int) ((double) ypts * 1.5), psfflag); avgfit = new float[xpts][ypts]; fit = new float[ncurves][xpts][ypts]; xvals = new float[ncurves][xpts][ypts]; for (int i = 0; i < ncurves; i++) { for (int j = 0; j < xpts; j++) { for (int k = 0; k < ypts; k++) { xvals[i][j][k] = (float) k; fit[i][j][k] = 1.0f; } } } globalc2label = new Label("Global chi^2 = " + (float) 0.0); globalc2label.setBounds(buttonsx, starty - 25 + 50 + 50 + 50, 140, 20); add(globalc2label); dispcurvelabel = new Label("Display Fit #"); dispcurvelabel.setBounds(buttonsx, starty - 25 + 50 + 50 + 50 + 30, 70, 20); add(dispcurvelabel); dispcurvechoice = new Choice(); for (int i = 0; i < ncurves; i++) { dispcurvechoice.add("" + (i + 1)); } dispcurve = 0; dispcurvechoice.select(0); dispcurvechoice.setBounds(buttonsx + 80, starty - 25 + 50 + 50 + 50 + 30, 40, 20); dispcurvechoice.addItemListener(this); add(dispcurvechoice); betalabel = new Label("Bleedthrough f"); betalabel.setBounds(buttonsx, starty - 25 + 50 + 50 + 50 + 30 + 30, 100, 20); add(betalabel); betaval = new TextField("" + (float) beta); betaval.setBounds(buttonsx + 110, starty - 25 + 50 + 50 + 50 + 30 + 30, 40, 20); betaval.addActionListener(this); add(betaval); beta = Double.parseDouble(betaval.getText()); updatebeta(); undobutton = new Button("Undo Global Fit"); undobutton.setBounds(buttonsx, starty - 25 + 50 + 50 + 50 + 30 + 30 + 50, 100, 40); undobutton.addActionListener(this); add(undobutton); geterrorsbutton = new Button("Get Errors"); geterrorsbutton.setBounds(buttonsx, starty - 25 + 50 + 50 + 50 + 30 + 30 + 50 + 50, 100, 40); geterrorsbutton.addActionListener(this); add(geterrorsbutton); copylabel = new Label("copyright 2009 Jay Unruh ([email protected]) non-profit use only"); copylabel.setBounds(10, 790, 400, 20); add(copylabel); n_b_label = new Label("N and B Analysis"); n_b_label.setBounds(250, 10, 100, 20); add(n_b_label); pwavg = new PlotWindow3D("Avg", "kg", "kr", "Frequency", avg, 0); pwavg.setLogAxes(false, false, true); pwavg.draw(); pwavg.addPoints(avgfit, true, 0); float[] temp = pwavg.getLimits(); temp[4] = 1.0f; pwavg.setLimits(temp); float[][] temppch = new float[xpts][ypts]; for (int i = 0; i < xpts; i++) { System.arraycopy(pch[dispcurve][i], 0, temppch[i], 0, ypts); } pwfit = new PlotWindow3D("Selected Curve", "kg", "kr", "Frequency", temppch, 0); pwfit.setLogAxes(false, false, true); pwfit.draw(); pwfit.addPoints(fit[dispcurve], true, 0); float[] temp2 = pwfit.getLimits(); temp2[4] = 1.0f; pwfit.setLimits(temp2); resetparams(); repaint(); }
/** Create the whole GUI, and set up event listeners */ public AllComponents(String title) { super(title); // set frame title. // Arrange to detect window close events this.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); // Set a default font this.setFont(new Font("SansSerif", Font.PLAIN, 12)); // Create the menubar. Tell the frame about it. MenuBar menubar = new MenuBar(); this.setMenuBar(menubar); // Create the file menu. Add to menubar. Menu file = new Menu("File"); menubar.add(file); // Create two items for the file menu, setting their label, shortcut, // action command and listener. Add them to File menu. // Note that we use the frame itself as the action listener MenuItem open = new MenuItem("Open", new MenuShortcut(KeyEvent.VK_O)); open.setActionCommand("open"); open.addActionListener(this); file.add(open); MenuItem quit = new MenuItem("Quit", new MenuShortcut(KeyEvent.VK_Q)); quit.setActionCommand("quit"); quit.addActionListener(this); file.add(quit); // Create Help menu; add an item; add to menubar // Display the help menu in a special reserved place. Menu help = new Menu("Help"); menubar.add(help); menubar.setHelpMenu(help); // Create and add an item to the Help menu MenuItem about = new MenuItem("About", new MenuShortcut(KeyEvent.VK_A)); about.setActionCommand("about"); about.addActionListener(this); help.add(about); // Now that we've done the menu, we can begin work on the contents of // the frame. Assign a BorderLayout manager with margins for this frame. this.setLayout(new BorderLayout(10, 10)); // Create two panels to contain two columns of components. Use our custom // ColumnLayout layout manager for each. Add them on the west and // center of the frame's border layout Panel column1 = new Panel(); column1.setLayout(new ColumnLayout(5, 10, 2, ColumnLayout.LEFT)); this.add(column1, "West"); Panel column2 = new Panel(); column2.setLayout(new ColumnLayout(5, 10, 2, ColumnLayout.LEFT)); this.add(column2, "Center"); // Create a panel to contain the buttons at the bottom of the window // Give it a FlowLayout layout manager, and add it along the south border Panel buttonbox = new Panel(); buttonbox.setLayout(new FlowLayout(FlowLayout.CENTER, 100, 10)); this.add(buttonbox, "South"); // Create pushbuttons and add them to the buttonbox Button okay = new Button("Okay"); Button cancel = new Button("Cancel"); buttonbox.add(okay); buttonbox.add(cancel); // Handle events on the buttons ActionListener buttonlistener = new ActionListener() { public void actionPerformed(ActionEvent e) { textarea.append("You clicked: " + ((Button) e.getSource()).getLabel() + "\n"); } }; okay.addActionListener(buttonlistener); cancel.addActionListener(buttonlistener); // Now start filling the left column. // Create a 1-line text field and add to left column, with a label TextField textfield = new TextField(15); column1.add(new Label("Name:")); column1.add(textfield); // Handle events on the TextField textfield.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { textarea.append("Your name is: " + ((TextField) e.getSource()).getText() + "\n"); } }); textfield.addTextListener( new TextListener() { public void textValueChanged(TextEvent e) { textarea.append("You have typed: " + ((TextField) e.getSource()).getText() + "\n"); } }); // Create a dropdown list or option menu of choices Choice choice = new Choice(); choice.addItem("red"); choice.addItem("green"); choice.addItem("blue"); column1.add(new Label("Favorite color:")); column1.add(choice); // Handle events on this choice choice.addItemListener( new ItemListener() { public void itemStateChanged(ItemEvent e) { textarea.append("Your favorite color is: " + e.getItem() + "\n"); } }); // Create checkboxes, and group them in a CheckboxGroup to give them // "radio button" behavior. CheckboxGroup checkbox_group = new CheckboxGroup(); Checkbox[] checkboxes = new Checkbox[3]; checkboxes[0] = new Checkbox("vanilla", checkbox_group, false); checkboxes[1] = new Checkbox("chocolate", checkbox_group, true); checkboxes[2] = new Checkbox("strawberry", checkbox_group, false); column1.add(new Label("Favorite flavor:")); for (int i = 0; i < checkboxes.length; i++) column1.add(checkboxes[i]); // Handle events on the checkboxes ItemListener checkbox_listener = new ItemListener() { public void itemStateChanged(ItemEvent e) { textarea.append( "Your favorite flavor is: " + ((Checkbox) e.getItemSelectable()).getLabel() + "\n"); } }; for (int i = 0; i < checkboxes.length; i++) checkboxes[i].addItemListener(checkbox_listener); // Create a list of choices. List list = new List(4, true); list.addItem("Java"); list.addItem("C"); list.addItem("C++"); list.addItem("Smalltalk"); list.addItem("Lisp"); list.addItem("Modula-3"); list.addItem("Forth"); column1.add(new Label("Favorite languages:")); column1.add(list); // Handle events on this list list.addItemListener( new ItemListener() { public void itemStateChanged(ItemEvent e) { textarea.append("Your favorite languages are: "); String[] languages = ((List) e.getItemSelectable()).getSelectedItems(); for (int i = 0; i < languages.length; i++) { if (i > 0) textarea.append(","); textarea.append(languages[i]); } textarea.append("\n"); } }); // Create a multi-line text area in column 2 textarea = new TextArea(6, 40); textarea.setEditable(false); column2.add(new Label("Messages")); column2.add(textarea); // Create a scrollpane that displays portions of a larger component ScrollPane scrollpane = new ScrollPane(); scrollpane.setSize(300, 150); column2.add(new Label("Scrolling Window")); column2.add(scrollpane); // Create a custom MultiLineLabel with a really big font and make it // a child of the ScrollPane container String message = "/*************************************************\n" + " * AllComponents.java *\n" + " * Written by David Flanagan *\n" + " * Copyright (c) 1997 by O'Reilly & Associates *\n" + " * *\n" + " *************************************************/\n"; MultiLineLabel biglabel = new MultiLineLabel(message); biglabel.setFont(new Font("Monospaced", Font.BOLD + Font.ITALIC, 24)); scrollpane.add(biglabel); }
public void init() { try { robot = new Robot(); } catch (AWTException ex) { ex.printStackTrace(); throw new RuntimeException(ex); } this.setLayout(new BorderLayout()); target.setBackground(Color.green); target.setName("GreenBox"); // for the ease of debug target.setPreferredSize(new Dimension(100, 100)); String toolkit = Toolkit.getDefaultToolkit().getClass().getName(); // on X systems two buttons are reserved for wheel though they are countable by MouseInfo. int buttonsNumber = toolkit.equals("sun.awt.windows.WToolkit") ? MouseInfo.getNumberOfButtons() : MouseInfo.getNumberOfButtons() - 2; for (int i = 0; i < 8; i++) { buttonNumber.add("BUTTON" + (i + 1) + "_MASK"); } pressOn.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("Now pressing : " + (buttonNumber.getSelectedIndex() + 1)); Timer timer = new Timer(); TimerTask robotInteraction = new TimerTask() { public void run() { robot.mouseMove(updateTargetLocation().x, updateTargetLocation().y); robot.mousePress(getMask(buttonNumber.getSelectedIndex() + 1)); } }; timer.schedule(robotInteraction, SEND_DELAY); } }); releaseOn.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("Now releasing : " + (buttonNumber.getSelectedIndex() + 1)); Timer timer = new Timer(); TimerTask robotInteraction = new TimerTask() { public void run() { robot.mouseMove(updateTargetLocation().x, updateTargetLocation().y); robot.mouseRelease(getMask(buttonNumber.getSelectedIndex() + 1)); } }; timer.schedule(robotInteraction, SEND_DELAY); } }); clickOn.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("Now clicking : " + (buttonNumber.getSelectedIndex() + 1)); Timer timer = new Timer(); TimerTask robotInteraction = new TimerTask() { public void run() { robot.mouseMove(updateTargetLocation().x, updateTargetLocation().y); robot.mousePress(getMask(buttonNumber.getSelectedIndex() + 1)); robot.mouseRelease(getMask(buttonNumber.getSelectedIndex() + 1)); } }; timer.schedule(robotInteraction, SEND_DELAY); } }); target.addMouseListener( new MouseAdapter() { public void mousePressed(MouseEvent e) { Sysout.println("" + e); } public void mouseReleased(MouseEvent e) { Sysout.println("" + e); } public void mouseClicked(MouseEvent e) { Sysout.println("" + e); } }); String[] instructions = { "Do provide an instruction to the robot by", "choosing the button number to act and ", "pressing appropriate java.awt.Button on the left.", "Inspect an output in the TextArea below.", "Please don't generate non-natural sequences like Release-Release, etc.", "If you use keyboard be sure that you released the keyboard shortly.", "If events are generated well press Pass, otherwise Fail." }; Sysout.createDialogWithInstructions(instructions); } // End init()
/** Capture des évènements des menus choix */ public void itemStateChanged(ItemEvent e) { if (e.getSource().equals(choix_couleur0)) { if (e.getItem() == "rouge") { choix_couleur0.setBackground(Color.red); choix_couleur1.setBackground(Color.blue); choix_couleur1.select("bleu"); couleurs[0] = ROUGE; couleurs[1] = BLEU; } if (e.getItem() == "bleu") { choix_couleur0.setBackground(Color.blue); choix_couleur1.setBackground(Color.red); choix_couleur1.select("rouge"); couleurs[0] = BLEU; couleurs[1] = ROUGE; } } if (e.getSource().equals(choix_couleur1)) { if (e.getItem() == "rouge") { choix_couleur1.setBackground(Color.red); choix_couleur0.setBackground(Color.blue); choix_couleur0.select("bleu"); couleurs[1] = ROUGE; couleurs[0] = BLEU; } if (e.getItem() == "bleu") { choix_couleur1.setBackground(Color.blue); choix_couleur0.setBackground(Color.red); choix_couleur0.select("rouge"); couleurs[1] = BLEU; couleurs[0] = ROUGE; } } } // itemStateChanged()