0
我对Java编程颇为陌生,并且创建了一个Java程序,使用户可以在JFrame上使用JSpinner输入时间(HH:mm:ss格式)。它是通过自定义JSPinner的代码(如下所示)完成的。我想要做的是获取用户输入的值(Time)并将其转换为显示在JLabel上的字符串。我尝试过使用状态改变事件,但只适用于整数模型。从JSpinner获取TIME值
的JSpinner定制的代码
Date date = new Date();
SpinnerDateModel sm = new SpinnerDateModel(date, null, null, Calendar.HOUR_OF_DAY);
time_spinner = new javax.swing.JSpinner(sm);
JSpinner.DateEditor te = new JSpinner.DateEditor(time_spinner, "HH:mm:ss");
time_spinner.setEditor(te);
getContentPane().add(time_spinner, new org.netbeans.lib.awtextra.AbsoluteConstraints(120, 50, 120, 30));
'的JSpinner#的getValue '会返回代表微调器“时间”的'Date'值 - 基本概念在[如何使用微调器](https://docs.oracle.com/javase/tutorial/uiswing/components/spinner。 html) – MadProgrammer
For [example](http://stackoverflow.com/questions/23103328/how-change-formate-time-from-jspinner-solved/23103458#23103458) – MadProgrammer
如何将收到的值传递给JLabe我在哪里?我试图在控制台上打印出来进行测试,但没有任何回复。我用你的例子对象value = time_spinner.getValue()。toString();和if语句,但删除了格式HH:mm,并尝试使用System.out.print(值)将其打印出来@MadProgrammer –