Total members 10261 | Gratitudes |It is currently Tue May 22, 2012 4:56 pm Login / Join Codemiles


All times are UTC [ DST ]




Post new topic Reply to topic  Quick reply  [ 1 post ] 
Author Code Snippet
 Code subject: draw Calendar in java
PostPosted: Tue Nov 11, 2008 7:46 pm 
Offline
Mastermind
User avatar

Joined: Tue Mar 27, 2007 10:55 pm
Posts: 2279
Location: Earth
Has thanked: 39 time
Have thanks: 61 time

draw Calendar in java
Code:
import java.awt.*;
import javax.swing.*;
import java.util.Calendar;
import java.text.DecimalFormat;

public class CalendarIconExample extends JComponent {
  int SIZE = 60;
  Dimension dim = new Dimension(SIZE, SIZE);
  int nx, ny, width = 38, height = 38;
  Calendar cal;
  Font dateFont, dayFont, monthFont;
  FontMetrics date, day, month ;
  boolean showTime = true;
  String[] days ={"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
  String[] months={"JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL",
      "AUG", "SEP", "OCT", "NOV", "DEC", };

  public CalendarIconExample(boolean show) {
    this(Calendar.getInstance(), show);
  }
  public CalendarIconExample(Calendar c, boolean show) {
    super();
    cal = c;
    ny = 5;
    nx = 10;
    dateFont = new Font("Serif", Font.BOLD, 18);
    date = getFontMetrics(dateFont);
    dayFont = new Font("Book Antiqua", Font.BOLD, 10);
    day = getFontMetrics(dayFont);
    monthFont = new Font("Book Antiqua", Font.BOLD, 10);
    month = getFontMetrics(monthFont);
  }
  public void paint(Graphics graphics) {
   paintIcon(this, graphics, 0, 0);
  }
  public void paintIcon(Component component, Graphics g,
       int x, int y) {
    g.drawRect(x, y, dim.width - 2, dim.height - 2);
    g.setColor(Color.gray);
    g.fillRect(x + nx + 3, y + ny + 3, width, height);
    g.setColor(Color.white);
    g.fillRect(x + nx, y + ny, width, height);
  g.setColor(Color.black);
  if (showTime)
     super.paint(g);
 
    String st = days[cal.get(Calendar.DAY_OF_WEEK) - 1];
    g.setFont(dayFont);
  g.setColor(Color.red);
    int w = day.stringWidth(st);
    g.drawString(st, x + nx + ((width - w) / 2), y + ny + 10);

    st = Integer.toString(cal.get(Calendar.DAY_OF_MONTH));
    g.setFont(dateFont);
  g.setColor(Color.black);
    w = date.stringWidth(st);
    g.drawString(st, x + nx + ((width - w) / 2), y + ny + 25);

    st = months[cal.get(Calendar.MONTH)];
    g.setFont(monthFont);
  g.setColor(Color.red);
    w = month.stringWidth(st);
    g.drawString(st, x + nx + ((width - w) / 2), y + ny + 35);
}
   public static void main(String[] args) {
    JFrame frame = new JFrame("Calendar");
    Container container= frame.getContentPane();
    CalendarIconExample iconExample = new CalendarIconExample(true);
    container.add(iconExample);
    frame.setSize(100, 100);
    frame.show();
  }
}


Attachments:
File comment: calender icon
calendarIcon.gif
calendarIcon.gif [ 1.95 KiB | Viewed 3790 times ]

_________________
Currenlty programming with : java , html , php , and javascript . (OCJP-6 certified )
TOP
 Profile Send private message  
Reply with quote  
Post new topic Reply to topic Quick reply  [ 1 post ] 
Quick reply


  

 Similar topics
 video chat application in java
 navigating to database using java
 java mobile apps
 need help in java
 Read your gmail using Java code
 Java Programing to communicating port parallel
 Java Chat
 Steganography in java
 java code for listing folder contents from remote folder
 java

All times are UTC [ DST ]


Users browsing similar codes

Users browsing this forum: No registered users and 1 guest



Jump to:  
Previous Code Snippet | Next Code Snippet 




Home
General Talks
Finished Projects
Code Library
Games
Tutorials

Java
C/C++
C-sharp
php
Script
JSP/Servlets
Ajax
ASP/ASP.net
Google SEO
Database
Communications
Phpbb3 styles
Photoshop tutorials
Flash tutorials
Find a job






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team