JButton btnClear = new JButton("clear"); btnClear.addActionListener(this); btnClear.setName("clear"); //.............. //.............. public void actionPerformed(ActionEvent e) { JButton o = (JButton)e.getSource(); String name = o.getName(); if (name == "clear") { euroMillText.setText(""); } else if (name == "eumill") { getLottoNumbers(); } //JOptionPane.showMessageDialog(null,name); }
public void actionPerformed(ActionEvent e) { // get the button that was pressed JButton b = (JButton) e.getSource(); // fire appropriate event if (b.getName().equals("Normal Setup")) { // set up for normal simulation fireSimulationEvent(SimulationEvent.NORMAL_SETUP_EVENT); } ......
for (int j = 0; j < MAX_COLUMNS; j++) { JButton button = new JButton("foo"); rows[i].add(button, button.getName()); }
for(JButton button : buttonList) { button.setText(languagePropertyManager.getProperty(button.getName())); }
public void actionPerformed(ActionEvent e) { if(buttonA.contains(e.getSource())) { JButton btn = (JButton) e.getSource(); display.setText(display.getText() + btn.getName()); } else if() { // operations like +,- etc., }
b1.addActionListener(this); b1.setName("OpenJDialog"); //this is to read in actionperformed method incase you have more than one button // in action performed method call the dialogue class public void actionPerformed(ActionEvent ae){ JButton jb = (JButton)ae.getSource(); String str = jb.getName(); if(str.equals("OpenJDialog"){ new OptionView(); //I am assuming u are configuring jdialog content in OptionView constructor } }
static class progHandler implements ActionListener{ @Override public void actionPerformed(ActionEvent e){ if(e.getSource().getClass().equals(JButton.class)) { JButton buttonPressed = (JButton)e.getSource(); if(buttonPressed.getName().equals("reserve A1"))//this is the symbol that it cannot find. { //do whatever you want } } } }
Random r = new Random(); int i = r.nextInt(5); // chooses 0, 1, .. 4 int j = r.nextInt(5); JButton b = buttons[i][j]; b.setText(b.getName());
@Override public void actionPerformed(java.awt.event.ActionEvent evt) { UUID id = UUID.fromString(evt.getActionCommand()); int idx = Integer.parseInt(((JButton)evt.getSource()).getName()); editUnit(id, idx, salvage); } }
@Override public void actionPerformed(ActionEvent e) { // press the button System.out.println(e.getActionCommand()); JButton btn=(JButton)e.getSource(); System.out.println(btn.getName()); // use name or action command in if statment }
@ScriptFunction(jsDoc = JS_NAME_DOC) @Override public String getName() { return super.getName(); }
@Override public void actionPerformed (ActionEvent e) { String setName = ((JButton) e.getSource()).getName(); ShapeSet set = ShapeSet.getShapeSet(setName); selectShapeSet(set); } };
private void JBsetseleccionadActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: Object boton = evt.getSource(); JButton este = (JButton) boton; este.setName("button_name"); // set the name first seleccionado = este; System.out.println("SOURCE " + boton.toString()); System.out.println("NAME " + este.getName()); }
JButton randomButton = new JButton("I'm a label!"); System.out.println(randomButton.getName()); // prints null System.out.println(randomButton.getText()); // prints the label
public FlippingCoins() { final JPanel p = new JPanel(); p.setLayout(new GridLayout(3, 3, 1, 1)); for (int i = 0; i < 9; i++) { final JButton jbt = new JButton("H"); jbt.setName("" + i); jbt.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent e) { jbt.setText("T"); System.out.println(jbt.getName()); } }); p.add(jbt); } setContentPane(p); }
protected void setButtonsVisible(JTable table, int row) { final ManageAddOnsPanel.AddOnTableModel model = (ManageAddOnsPanel.AddOnTableModel) table.getModel(); final AddOnProperties addOn = model.getAddOnAt(row); for (JButton btn : buttons) { final boolean supportsOperation = addOn.supportsOperation(btn.getName()); btn.setVisible(supportsOperation); } }
public void actionPerformed(ActionEvent e) { // press the button JButton button = (JButton)e.getSource(); Syestem.out.println(button.getName()); // get the name System.out.println(button.getText()) // get the text content if(button.getText().equals("clearBtn")) // clear things for me }
ActionListener actionListener = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if(e.getSource() instanceof JButton){ JButton pressedButton = (JButton) e.getSource(); String buttonsName = pressedButton.getName(); String buttonsText = pressedButton.getText(); // do something with those } } }; JButton a = new JButton("A"); a.addActionListener(actionListener); JButton b = new JButton("B"); b.addActionListener(actionListener); ....
/** * This method initializes jPanel1 * * @return JPanel */ private JPanel getJPanel1() { if (jPanel1 == null) { jPanel1 = new JPanel(); jPanel1.setLayout(null); jPanel1.add(getJButton1(), getJButton1().getName()); jPanel1.setBounds(11, 142, 287, 38); jPanel1.setBackground(new java.awt.Color(245, 245, 245)); jPanel1.setBorder( BorderFactory.createEtchedBorder( EtchedBorder.LOWERED)); } return jPanel1; } /**