javax.swing.JButton.getName()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(5.9k)|赞(0)|评价(0)|浏览(186)

本文整理了Java中javax.swing.JButton.getName()方法的一些代码示例,展示了JButton.getName()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JButton.getName()方法的具体详情如下:
包路径:javax.swing.JButton
类名称:JButton
方法名:getName

JButton.getName介绍

暂无

代码示例

代码示例来源:origin: stackoverflow.com

  1. JButton btnClear = new JButton("clear");
  2. btnClear.addActionListener(this);
  3. btnClear.setName("clear");
  4. //..............
  5. //..............
  6. public void actionPerformed(ActionEvent e) {
  7. JButton o = (JButton)e.getSource();
  8. String name = o.getName();
  9. if (name == "clear")
  10. {
  11. euroMillText.setText("");
  12. }
  13. else if (name == "eumill")
  14. {
  15. getLottoNumbers();
  16. }
  17. //JOptionPane.showMessageDialog(null,name);
  18. }

代码示例来源:origin: stackoverflow.com

  1. public void actionPerformed(ActionEvent e) {
  2. // get the button that was pressed
  3. JButton b = (JButton) e.getSource();
  4. // fire appropriate event
  5. if (b.getName().equals("Normal Setup")) {
  6. // set up for normal simulation
  7. fireSimulationEvent(SimulationEvent.NORMAL_SETUP_EVENT);
  8. }
  9. ......

代码示例来源:origin: stackoverflow.com

  1. for (int j = 0; j < MAX_COLUMNS; j++) {
  2. JButton button = new JButton("foo");
  3. rows[i].add(button, button.getName());
  4. }

代码示例来源:origin: stackoverflow.com

  1. for(JButton button : buttonList) {
  2. button.setText(languagePropertyManager.getProperty(button.getName()));
  3. }

代码示例来源:origin: com.eas.platypus/platypus-js-forms

  1. @Override
  2. public String toString() {
  3. return String.format("%s [%s]", super.getName() != null ? super.getName() : "", getClass().getSimpleName());
  4. }

代码示例来源:origin: stackoverflow.com

  1. public void actionPerformed(ActionEvent e) {
  2. if(buttonA.contains(e.getSource())) {
  3. JButton btn = (JButton) e.getSource();
  4. display.setText(display.getText() + btn.getName());
  5. } else if() { // operations like +,- etc.,
  6. }

代码示例来源:origin: stackoverflow.com

  1. b1.addActionListener(this);
  2. b1.setName("OpenJDialog");
  3. //this is to read in actionperformed method incase you have more than one button
  4. // in action performed method call the dialogue class
  5. public void actionPerformed(ActionEvent ae){
  6. JButton jb = (JButton)ae.getSource();
  7. String str = jb.getName();
  8. if(str.equals("OpenJDialog"){
  9. new OptionView();
  10. //I am assuming u are configuring jdialog content in OptionView constructor
  11. }
  12. }

代码示例来源:origin: stackoverflow.com

  1. static class progHandler implements ActionListener{
  2. @Override
  3. public void actionPerformed(ActionEvent e){
  4. if(e.getSource().getClass().equals(JButton.class))
  5. {
  6. JButton buttonPressed = (JButton)e.getSource();
  7. if(buttonPressed.getName().equals("reserve A1"))//this is the symbol that it cannot find.
  8. {
  9. //do whatever you want
  10. }
  11. }
  12. }
  13. }

代码示例来源:origin: stackoverflow.com

  1. Random r = new Random();
  2. int i = r.nextInt(5); // chooses 0, 1, .. 4
  3. int j = r.nextInt(5);
  4. JButton b = buttons[i][j];
  5. b.setText(b.getName());

代码示例来源:origin: MegaMek/mekhq

  1. @Override
  2. public void actionPerformed(java.awt.event.ActionEvent evt) {
  3. UUID id = UUID.fromString(evt.getActionCommand());
  4. int idx = Integer.parseInt(((JButton)evt.getSource()).getName());
  5. editUnit(id, idx, salvage);
  6. }
  7. }

代码示例来源:origin: stackoverflow.com

  1. @Override
  2. public void actionPerformed(ActionEvent e) {
  3. // press the button
  4. System.out.println(e.getActionCommand());
  5. JButton btn=(JButton)e.getSource();
  6. System.out.println(btn.getName()); // use name or action command in if statment
  7. }

代码示例来源:origin: com.eas.platypus/platypus-js-forms

  1. @ScriptFunction(jsDoc = JS_NAME_DOC)
  2. @Override
  3. public String getName() {
  4. return super.getName();
  5. }

代码示例来源:origin: Audiveris/audiveris

  1. @Override
  2. public void actionPerformed (ActionEvent e)
  3. {
  4. String setName = ((JButton) e.getSource()).getName();
  5. ShapeSet set = ShapeSet.getShapeSet(setName);
  6. selectShapeSet(set);
  7. }
  8. };

代码示例来源:origin: stackoverflow.com

  1. private void JBsetseleccionadActionPerformed(java.awt.event.ActionEvent evt) {
  2. // TODO add your handling code here:
  3. Object boton = evt.getSource();
  4. JButton este = (JButton) boton;
  5. este.setName("button_name"); // set the name first
  6. seleccionado = este;
  7. System.out.println("SOURCE " + boton.toString());
  8. System.out.println("NAME " + este.getName());
  9. }

代码示例来源:origin: stackoverflow.com

  1. JButton randomButton = new JButton("I'm a label!");
  2. System.out.println(randomButton.getName()); // prints null
  3. System.out.println(randomButton.getText()); // prints the label

代码示例来源:origin: stackoverflow.com

  1. public FlippingCoins() {
  2. final JPanel p = new JPanel();
  3. p.setLayout(new GridLayout(3, 3, 1, 1));
  4. for (int i = 0; i < 9; i++) {
  5. final JButton jbt = new JButton("H");
  6. jbt.setName("" + i);
  7. jbt.addActionListener(new ActionListener() {
  8. public void actionPerformed(final ActionEvent e) {
  9. jbt.setText("T");
  10. System.out.println(jbt.getName());
  11. }
  12. });
  13. p.add(jbt);
  14. }
  15. setContentPane(p);
  16. }

代码示例来源:origin: freeplane/freeplane

  1. protected void setButtonsVisible(JTable table, int row) {
  2. final ManageAddOnsPanel.AddOnTableModel model = (ManageAddOnsPanel.AddOnTableModel) table.getModel();
  3. final AddOnProperties addOn = model.getAddOnAt(row);
  4. for (JButton btn : buttons) {
  5. final boolean supportsOperation = addOn.supportsOperation(btn.getName());
  6. btn.setVisible(supportsOperation);
  7. }
  8. }

代码示例来源:origin: stackoverflow.com

  1. public void actionPerformed(ActionEvent e) {
  2. // press the button
  3. JButton button = (JButton)e.getSource();
  4. Syestem.out.println(button.getName()); // get the name
  5. System.out.println(button.getText()) // get the text content
  6. if(button.getText().equals("clearBtn"))
  7. // clear things for me
  8. }

代码示例来源:origin: stackoverflow.com

  1. ActionListener actionListener = new ActionListener() {
  2. @Override
  3. public void actionPerformed(ActionEvent e) {
  4. if(e.getSource() instanceof JButton){
  5. JButton pressedButton = (JButton) e.getSource();
  6. String buttonsName = pressedButton.getName();
  7. String buttonsText = pressedButton.getText();
  8. // do something with those
  9. }
  10. }
  11. };
  12. JButton a = new JButton("A");
  13. a.addActionListener(actionListener);
  14. JButton b = new JButton("B");
  15. b.addActionListener(actionListener);
  16. ....

代码示例来源:origin: org.apache.geronimo.daytrader.modules/wsappclient

  1. /**
  2. * This method initializes jPanel1
  3. *
  4. * @return JPanel
  5. */
  6. private JPanel getJPanel1() {
  7. if (jPanel1 == null) {
  8. jPanel1 = new JPanel();
  9. jPanel1.setLayout(null);
  10. jPanel1.add(getJButton1(), getJButton1().getName());
  11. jPanel1.setBounds(11, 142, 287, 38);
  12. jPanel1.setBackground(new java.awt.Color(245, 245, 245));
  13. jPanel1.setBorder(
  14. BorderFactory.createEtchedBorder(
  15. EtchedBorder.LOWERED));
  16. }
  17. return jPanel1;
  18. }
  19. /**

相关文章

JButton类方法