Please help me to make more readable and simple code like this. What if I had 20 components? Is it right to organize code like this?
package newpackage.view;
import java.awt.GridLayout;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
public class UserPanel extends JPanel{
private JLabel idLbl;
private JLabel nameLbl;
private JLabel passwordLbl;
private JRadioButton adminRad;
private JRadioButton userRad;
private JTextField idFld;
private JTextField nameFld;
private JPasswordField passwordFld;
private JButton submitBtn;
public UserPanel() {
setLayout(new GridLayout(4,2));
idLbl = new JLabel("ID");
nameLbl = new JLabel("Name");
passwordLbl = new JLabel("Password");
adminRad = new JRadioButton("Admin");
userRad = new JRadioButton("User");
idFld = new JTextField();
nameFld = new JTextField();
passwordFld = new JPasswordField();
submitBtn = new JButton("Submit");
add(idLbl);
add(idFld);
add(nameLbl);
add(nameFld);
add(passwordLbl);
add(passwordFld);
add(adminRad);
add(userRad);
add(submitBtn);
}
}