您好我从我的团队负责人那里得到了一份任务,用于存储员工详细信息用户在文本字段中输入的内容,然后在另一个框架中,管理员必须通过调用arraylist来检查每个员工的详细信息,该列表应显示cardlayout中的面板,这里是我的员工注册编码。任何人都可以帮助我
Registration()
{
frm=new JFrame("Welcome to the login page");
left=new JPanel(new GridLayout(0,1));
left.setBackground(Color.LIGHT_GRAY);
right=new JPanel(new GridLayout(0,1));
right.setBackground(Color.LIGHT_GRAY);
sp=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,left,right);
lb9=new JLabel("Member");
lb9.setFont(new Font("Serif",Font.PLAIN, 18));
lb9.setForeground (Color.blue);
lb10=new JLabel("Create an Account");
lb10.setFont(new Font("Serif", Font.PLAIN, 16));
lb10.setForeground (Color.blue);
lb1=new JLabel("Username");
tf1=new JTextField(10);
lb2=new JLabel("Password");
tf6=new JTextField(10);
lb3=new JLabel("First Name");
tf2=new JTextField(10);
lb4=new JLabel("Last Name");
tf3=new JTextField (10);
lb5=new JLabel("Password");
psd2=new JPasswordField (10);
lb6=new JLabel("Confirm password");
psd3=new JPasswordField (10);
lb7=new JLabel("MailID:");
tf4=new JTextField (10);
lb8=new JLabel("Contact No");
tf5=new JTextField (10);
b1=new JButton("Enter");
b2=new JButton("Register");
}
public void launchFrame()
{
frm.setSize(450, 350);
frm.add(sp);
//sp.setLeftComponent(left);
//sp.setRightComponent(right);
left.add(lb9);
left.add(lb1);
left.add(tf1);
left.add(lb2);
left.add(tf6);
left.add(b1);
right.add(lb10);
right.add(lb3);
right.add(tf2);
right.add(lb4);
right.add(tf3);
right.add(lb5);
right.add(psd2);
psd2.setEchoChar('*');
right.add(lb6);
right.add(psd3);
psd3.setEchoChar('*');
right.add(lb7);
right.add(tf4);
right.add(lb8);
right.add(tf5);
right.add(b2);
frm.setVisible(true);
}
答案 0 :(得分:2)
以这种方式创建List对象
List<JPanel> panelList = new ArrayList<JPanel>();
// add your JPanel object like this way
panelList.add(yourPanel);
// retrieve your JPanel object from list
JPanel panel = panelList.get(index);
答案 1 :(得分:1)
只评论,不回答
是否有可能在arraylist中存储JPanel对象
是的可能,但为什么原因,