Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get return value to label value

Tags:

java

swing

jlabel

Hi i have written this code and what I am trying in this code is to to get the return value of method to java swing label

here is my code:

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;
      }

This is swings code:

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

I want to get the return value of method in place of "00:45:20"

How to do this?

like image 691
milano Avatar asked Dec 01 '25 11:12

milano


2 Answers

Try this

JLabel lblTimeBilledDayText = new JLabel(String.valueOf(search(date)) , JLabel.RIGHT);
pnlOuter.add(lblTimeBilledDayText);
like image 55
aksh1t Avatar answered Dec 02 '25 23:12

aksh1t


If b is the return int value then

JLabel lblTimeBilledDayText = new JLabel(new String(Integer.toString(b)), JLabel.RIGHT);
pnlOuter.add(lblTimeBilledDayText);
like image 24
AvmnuSng Avatar answered Dec 03 '25 01:12

AvmnuSng



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!