110 likes | 121 Views
Learn how to create an event calendar in Java by integrating features like JFrame, JButton, JTextComponent, iText for PDF generation, Calendar class for day calculations, and display customization using PDFContentByte.
E N D
Creating an Event Calendar with Java By Keith Lynn Field Trip #29
JFrame • A JFrame is a top-level container • It can run in a stand alone program • It can contain independent panels • The JFrame has a title
JButton • A JButton is a component that we can place on a JFrame • It is a push button • We can place a label in the button • A JButton has a margin. If the label won't display, we can obtain the insets of the button and change the margin
JTextComponent • In order to get input from the user, we will use a JtextField • A JtextField is a JtextComponent • It is a box on the screen • We can retrieve the text in a box with the method getText()
iText • We will use a third party library called iText • iText was written by Bruno Lowagie • It allows us to directly create PDF documents • We begin with creating a Document object and then a PdfWriter • The PdfWriter is created using the Document and a FileOutputStream attached to a file • After we have completed the document, we need to save it
PdfContentByte • There are many things we can place in a PDF document • One way of adding content is to draw directly on it • In order to do this, we obtain the PdfContentByte of the document • We use the method getDirectContent on the PdfWriter
Finding Days of Month • We make use of the Calendar class • The Calendar class is found in the java.util package • When we create a Calendar object, we will set the year, month, and day of the month the user specified • Then using the field DAY_OF_WEEK, we can determine where the current day falls • We can then fill in the numbers of the month
Drawing a Grid • In order to draw the grid on the screen, we will use the PdfContentByte • To create a line on the screen, we move to a certain location with the moveTo method • Then we move to another location with the lineTo method • After we have moved to all the locations, we call the method stroke • Repeating this, we can draw a rectangle
Displaying Event • We will make use of arrays in this app • An array is a collection of elements of the same type • The array we will create will contain objects that contain information about the current day of the week • In particular, we will include whatever event the user entered
Displaying the Month • After we have created the object representing the days of the week and the events, we use the method setTextMatrix to hold text • We can change the font • We can change the color • We can change the font using a BaseFont • We can change the color using a BaseColor • After the events are displayed, we can save the document