Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need help with writing a GUI application that allows a user to select specific

ID: 664755 • Letter: I

Question

I need help with writing a GUI application that allows a user to select specific options for a dorm room from the available list of options. This GUI application will use JCheckBoxes placed on JFrame to allow selections of a private room option, internet connection, cable TV connection, microwave, and refrigerator. Also – have a text area to show the choice made. When the application starts, the text area will display a message listing the options which can be selected, and as the user selects and deselects options, the proper additions to that message will be made. Please provide explanations/comments of the solution.

Explanation / Answer

package clickers; /** * * @author User */ import java.awt.*; import javax.swing.*; import java.util.ArrayList.*; import java.util.Arrays.*; import javax.swing.JComboBox; import javax.swing.JFrame; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class Clickers extends JPanel implements ActionListener { TextArea text1; JRadioButton button1,button2; JComboBox d; JCheckBox e,f,g,h,i,j; public Clickers(){ CheckboxGroup a = new CheckboxGroup(); e=new JCheckBox("Hospital"); f=new JCheckBox("University"); g=new JCheckBox("Pool"); h=new JCheckBox("Farm"); i=new JCheckBox("Castle"); j=new JCheckBox("Sewer"); add(e); add(f); add(g); add(h); add(i); add(j); e.addActionListener(this); f.addActionListener(this); g.addActionListener(this); h.addActionListener(this); i.addActionListener(this); j.addActionListener(this); String[] v={"Car","Bicycle","DumpTruck","BattleTank"}; d = new JComboBox(v); add(d); text1 = new TextArea(); add(text1); button1 = new JRadioButton("Boy"); add(button1); button1.addActionListener(this); button2 = new JRadioButton("Girl"); add(button2); button2.addActionListener(this); ButtonGroup bg = new ButtonGroup(); bg.add(button1); bg.add(button2); } @Override public void actionPerformed(ActionEvent event){ if(event.getSource()==button1 || (event.getSource()==e)){ text1.setText("When I was a boy, I always dreamed of having my own Hospital"); } if(event.getSource()==button1 || (event.getSource()==f)){ text1.setText("When I was a boy, I always dreamed of having my own University"); } if(event.getSource()==button1 || (event.getSource()==g)){ text1.setText("When I was a boy, I always dreamed of having my own Pool"); } if(event.getSource()==button1 || (event.getSource()==h)){ text1.setText("When I was a boy, I always dreamed of having my own Farm"); } if(event.getSource()==button1 || (event.getSource()==i)){ text1.setText("When I was a boy, I always dreamed of having my own Castle"); } if(event.getSource()==button1 && (event.getSource()==j)){ text1.setText("When I was a boy, I always dreamed of having my own Sewer"); } if(event.getSource()==button1){ text1.setText("When I was a boy, I always dreamed of having my own"); } if(event.getSource()==button2 || (event.getSource()==e)){ text1.setText("When I was a girl, I always dreamed of having my own Hospital"); } if(event.getSource()==button2 || (event.getSource()==f)){ text1.setText("When I was a girl, I always dreamed of having my own University"); } if(event.getSource()==button2 || (event.getSource()==g)){ text1.setText("When I was a girl, I always dreamed of having my own Pool"); } if(event.getSource()==button2 || (event.getSource()==h)){ text1.setText("When I was a girl, I always dreamed of having my own Farm"); } if(event.getSource()==button2 || (event.getSource()==i)){ text1.setText("When I was a girl, I always dreamed of having my own Castle"); } if(event.getSource()==button2 || (event.getSource()==j)){ text1.setText("When I was a girl, I always dreamed of having my own Sewer"); } if(event.getSource()==button2){ text1.setText("When I was a girl, I always dreamed of having my own"); } } public static void main(String[] args){ JFrame jf = new JFrame("Defend for our Final!"); jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); jf.setSize(500, 400); jf.getContentPane().add(new Clickers()); jf.setVisible(true); } }