0
내 프로그램에서 가능한 오류를 처리하려고 시도했지만 루프를 표시하는 메시지 대화 상자에 "빈을 채우다"라고 표시되어 있지만 무한히 수행합니다. 간단히 말해, 뭔가 (연락처 등)를 추가하려고 할 때 몇 가지 필드가 모두 채워져 있어야합니다. 어떻게 확인할 수 있습니까?빈 필드를 채우는 동안 JAVA 무한 루프
내 코드는 채워지지 않은 입력란을 찾기에 적합하지만 무한히 실행됩니다.
public void createContact(){
final JFrame addContact = new JFrame("Add Contact");
addContact.setSize(400,300);
addContact.setLayout(new BorderLayout());
addContact.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
JPanel info = new JPanel(new GridLayout(6,2));
JButton add = new JButton("Add");
JLabel title = new JLabel("Title: ");
JLabel firstname = new JLabel("FIRST NAME: ");
JLabel lastname = new JLabel("LAST NAME: ");
JLabel adress = new JLabel("Adress: ");
JLabel email = new JLabel("Email: ");
JLabel company = new JLabel("Company Name: ");
final JTextField title1 = new JTextField(20);
final JTextField firstname1 = new JTextField(20);
final JTextField lastname1 = new JTextField(20);
final JTextField adress1 = new JTextField(20);
final JTextField email1 = new JTextField(20);
final JTextField company1 = new JTextField(20);
info.add(title);
info.add(title1);
info.add(firstname);
info.add(firstname1);
info.add(lastname);
info.add(lastname1);
info.add(adress);
info.add(adress1);
info.add(email);
info.add(email1);
info.add(company);
info.add(company1);
addContact.add(info,BorderLayout.NORTH);
addContact.add(add,BorderLayout.SOUTH);
add.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
while(title1.getText().length() == 0 || firstname1.getText().length() == 0 || firstname1.getText().length() == 0 || adress1.getText().length() == 0 || email1.getText().length() == 0 ||company1.getText().length() ==0){
JOptionPane.showMessageDialog(null,"Please fill the empty fields.");
}
Contact newContact = new Contact(title1.getText(),firstname1.getText(),lastname1.getText(),adress1.getText(),email1.getText(),company1.getText());
contactList.add(newContact);
JOptionPane.showMessageDialog(null,"Contact has been added successfuly!");
addContact.setVisible(false);
}
});
addContact.pack();
addContact.setVisible(true);
}
와우! 나는 그것에 대해 생각하지 않았다, 어리석은 지금 haha 보인다! 고맙습니다! – Hamad