change JFrame to JDialog; move code to function totalAmount