사용자가 입력 한 텍스트 필드에서 처리를 위해 값을 가져 오려고합니다. 그러나 내가 무엇을해도 그것이 입력 된 가치를 얻지 못할 것이고 그것은 비어있는 것처럼 보입니다. 어떤 사람이 텍스트 필드에서 값을 가져 오지 않는 이유를 말해 줄 수 있습니까? Java 코드가 JText 필드의 값을 선택하지 않는 이유는 무엇입니까?
이
은 initialy writeStringspublic void chooseEmpToAdd()
{
JTextArea EmpDetails = new JTextArea(5,20);
JTextField writeStrings = new JTextField(20);
JLabel enterIDno = new JLabel("Please enter The Employye ID number that you wish to assign to a department: ");
JButton submit = new JButton (" Submit") ;
ButtonListenerEmp Listener2 = new ButtonListenerEmp();
submit.addActionListener(Listener2);
JFrame frameAllEmps = new JFrame();
frameAllEmps.setSize(150, 140);
frameAllEmps.pack();
frameAllEmps.setVisible(true);
//layout
frameAllEmps.setLayout(new FlowLayout());
frameAllEmps.add(enterIDno);
int x = 0;
System.out.println("ALL Emps from the tree map");
for(int key:employeeMap.keySet())
{
Employee dEmp = employeeMap.get(key);
System.out.println("Employe no :" +x+": "+dEmp);
EmpDetails.setText(EmpDetails.getText()+" "+dEmp);
frameAllEmps.add(EmpDetails);
x++;
}
frameAllEmps.add(new JScrollPane(EmpDetails));
frameAllEmps.add(writeStrings);
frameAllEmps.add(submit);
frameAllEmps.pack();
}
그리고이 텍스트 상자에서 값을 콘솔에 인쇄해야합니다 액션 청취자입니다 명명 된 텍스트 필드를 생성하는 방법이지만 않습니다 작동하지.
private class ButtonListenerEmp implements ActionListener
{
public void actionPerformed (ActionEvent e)
{
String ID ;
int dID;
ID = writeStrings.getText();
System.out.println("start of try b4 changes: "+ID);
}
}
문제는 쉽게 코드에 표시되지 않을 수 있습니다. 더 빨리 도움을 받으려면 [SSCCE] (http://sscce.org/)를 게시하십시오. –
자바 명명 규칙을 배우고 그들에게 붙이십시오. – kleopatra