이것은 분명한 질문 일 수 있습니다. 모르겠지만 어디에서나 답을 찾을 수 없습니다. 그래서, 나는 몇 가지 텍스트를 가져 와서 그것을 문자열 []에 넣는 JTextField를 가지고 있지만 대신 int []에 넣고 싶습니다. 여기에 약간의 코드가 있지만 물론 오류가 있으며 int []로 변환해야합니다. 내가 어떻게 할 수 있는지에 대한 아이디어는?String []을 int []로 변환하려면 어떻게해야합니까?
또한 문제가있는 코드는 버튼 액션 이벤트 내부에 있으므로 쉽게 찾을 수 있습니다. 감사합니다.
private void initComponents() {
// JFormDesigner - Component initialization - DO NOT MODIFY
// //GEN-BEGIN:initComponents
// Generated using JFormDesigner Evaluation license - Will Baker
textField9 = new JTextField();
textField10 = new JTextField();
label10 = new JLabel();
label9 = new JLabel();
button5 = new JButton();
// ======== this ========
Container contentPane = getContentPane();
contentPane.setLayout(null);
contentPane.add(textField9);
textField9.setBounds(90, 15, 273,
textField9.getPreferredSize().height);
contentPane.add(textField10);
textField10.setBounds(90, 40, 273,
textField10.getPreferredSize().height);
// ---- label10 ----
label10.setText("Loot Name(s):");
contentPane.add(label10);
label10.setBounds(new Rectangle(new Point(20, 40), label10
.getPreferredSize()));
// ---- label9 ----
label9.setText("NPC Name(s):");
contentPane.add(label9);
label9.setBounds(20, 10, 68, 25);
// ---- button5 ----
button5.setText("Start!");
button5.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
NPC_NAME = textField9.getText().split(",");
LOOT_NAMES = textField10.getText().split(",");
running = true;
gui.dispose();
}
});
contentPane.add(button5);
button5.setBounds(90, 70, 208, button5.getPreferredSize().height);
{ // compute preferred size
Dimension preferredSize = new Dimension();
for (int i = 0; i < contentPane.getComponentCount(); i++) {
Rectangle bounds = contentPane.getComponent(i).getBounds();
preferredSize.width = Math.max(bounds.x + bounds.width,
preferredSize.width);
preferredSize.height = Math.max(bounds.y + bounds.height,
preferredSize.height);
}
Insets insets = contentPane.getInsets();
preferredSize.width += insets.right;
preferredSize.height += insets.bottom;
contentPane.setMinimumSize(preferredSize);
contentPane.setPreferredSize(preferredSize);
}
pack();
setLocationRelativeTo(getOwner());
// JFormDesigner - End of component initialization
// //GEN-END:initComponents
}
// JFormDesigner - Variables declaration - DO NOT MODIFY
// //GEN-BEGIN:variables
// Generated using JFormDesigner Evaluation license - Will Baker
private JTextField textField9;
private JTextField textField10;
private JLabel label10;
private JLabel label9;
private JButton button5;
// JFormDesigner - End of variables declaration //GEN-END:variables
}
당신의'문자열 []'반복하고있는 Integer.parseInt()'호출하여의''int로 []' –
은 http://docs.oracle.com보기 /javase/7/docs/api/java/lang/Integer.html#parseInt%28java.lang.String%29 – fajarkoe
왜이 관련성이없는 코드를 게시 하시겠습니까? 다음 시그니처를 가진 메소드를 작성함으로써 시작하십시오 :'int [] stringArrayToIntArray (String [] strings)'. 그런 다음 구현하십시오. 루프가 필요할 것이고 java.lang.Integer의 javadoc에서 String을 int로 변환하는 방법을 찾아야 할 것이다. 어렵지 않아야합니다. –