JCreatorを使ってログインデザインを作っています。split を使用して txt ファイルを解析し、適切な場所に配置するにはどうすればよいですか?
public logins()
{
super ("logins");
Container c=getContentPane();
c.setLayout(new GridLayout(3,3,5,5));
lbl1=new JLabel("USERNAME:");
lbl2=new JLabel("PASSWORD:");
txt1=new JTextField(10);
psw1=new JPasswordField(10);
btnLog=new JButton("LOG-IN");
btnCancel=new JButton("CANCEL");
c.add(lbl1);
c.add(txt1);
c.add(lbl2);
c.add(psw1);
c.add(btnLog);
c.add(btnCancel);
btnLog.addActionListener(this);
btnCancel.addActionListener(this);
setSize(350,150);
setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==btnCancel)
{
System.exit(0);
}
else if(e.getSource()==btnLog)
{
try
{
BufferedReader data=new BufferedReader(new FileReader("user.txt"));
String userName=txt1.getText();
String userLine=data.readLine();
boolean found=false;
while(userLine!=null)
{
if(userName.equalsIgnoreCase(userLine))
{
found=true;
break;
}
userLine=data.readLine();
}
if(found==true)
{
JOptionPane.showMessageDialog(null,"ACCESS GRANTED");
}
else
{
JOptionPane.showMessageDialog(null,"ACCESS DENIED");
}
}
catch(Exception err)
{
JOptionPane.showMessageDialog(null,err.getMessage());
}
}
}
public static void main(String args[])
{
logins lo=new logins();
lo.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}