Java 将数字添加到列表并打印出来的按钮
我正在尝试制作一个程序,该程序接收一个数字并将其添加到列表中,然后用按钮打印出列表,但每次我运行该程序时,输出都是错误的,例如,当我输入3时,它将输出“id”=[333],请问有人能帮我吗Java 将数字添加到列表并打印出来的按钮,java,list,arraylist,Java,List,Arraylist,我正在尝试制作一个程序,该程序接收一个数字并将其添加到列表中,然后用按钮打印出列表,但每次我运行该程序时,输出都是错误的,例如,当我输入3时,它将输出“id”=[333],请问有人能帮我吗 ArrayList<Integer> list = new ArrayList<Integer>(); // store integers result.addActionListener(new ActionListener() { publ
ArrayList<Integer> list = new ArrayList<Integer>(); // store integers
result.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
int temp = Integer.parseInt(input.getText()); // get the input
list.add(temp); // add it to the list
JOptionPane.showMessageDialog(null, "The ID has been added");
} catch (NumberFormatException ex) {
JOptionPane.showMessageDialog(null, "The number you entered is not a valid Integer", "Invalid Input",
JOptionPane.WARNING_MESSAGE); // message to show if the input is invalid
}
}
});
show.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
for(int i=0;i<list.size();i++){ // print out the list
System.out.println("IDs : "+list.toString());
}
ArrayList list=new ArrayList();//存储整数
result.addActionListener(新ActionListener(){
已执行的公共无效操作(操作事件e){
试一试{
int temp=Integer.parseInt(input.getText());//获取输入
list.add(temp);//将其添加到列表中
showMessageDialog(null,“已添加ID”);
}捕获(NumberFormatException ex){
JOptionPane.showMessageDialog(null,“输入的数字不是有效整数”,“输入无效”,
JOptionPane.WARNING_MESSAGE);//显示输入是否无效的消息
}
}
});
show.addActionListener(新建ActionListener()){
已执行的公共无效操作(操作事件e){
试一试{
对于(int i=0;i您说您正在键入3。您在哪里键入它?在某个文本区域?如果您显示更多代码会有所帮助。您必须在文本字段中键入333
。不,我不,我只键入3。结果是什么?执行的操作是为了听什么?我们可以看到更多代码吗,因为现在无法知道为什么要打印它如果你在打3,请打333。