Java - get JRadioButton cmd with Jbutton listener
<p>I am new to java and creating a Simple gui App. In this simple app, I am trying to write a e-commerce letter for Firms. So, I planned  my app something like this.. </p>

<blockquote>
  <p>First i ask to user if he want to write an letter to British Firm or American. For this i use two radio buttons(one for american firm and second for british) and  JButton. When user Trigger jbutton then i want to get radiobutton command(which type of letter user want to write).</p>
</blockquote>

<p>The problem is I don't have any  idea to get Radiobutton command when i trigger jButton. Please give me an Simple Idea(if possible with exapmle not complicated for begginers) to get RadioButtons value..</p>

<p>Here is my java Code:</p>

<pre><code>import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

class englet{

    static public JFrame f;
    static public JPanel p;
    static class getTypeOfLetter implements ActionListener{

        public void actionPerformed( ActionEvent e){
            String btnInput = e.getActionCommand();
            System.out.println(btnInput);

        }
    }
    public static void askletter(){
        JRadioButton btnRadio1;
        JRadioButton btnRadio2;
        ButtonGroup btngrp;
        JButton btnGo = new JButton("Write");
        btnRadio1 = new JRadioButton("Write Letter For American Firm");
        btnRadio1.setActionCommand("Amer");
        btnRadio2 = new JRadioButton("Write Letter For British Firm");
        btnRadio2.setActionCommand("Brit");
        btngrp    = new ButtonGroup();
        btnGo.setActionCommand("WriteTest");
        btnGo.addActionListener(new getTypeOfLetter());
        btngrp.add(btnRadio1);
        btngrp.add(btnRadio2);
        p.add(btnRadio1);
        p.add(btnRadio2);
        p.add(btnGo);
    }
    englet(){
        f  = new JFrame("English Letter");
        p  = new JPanel();
        askletter();
        f.add(p);
        f.setSize(400,200);
        f.setVisible(true);

    }
    public static void main (String[] argv ){
        englet i = new englet();
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
}
</code></pre>

<p>I am using Notepad++ and CMD.. Not any another tools like netbeans initllli ecplisse.
**RE-EDIT ** I want a possible solution and can satisfy me.. this app works but i am not able to get radiobuttons commmand with jubtton..</p>