gpt4 book ai didi

java - 如何获取标签值的返回值

转载 作者:行者123 更新时间:2023-12-02 14:30:06 24 4
gpt4 key购买 nike

嗨,我已经编写了这段代码,我在这段代码中尝试的是将方法的返回值获取到 java swing 标签

这是我的代码:

public static int search(java.util.Date date)
{

Connection conn = null;
ResultSet rs = null;
Statement st = null;
int b=0;
try
{

conn=DBMgr.openConnection();
DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
String dateStr=formatter.format(date);
System.out.println("date"+dateStr);
String sqlQuery = "select sum(time_spend) as Time_Billed_Per_Day,datetime from time_entry where datetime like '"+dateStr+"%' ";


st = conn.createStatement();
rs = st.executeQuery(sqlQuery);

while(rs.next())
{

b = rs.getInt(1);
System.out.println("BILL of the date u specified is:"+b);
}
}
catch(SQLException ex)
{
System.out.println(ex.toString());
}
finally
{
try
{

if(rs!=null)
rs.close();
if(conn!=null)
DBMgr.closeConnection(conn);
}
catch(Exception ex)
{
}

}
return b;
}

这是 Swing 代码:

JLabel lblTimeBilledDayText = new JLabel( "00:45:20" , JLabel.RIGHT);
pnlOuter.add(lblTimeBilledDayText);

我想获取方法的返回值来代替“00:45:20”

如何做到这一点?

最佳答案

试试这个

JLabel lblTimeBilledDayText = new JLabel(String.valueOf(search(date)) , JLabel.RIGHT);
pnlOuter.add(lblTimeBilledDayText);

关于java - 如何获取标签值的返回值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17020084/

24 4 0