5 Replies - 257 Views - Last Post: 06 April 2013 - 05:41 AM Rate Topic: -----

#1 ballisticpendulum  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 06-March 13

Help in plain english? Get string that assigned to JButton

Posted 31 March 2013 - 06:02 PM

How would I get a string to output with the setText() method that was assigned randomly to a 2d array of JButtons to output when I click the JButton in the actionPerformed method? This is on a JFrame
Is This A Good Question/Topic? 0
  • +

Replies To: Help in plain english? Get string that assigned to JButton

#2 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8325
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Help in plain english? Get string that assigned to JButton

Posted 31 March 2013 - 06:09 PM

I guess YOU should rephrase your phrase in plain English :)
Was This Post Helpful? 0
  • +
  • -

#3 ballisticpendulum  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 06-March 13

Re: Help in plain english? Get string that assigned to JButton

Posted 31 March 2013 - 06:16 PM

okay okay let me try, this is using JFrame, I am not printing anything: How would I get the String (Array) assigned to a button(2D Array) randomly to be outputted onto the frame?
Was This Post Helpful? 0
  • +
  • -

#4 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8325
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Help in plain english? Get string that assigned to JButton

Posted 31 March 2013 - 06:29 PM

    String[] bntName = {"aaa", "bbb", "ccc", "ddd");
    ArrayList<String> al = new ArrayList<String>(btnName.length);
    for(String str : btnName)
      al.add(str);

    Random ran = new Random();
    while(al.size() != 0) {
      int index = ran.nextInt(al.size());
      JButton b = new JButton(al.remove(index));
      add(B)/>;
    }


Was This Post Helpful? 0
  • +
  • -

#5 ballisticpendulum  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 06-March 13

Re: Help in plain english? Get string that assigned to JButton

Posted 05 April 2013 - 05:02 PM

Thanks, this really helps :bananaman:
Was This Post Helpful? 0
  • +
  • -

#6 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2656
  • View blog
  • Posts: 11,204
  • Joined: 20-September 08

Re: Help in plain english? Get string that assigned to JButton

Posted 06 April 2013 - 05:41 AM

System.out.println(event.getActionCommand());

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1