Ejemplo n.º 1
0
    private void initButton() {
      int actionCommandId = 1;
      for (int i = 0; i < 6; i++) {
        for (int j = 0; j < 7; j++) {
          JButton numberButton = new JButton();
          numberButton.setBorder(BorderFactory.createEmptyBorder());
          numberButton.setHorizontalAlignment(SwingConstants.CENTER);
          numberButton.setActionCommand(String.valueOf(actionCommandId));

          numberButton.addMouseListener(this);

          numberButton.setBackground(palletTableColor);
          numberButton.setForeground(dateFontColor);
          numberButton.setText(String.valueOf(actionCommandId));
          numberButton.setPreferredSize(new Dimension(25, 25));
          daysButton[i][j] = numberButton;
          actionCommandId++;
        }
      }
    }
Ejemplo n.º 2
0
 public LogDateChooser(String label) {
   thisDialog = this;
   border = new EtchedBorder();
   setBorder(border);
   Font f = new Font("Helvetica", Font.PLAIN, 10);
   title = new JLabel(label);
   add(title);
   setLayout(new DateLayout());
   dfs = new DateFormatSymbols();
   months = dfs.getMonths();
   weekdays = dfs.getShortWeekdays();
   for (int i = 0; i < 7; i++) {
     days[i] = new JLabel(weekdays[i + 1]);
     days[i].setFont(f);
     add(days[i]);
   }
   gc = new GregorianCalendar();
   mDown = new JButton("<");
   mDown.setMargin(new Insets(0, 0, 0, 0));
   mDown.addActionListener(new MDownEar());
   mDown.setBorderPainted(false);
   mDown.setFont(f);
   mDown.setForeground(Color.BLUE);
   add(mDown);
   mUp = new JButton(">");
   mUp.setMargin(new Insets(0, 0, 0, 0));
   mUp.addActionListener(new MUpEar());
   mUp.setBorderPainted(false);
   mUp.setFont(f);
   mUp.setForeground(Color.BLUE);
   add(mUp);
   month = new JLabel(months[gc.get(Calendar.MONTH)]);
   month.setHorizontalAlignment(SwingConstants.CENTER);
   month.setFont(f);
   add(month);
   year = new JLabel(new Integer(gc.get(Calendar.YEAR)).toString());
   year.setFont(f);
   add(year);
   yDown = new JButton("<");
   yDown.setMargin(new Insets(0, 0, 0, 0));
   yDown.addActionListener(new YDownEar());
   yDown.setBorderPainted(false);
   yDown.setFont(f);
   yDown.setForeground(Color.BLUE);
   add(yDown);
   yUp = new JButton(">");
   yUp.setMargin(new Insets(0, 0, 0, 0));
   yUp.addActionListener(new YUpEar());
   yUp.setBorderPainted(false);
   yUp.setFont(f);
   yUp.setForeground(Color.BLUE);
   add(yUp);
   //    System.out.println(year.getText());
   NumberEar numberEar = new NumberEar();
   for (int i = 0; i < 31; i++) {
     number[i] = new JButton(new Integer(i + 1).toString());
     number[i].setMargin(new Insets(0, 0, 0, 0));
     number[i].addActionListener(numberEar);
     number[i].setBorderPainted(false);
     number[i].setContentAreaFilled(false);
     number[i].setFont(f);
     number[i].setForeground(Color.BLUE);
     add(number[i]);
   }
   number[0].setForeground(Color.CYAN);
 }
Ejemplo n.º 3
0
    private void flushWeekAndDayPanal(Calendar c) {
      //            c.set
      c.set(Calendar.DAY_OF_MONTH, 1);
      c.setFirstDayOfWeek(0);
      int firstdayofWeek = c.get(Calendar.DAY_OF_WEEK);
      int lastdayofWeek = c.getActualMaximum(Calendar.DAY_OF_MONTH);
      String colname[] = {"日", "一", "二", "三", "四", "五", "六"};
      int today = getNowCalendar().get(Calendar.DAY_OF_MONTH);
      // 璁剧疆鍥哄畾瀛椾綋锛屼互鍏嶈皟鐢ㄧ幆澧冩敼鍙樺奖鍝嶇晫闈㈢編瑙�
      dayPanel.setFont(new java.awt.Font("寰蒋闆呴粦", java.awt.Font.PLAIN, 12));
      dayPanel.setLayout(new GridBagLayout());
      dayPanel.setBackground(palletTableColor);

      JLabel cell;

      for (int i = 0; i < 7; i++) {
        cell = new JLabel(colname[i]);
        cell.setHorizontalAlignment(JLabel.CENTER);
        cell.setPreferredSize(new Dimension(25, 25));
        if (i == 0 || i == 6) {
          cell.setForeground(weekendFontColor);
        } else {
          cell.setForeground(weekFontColor);
        }
        dayPanel.add(
            cell,
            new GridBagConstraints(
                i,
                0,
                1,
                1,
                0.0,
                0.0,
                GridBagConstraints.CENTER,
                GridBagConstraints.NONE,
                new Insets(0, 0, 0, 0),
                0,
                0));
      }

      int actionCommandId = 1;
      for (int i = 0; i < 6; i++) {
        for (int j = 0; j < 7; j++) {

          JButton numberButton = daysButton[i][j];
          actionCommandId = Integer.parseInt(numberButton.getActionCommand());
          if (actionCommandId == today) {
            numberButton.setBackground(todayBtnColor);
          }
          if ((actionCommandId + firstdayofWeek - 2) % 7 == 6
              || (actionCommandId + firstdayofWeek - 2) % 7 == 0) {
            numberButton.setForeground(weekendFontColor);
          } else {
            numberButton.setForeground(dateFontColor);
          }
          if (actionCommandId <= lastdayofWeek) {
            int y = 0;
            if ((firstdayofWeek - 1) <= (j + firstdayofWeek - 1) % 7) {
              y = i + 1;
            } else {
              y = i + 2;
            }
            dayPanel.add(
                numberButton,
                new GridBagConstraints(
                    (j + firstdayofWeek - 1) % 7,
                    y,
                    1,
                    1,
                    0.0,
                    0.0,
                    GridBagConstraints.CENTER,
                    GridBagConstraints.NONE,
                    new Insets(0, 0, 0, 0),
                    0,
                    0));
          }
        }
      }
    }