我使用this帖子中的代码将jdatepicker放入我的简单程序中(下面只是jdatepicker所需的代码)。它有效,但我有两个问题:
def multiFunctionalPrinter
puts "How many times do you want to print?"
number = gets
puts "-------------------------------------------"
puts "What do you want to print?"
text = gets.chomp #chomping variable to format it for decision making
puts "-------------------------------------------"
puts "Do you want to print in different lines (Y or N)?"
answer = gets.chomp #chomping variable to format it for decision making
puts "-------------------------------------------"
puts "Do you want to add quotation marks (') (Y or N)?"
marks = gets.chomp #chomping variable to format it for decision making
if answer == "Y" && marks == "Y" # Different lines: ON , Quotation marks: ON
1.upto(number.to_i) {puts "'" + text.to_s + "'"}
elsif answer == "Y" && marks == "N" # Different lines: ON , Quotation marks: OFF
1.upto(number.to_i) {puts text.to_s}
elsif answer == "Y" && marks != "Y" || marks != "N" # Different lines: ON , Quotation marks: INVALID
puts "Answer '#{marks}' is invalid. Program is terminating."
elsif answer == "N" && marks == "Y" # Different lines: OFF , Quotation marks: ON
puts "Do you want to split what you print? (Y or N)"
answer2 = gets.chomp
if answer2 == "Y" # Split: ON
1.upto(number.to_i) {print "'" + text.to_s + "' "}
print "\n"
elsif answer2 == "N" # Split: OFF
1.upto(number.to_i) {print "'" + text.to_s + "'"}
else
puts "Answer '#{answer2}' is invalid. Program is terminating."
end
elsif answer == "N" && marks == "N" # Different lines: OFF , Quotation marks: OFF
puts "Do you want to split what you print? (Y or N)"
answer2 = gets.chomp
if answer2 == "Y" # Split: ON
1.upto(number.to_i) {print text.to_s + " "}
elsif answer2 == "N" # Split: OFF
1.upto(number.to_i) {print text.to_s}
else
puts "Answer '#{answer}' is invalid. Program is terminating."
end
else
puts "Answer '#{answer}' or '#{marks}' is invalid. Program is terminating."
end
puts "--------------------------------------------"
end
multiFunctionalPrinter
答案 0 :(得分:3)
如何将选定日期转换为字符串?
datePicker.getJFormattedTextField().getText();
如何在JDatePicker文本框中重置日期?
datePicker.getJFormattedTextField().setText("");