FileDocCategorySizeDatePackage
DateBean.javaAPI DocExample5022Sat Sep 12 03:01:00 BST 1998borland.samples.beans.customizer

DateBean

public class DateBean extends JLabel

Fields Summary
private Calendar
c
private int
m
private int
d
private int
y
private int
e
private String
month
private String
day
private String
year
private String
era
private String
month_str
private boolean
useMonthString
private Color
fontColor
private int
style
static final int
MONTH_DAY_YEAR
static final int
MONTH_DAY_YEAR_ERA
static final int
YEAR_MONTH_DAY
static final int
MONTH_YEAR
static final int
DAY_MONTH_YEAR
static final String[]
allMonths
Constructors Summary
public DateBean()


    
      m = c.get(Calendar.MONTH) + 1;
      d = c.get(Calendar.DATE);
      y = c.get(Calendar.YEAR);
      e = c.get(Calendar.ERA);

      if(m <= 9)
        month = "0" + String.valueOf(m);
      else
        month = String.valueOf(m);

      if(d <=9)
        day = "0" + String.valueOf(d);
      else
        day = String.valueOf(d);

      year = String.valueOf(y);
      month_str = allMonths[m - 1];

      // AD or BC -- it might matter when Java builds time machines!
      if(e == 1)
        era = "AD";
      else
        era = "BC";

      setStyle(MONTH_DAY_YEAR_ERA);
      useMonthString = false;
  
Methods Summary
public java.awt.ColorgetBackground()

      return super.getBackground();
  
public java.awt.FontgetFont()

      return super.getFont();
  
public java.awt.ColorgetFontColor()

      return super.getForeground();
  
public intgetStyle()

      return style;
  
public booleangetUseMonthString()

    return useMonthString;
  
public voidsetBackground(java.awt.Color newBackground)

    super.setBackground(newBackground);
  
public voidsetFont(java.awt.Font newFont)

    super.setFont(newFont);
  
public voidsetFontColor(java.awt.Color newFontColor)

    super.setForeground(newFontColor);
  
public voidsetStyle(int newStyle)

    style = newStyle;

    switch(style){
      case MONTH_DAY_YEAR:
        if(useMonthString)
          this.setText(month_str + " " + day + ", " + year);
        else
          this.setText(month + " / " + day + " / " + year);
        break;

      case MONTH_DAY_YEAR_ERA:
        if(useMonthString)
          this.setText(month_str + " " + day + ", " + year + " " + era);
        else
          this.setText(month + " / " + day + " / " + year + " " + era);
        break;

      case YEAR_MONTH_DAY:
        if(useMonthString)
          this.setText(year + " " + month_str + " " + day);
        else
          this.setText(year + " / " + month + " / " + day);
        break;

      case MONTH_YEAR:
        if(useMonthString)
          this.setText(month_str + " " + year);
        else
          this.setText(month + " " + year);
        break;

      case DAY_MONTH_YEAR:
        if(useMonthString)
          this.setText(day + " " + month_str + " " + year);
        else
          this.setText(day + " / " + month + " / " + year);
        break;

      default:
        this.setText("invalid");
    }
  
public voidsetUseMonthString(boolean x)

    useMonthString = x;
    this.setStyle(this.getStyle());