دنبال کننده ها

۱۳۹۶ اسفند ۹, چهارشنبه

java - Update only once a week

[ad_1]



I'm trying to make a method that once a week returns the points number in the qntSemanal Label.
How can i have a fixed day that every week calculates the pts?



Obs: I'm new at JCalendar, do u think it's better to create a List of the days of the month, or use the JCalendar methods? how it would be more optimized?



 public class CoffeeCalendar extends javax.swing.JFrame 
List dailyCoffeeTimes = new ArrayList();

jTextField1 = new javax.swing.JTextField();
coffeeCalendar = new com.toedter.calendar.JCalendar();
coffeeTimesAnswer2 = new javax.swing.JTextField();
qntSemanal = new java.awt.Label();
jTextField1.setText("jTextField1");


private void coffeeTimesAnswerKeyPressed(java.awt.event.KeyEvent evt)
//check if has only numbers on the field
if(evt.getKeyCode() == KeyEvent.VK_ENTER)
try

if(coffeeTimesAnswer.getText().length() != 0 )
try
int i = Integer.parseInt(coffeeTimesAnswer.getText());

coffeeTimesAnswer.setText("");
dailyCoffeeTimes.add(i);



///////////////////////////////////////////////////////////////
catch (NumberFormatException ex)
JOptionPane.showMessageDialog(null, "This field only accept numbers" ,"Info",JOptionPane.INFORMATION_MESSAGE);
coffeeTimesAnswer.grabFocus();// focus field
coffeeTimesAnswer.setText(""); //cleans field



catch(Exception e)









//gets the last day of the week and sum the points
public int getLastDayOfWeek()
Calendar coffeeCalendar = Calendar.getInstance();
int week = coffeeCalendar.get(Calendar.SUNDAY);
return week;


// sum the ArrayList elements (calculates the coffee quantity)
public void calculaPontos()
int sum = 0;
for (Iterator it = dailyCoffeeTimes.iterator(); it.hasNext();)
int k = (int) it.next();
sum = sum + k;
System.out.println(sum);









[ad_2]

لینک منبع