Olá estou tentando fazer algo realtivamente simples porém estou me confudindo...
Preciso chamar um metodo que crie 2 formatedtextfield para que o usuario insira 2 datas,inicial e final.
Após isso preciso pegar o valor dessas duas datas para gerar o relatorio,o problema está em criar está tela e em pegar os valores depois, preciso que o valor inserido seja dd/MM/yyyy e entre em um sql.date yyyy-MM-dd
Também quero fazer para que a data maxima seja o dia atual tanto para inicio e fim, também fazendo com que a data de inical não supere a final do contrario enviar mensagem de alerta
Pois bem eis o que tentei:JFormattedTextField dtInicio = new JFormattedTextField();
JFormattedTextField dtFim = new JFormattedTextField();
dtInicio.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.DateFormatter(new java.text.SimpleDateFormat("dd/MM/yyyy"))));
dtInicio.setToolTipText("Digite a data no formato DIA/MÊS/ANO exemplo: 01/02/2013 *01 Fevereiro de 2013*.");
dtFim.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.DateFormatter(new java.text.SimpleDateFormat("dd/MM/yyyy"))));
dtFim.setToolTipText("Digite a data no formato DIA/MÊS/ANO exemplo: 01/02/2013 *01 Fevereiro de 2013*.");
MaskFormatter format;
try {
format = new MaskFormatter("##/##/####");
format.install(dtInicio);
} catch (ParseException ex) {
Logger.getLogger(DadosPreventiva.class.getName()).log(Level.SEVERE, null, ex);
}
try {
format = new MaskFormatter("##/##/####");
format.install(dtFim);
} catch (ParseException ex) {
Logger.getLogger(DadosPreventiva.class.getName()).log(Level.SEVERE, null, ex);
}
// Date atual = new Date(System.currentTimeMillis());
// String dia = Integer.toString(atual.getDay());
// String mes = Integer.toString(atual.getMonth()+1);
// String ano = Integer.toString(atual.getYear()+1900);
// dtFim.setText(dia+mes+ano);
JPanel myPanel = new JPanel();
myPanel.add(new JLabel("Insira o periodo que deseja"));
myPanel.add(Box.createVerticalStrut(20));
myPanel.add(new JLabel("Inicio:"));
myPanel.add(dtInicio);
myPanel.add(Box.createHorizontalStrut(15)); // a spacer
myPanel.add(new JLabel("Fim:"));
myPanel.add(dtFim);
int result = JOptionPane.showConfirmDialog(null, myPanel,
"Periodo", JOptionPane.OK_CANCEL_OPTION);
if (result == JOptionPane.OK_OPTION) {
dtInicio.getText();
dtFim.getText();
SimpleDateFormat formato;
formato = new SimpleDateFormat("yyyy-MM-dd");
try {
java.sql.Date dataInicio = new java.sql.Date(formato.parse(dtInicio.getText()).getTime());
java.sql.Date dataFim = new java.sql.Date(formato.parse(dtFim.getText()).getTime());
} catch (ParseException ex) {
Logger.getLogger(GestorView.class.getName()).log(Level.SEVERE, null, ex);
}
}
ps: No Delphi eu fazia esse tipo de tarefa com um datetimepicker, no JAVA não teria algo semelhante? Sempre vejo pessoas usando o formatedtextfield para falar manipular datas...
Obrigado