Pls some help Use netbeans: Jframe This homework asks you to build a single inte
ID: 3684753 • Letter: P
Question
Pls some help
Use netbeans: Jframe
This homework asks you to build a single interface with the features below:
1. Build an interface that has two list, one set of radio buttons, one textfield, and one regular button.
2. The set radio buttons has 2 choices (that is two buttons). The first one is "Copy To List 1" and the second is "Copy To List 2".
3. One of the radio buttons must show selected when the program starts (before the user has a chance to interact with the interface).
4. The regular button, "Copy" should work in conjunction with the radio buttons to move text in the textfield to one list or the other.
5. Prevent an empty string to be copied to the first list, but allow that to happen to the second.
Explanation / Answer
class Example extends Jframe implements ActionListener
{
JTextarea ta;
JRadioButton rb1,rb2;
JButton b;
ButtonGroup bg;
Example()
{
Container c=getContentPane( );
c.setLayout(new FlowLayout( ));
ta=new JTextarea( );
rb1=new JRadioButton("Copy to List 1",true);
rb2=new JRadioButton("Copy to List 2",false);
bg=new ButtonGroup( );
b=new JButton("COPY");
c.add(" ",ta);
bg.add(rb1);
bg.add(rb2);
c.add(rb1);
c.add(rb2);
c.add(b);
rb1.addActionListener(this);
rb2.addActionListener(this);
b.addActionListener(this);
}
public void actionPerformed(Action Event ae)
{
String str=" ";
BufferedReader br=new Buffered Reader( );
if(rb1.getModel( ).IsSelected() && str=br.readLine() != null)
{
Strin line1;
line1+str;
}
else
{
line2+str;
}
}
public static void main(String args[ ])
{
Example e=new Example( );
e.setSize(400,400);
e.setVisible(true);
e.setDefaultClose Operation(Jframe.EXIT_ON_CLOSE);
}
}