カレンダーから選んだ日付に基づいてラベルを表示しようとしています。開始日と終了日はデータベースから取得され、それらの間の日付は計算されています..すべて正常に機能しています..しかし、カレンダーの日付ピッキングで間隔が等しいかどうかを確認しても、可視性が得られません..助けてください..これが私のものですコード
package javaapplication91;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class JavaApplication91 implements MouseListener {
static String driverName = "org.firebirdsql.jdbc.FBDriver";
String url = "jdbc:firebirdsql://localhost:3050/C:\\DOCTORSMASTERTABLE.GDB";
String userName = "SYSDBA";
String password = "masterkey";
Connection connect;
ResultSet rs;
Statement st;
String qry,ran;
List<Date> dates = new ArrayList<>();
DateFormat formatter;
JTextField[][] lb = new JTextField[1000][500];
JFrame prnt = new JFrame();
JPanel p = new JPanel(new FlowLayout(FlowLayout.CENTER,10,10));
JPanel p1 = new JPanel(new FlowLayout(FlowLayout.CENTER,10,10));
JLabel l = new JLabel();
int in,i,k;
public JavaApplication91() throws IOException {
prnt.setLayout(new BorderLayout());
p1.setPreferredSize(new Dimension(200, 200));
p1.setBackground(Color.red);
l.setPreferredSize(new Dimension(100, 100));
l.setBackground(Color.black);
l.setText("clik");
l.addMouseListener(this);
p1.add(l);
}
public void ctr() throws ParseException, SQLException {
connect = DriverManager.getConnection(url, userName, password);
st = connect.createStatement();
qry="SELECT \"AVAIL FROM_DATE\",\"AVAIL TO_DATE\",D_NAME FROM DOCTOR_DETAILS;";
rs = st.executeQuery(qry);
prnt.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
formatter = new SimpleDateFormat("dd/MM/yyyy");
in = 0;
java.sql.Date ran;
java.sql.Date ran1;
while(rs.next()){
ran = rs.getDate(1);
ran1 = rs.getDate(2);
String name = rs.getString(3);
long interval = 24 * 1000 * 60 * 60;
long endTime = ran1.getTime();
long curTime = ran.getTime();
while (curTime <= endTime) {
dates.add(new Date(curTime));
curTime += interval;
}
for (i = 0; i < dates.size(); i++) {
Date lDate = (Date) dates.get(i);
String ds = formatter.format(lDate);
lb[in][i] = new JTextField();
lb[in][i].setText(""+ds);
lb[in][i].setPreferredSize(new Dimension(100,30));
p.add(lb[in][i]);
//lb[i].setVisible(false);
System.out.println(" Date is ..." + ds);
}
dates.clear();
in++;
}prnt.add(p,BorderLayout.CENTER);
prnt.add(p1,BorderLayout.EAST);
prnt.pack();
prnt.setVisible(true);
}
public static void main(String[] args) throws ParseException, IOException, SQLException {
new JavaApplication91().ctr();
}
@Override
public void mouseClicked(MouseEvent e) {
if(e.getComponent() == l){
JavaApplication89 d = new JavaApplication89(prnt);
l.setText(d.setPickedDate());
for(int k = 0; k < in;k++){
for(int m = 0; m<i ; m++){
if(lb[k][m] != null){
if(lb[k][m].getText().equals(d.setPickedDate())){
dates.clear();
lb[k][m].setVisible(true);
}else{
lb[k][m].hide();
}
}
}
}
}
}
@Override
public void mousePressed(MouseEvent e) {
}
@Override
public void mouseReleased(MouseEvent e) {
//To change body of generated methods, choose Tools | Templates.
}
@Override
public void (mouseEntered(MouseEvent e) {
//To change body of generated methods, choose Tools | Templates.
}
@Override
public void mouseExited(MouseEvent e) {
//To change body of generated methods, choose Tools | Templates.
}
}
問題は条件の場合にマウスをクリックすることです
setPickDate を提供するクラスは
package javaapplication91;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Random;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class JavaApplication89 {
JLabel l1;
int month = java.util.Calendar.getInstance().get(java.util.Calendar.MONTH);
int year = java.util.Calendar.getInstance().get(java.util.Calendar.YEAR);
//JLabel l = new JLabel("",JLabel.CENTER) ;
String day = "";
JDialog d;
JButton[] button = new JButton[49];
Random rm = new Random();
public JavaApplication89(JFrame parent) {
d = new JDialog();
d.setModal(true);
System.out.println("mnth " + month);
l1 = new JLabel();
l1.setText("Year : "+String.valueOf(year)+" Month:"+String.valueOf(month) );
l1.setPreferredSize(new Dimension(50, 50));
String[] header = { "Sun", "Mon", "Tue", "Wed", "Thur", "Fri", "Sat" };
final JPanel p1 = new JPanel(new GridLayout(7, 7));
p1.setPreferredSize(new Dimension(700, 500));
for (int x = 0; x < button.length; x++) {
final int selection = x;
button[x] = new JButton();
button[x].setFocusPainted(false);
button[x].setBackground(Color.white);
if (x > 6)
button[x].addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent ae) {
day = button[selection].getActionCommand();
d.dispose();
}
});
if (x < 7) {
button[x].setText(header[x]);
button[x].setForeground(Color.red);
}
d.add(l1,BorderLayout.NORTH);
p1.add(button[x]);
}
JPanel p2 = new JPanel(new GridLayout(10, 3));
JButton previous = new JButton("<< Previous");
previous.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent ae) {
month--;
displayDate();
l1.setText( "Year :" + year +" month : "+month);
}
});
p2.add(previous);
JButton next = new JButton("Next >>");
JButton raa = new JButton("Time Choose from here");
raa.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
e.getSource();
JFrame fm = new JFrame("time Picker");
fm.setPreferredSize(new Dimension(500, 500));
JLabel lb = new JLabel();
fm.add(lb, BorderLayout.CENTER);
fm.pack();
fm.setVisible(true);//To change body of generated methods, choose Tools | Templates.
}
});
next.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent ae) {
month++;
displayDate();
l1.setText( "Year :" + year +" month : "+month);
}
});
p2.add(next);
d.add(p1, BorderLayout.CENTER);
d.add(p2, BorderLayout.SOUTH);
d.pack();
d.setLocationRelativeTo(parent);
displayDate();
d.setVisible(true);
}
public void displayDate() {
for (int x = 7; x < button.length; x++)
button[x].setText("");
java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(
"mmm hhh");
java.util.Calendar cal = java.util.Calendar.getInstance();
cal.set(year, month, 1);
int dayOfWeek = cal.get(java.util.Calendar.DAY_OF_WEEK);
int daysInMonth = cal.getActualMaximum(java.util.Calendar.DAY_OF_MONTH);
for (int x = 6 + dayOfWeek, day = 1; day <= daysInMonth; x++, day++)
button[x].setText("" + day);
//l.setText(sdf.format(cal.getTime()));
d.setTitle("Date Picker");
}
public String setPickedDate() {
if (day.equals(""))
return day;
java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(
"dd/MM/yyyy");
java.util.Calendar cal = java.util.Calendar.getInstance();
cal.set(year, month, Integer.parseInt(day));
return sdf.format(cal.getTime());
}
public static void main(String[] args) {
JLabel label = new JLabel("Selected Date:");
final JTextField text = new JTextField(20);
JButton b = new JButton("popup");
JPanel p = new JPanel();
p.add(label);
p.add(text);
p.add(b);
final JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.getContentPane().add(p);
f.pack();
f.setVisible(true);
b.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent ae) {
text.setText(new JavaApplication89(f).setPickedDate());
}
});
}
}