//import javax.swing.JButton; //import javax.swing.JTextField; //import javax.swing.JLabel; //import javax.swing.JFrame; import java.awt.event.*; import javax.swing.*; import java.awt.FlowLayout; import java.awt.BorderLayout; class BobPanel3 extends JPanel { private JButton myButton; private JTextField firstNameField; private JTextField LastNameField; private JLabel label1; private JLabel label2; private JCheckBox cbox; private String[] buttonLabels = {"Button1", "Button2", "Button3", "Button4"}; private JRadioButton[] rbuttons; ButtonGroup bgroup; public BobPanel3() // one possible constructor { // setLayout(new GridLayout(4,2) ); firstNameField = new JTextField(15); this.add(firstNameField, BorderLayout.NORTH); // this is the same as saying: add(firstNameField); myButton = new JButton("Query the text field"); add(myButton, BorderLayout.CENTER); JPanel bottomPanel = new JPanel(); bgroup = new ButtonGroup(); rbuttons = new JRadioButton[buttonLabels.length]; for (int i = 0; i < buttonLabels.length; i++) { rbuttons[i] = new JRadioButton(buttonLabels[i]); bottomPanel.add(rbuttons[i]); bgroup.add(rbuttons[i]); } this.add(bottomPanel, BorderLayout.SOUTH); } public static void main(String[] args) { // from here, can I use the variables I declared above? // NO!!!!!!!!!!!!!!!!!!! JFrame myFrame = new JFrame("My Program In Class"); BobPanel3 p = new BobPanel3(); myFrame.add(p); // adds the panel (p) INTO the frame (myFrame) myFrame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); myFrame.setSize( 400, 300 ); // set frame size myFrame.setVisible( true ); // display frame } } // end of class BobPanel3