-4

I'm getting this error:

non-method setBounds(int,int,int,int) cannot be referenced from a static context

My code is below:

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JButton;
import javax.swing.JTextField;
import javax.swing.JLabel;
import javax.swing.JTextArea;
import javax.swing.JCheckBox;
import javax.swing.JRadioButton;

import java.awt.*;
import java.awt.event.*;
import java.util.*;
/**
 * Write a description of class GUI here.
 * 
 * @author Ibrahim Y. Hmood 
 * @version 04.02.14
 */
public class GUI extends JFrame implements ActionListener {
    /**
     * Identify the components for the window
     */
    JPanel contentPane;
    JLabel lblLastName;
    JLabel lblFirstName;
    JLabel lblStudentID;
    JTextField txtLastName;
    JTextField txtFirstName;
    JTextField txtStudentID;
    JButton    btnSubmit;
    JLabel lblStoreFirstName;
    JLabel lblStoreLastName;
    JLabel lblStoreStudentID;
    JTextField txtStorestudentID;
    JTextArea txaAll;
    JCheckBox chkBox1;
    CheckBoxListener myListener = null;
    /**
     * Constructor for objects of class GUI
     */
public GUI()
{
    /**
     * Create the panel, its components and add them to the panel
     */
    contentPane = new JPanel (null);
    lblLastName = new JLabel ("Enter Last Name");
    lblFirstName = new JLabel ("Enter First Name");
    lblStudentID = new JLabel ("Enter Student ID");
    txtLastName = new JTextField ();
    txtFirstName = new JTextField();
    txtStudentID = new JTextField();
    btnSubmit = new JButton ("Submit Info");
    lblStoreFirstName = new JLabel ();
    lblStoreLastName = new JLabel ();
    lblStoreStudentID = new JLabel ();
    txaAll= new JTextArea ();
    chkBox1 =  new JCheckBox ("Check box one");
    chkBox1.setBounds(200,180,150,20);
    JRadioButton Label  = new JRadioButton ();
    JRadioButton.setBounds (100,200, 150, 20);

    lblLastName.setBounds(25, 25, 590, 20);
    lblFirstName.setBounds (25, 65,590, 20);
    lblStudentID.setBounds (25, 105,590, 20);

    txtLastName.setBounds(140,25,150,20);
    txtFirstName.setBounds(140,65,150,20);
    txtStudentID.setBounds(140,105,150,20);
    txaAll.setBounds(140,345,250,250); 


    btnSubmit.setBounds(100, 130, 250 ,20);

   lblStoreFirstName.setBounds(200,200,150,20);
    lblStoreLastName.setBounds(200, 240, 150, 20);
     lblStoreStudentID.setBounds(200,260, 150, 20);

    contentPane.add(lblLastName);
    contentPane.add(lblFirstName);
    contentPane.add(lblStudentID);

    contentPane.add(txtLastName);
    contentPane.add(txtFirstName);
    contentPane.add(txtStudentID);
    contentPane.add(lblStoreFirstName);
    contentPane.add(lblStoreLastName);
    contentPane.add(lblStoreStudentID);
    contentPane.add(txaAll);

    myListener = new CheckBoxListener();
    chkBox1.addItemListener(new CheckBoxListener());
    contentPane.add(chkBox1);


    chkBox1.setActionCommand("checkbox1");
    chkBox1.addActionListener(this);
     contentPane.add(chkBox1);

    btnSubmit.setActionCommand("Submit");
    btnSubmit.addActionListener(this);
    contentPane.add(btnSubmit);


    setTitle("GUI");
    setContentPane(contentPane);
    setLocation(0,0);
    setSize(600,600);
    setResizable(false);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
    private class CheckBoxListener implements ItemListener{
        public void itemStateChanged (ItemEvent e)
        {
            Object source = e.getSource();
            if (source == chkBox1) {
                if (e.getStateChange() == ItemEvent.SELECTED) {
                    txaAll.setBackground(Color.green);
                }
            }
        }
    }
    @Override
    public void actionPerformed(ActionEvent e) {
        if ("Submit".equals(e.getActionCommand())){
        btnSubmit.setBackground(Color.red);
        btnSubmit.setBackground(Color.cyan);
        String lastname = txtLastName.getText();
        String firstname = txtFirstName.getText();
        String studentID = txtStudentID.getText();
        String str = txaAll.getText();
        str+= firstname + "\t" + lastname + "\t" + studentID + "\n";
        lblStoreLastName.setText(lastname);
        lblStoreFirstName.setText (firstname);
        lblStoreStudentID.setText (studentID);
        txaAll.setText(str);      
    }
     else if ("checkBox1".equals(e.getActionCommand()))
        this.setBackground(Color.yellow);
    }
}

How can I fix this?

hichris123
  • 9,735
  • 15
  • 51
  • 66
  • It wants you to add more detail. Add more detail. Perhaps post the whole error message, and what you've actually tried to fix it. What do you think the problem is? What does it sound like the error is telling you? It would be easier for people to help you if you just posted the applicable part of your code, rather than your whole program. – Reinstate Monica -- notmaynard Apr 10 '14 at 18:27

2 Answers2

1

You put
JRadioButton label = new JRadioButton(); JRadioButton.setBounds(100,200,150,20);
You should put
label.setBounds(100,200,150,20);

PotatoPhil
  • 166
  • 1
  • 9
0

Can't just say JRadioButton.setBounds (100,200, 150, 20); Calling setBounds on JRadioButton is calling it in a static context. You have to call that on an instance of the class.

Big Al
  • 798
  • 1
  • 7
  • 20