CNT 4714 - Fall 2013 - Code Examples


GUI Examples

Part 1:
  • Image files
  • Simple Addition GUI - page 6
  • Labeling GUI components - page 11
  • Driver program for above
  • Grid Layout Manager Example - page 22
  • TextFields and Nested Classes Example - page 29
  • Driver program for above
  • JButton Example - page 43
  • Driver program for above
  • JCheckBox Example - page 48
  • Driver program for above
  • JRadioButton Example - page 52
  • Driver program for above
  • JComboBox Example - page 56
  • Driver program for above
  • JList Example - page 61
  • Driver program for above
  • Multiple Selection List Example - page 63
  • Driver program for above

  • Part 2:
  • Tracking Mouse Movement Example - page 6
  • Driver program for above
  • Illustration of an Adapter Class - page 12
  • Driver program for above
  • JTextArea Example - page 15
  • Driver program for above
  • Border Layout Manager Example - page 19
  • Driver program for above
  • File Chooser Demo - page 26
  • Basic Window Pane for Web Browser - JEditorPane Example - page 34
  • Tool Bar Class for Web Browser - page 36
  • Simple Web Browser with history - page 39
  • Web Browser extended with favorites (JSplitPane example) - page 43
  • HTML file containing "favorite" URLs - (required for above)
  • Web Browser (multiple page version - JTabbedPane example) - page 47
  • Drag and Drop version of the Web Browser - page 54

  • MULTI-THREADED APPLICATIONS
  • Simple Thread Test Program - page 18
  • Example for Runnable Interface - page 21
  • Another simple thread example - page 30
  • Basic Clock - Utilizing Timer Class and Threads - page 33
  • Sleeping a Thread Until a Specified Time - page 37
  • More on Sleeping Threads - page 57
  • Driver class for above - page 59
  • Class for Prime Number Determination - page 62
  • Driver program for determining prime numbers - page 63
  • Steam Boiler Simulator (Driver class) - page 66
  • Threaded pressure gauge checking for above - page 67
  • PRODUCER/CONSUMER PROBLEM
  • Producer Class - page 88
  • Consumer Class - page 89
  • Buffer Interface - page 90
  • Unsynchronized Buffer Class - page 90
  • Producer/Consumer Driver Class - UNSYNCHRONIZED - page 91
  • Synchronized Buffer Class - page 95
  • Producer/Consumer Driver Class - SYNCHRONIZED - page 98


  • JAVA NETWORKING
  • Simple UDP Server (non-GUI) - page 44
  • Simple UDP Client (non-GUI) - page 46
  • Simple TCP Server (non-GUI) - page 53
  • Simple TCP Client (non-GUI) - page 55
  • GUI-based TCP Server - page 75
  • Driver class for GUI-based TCP Server - page 41
  • GUI-based TCP Client - page 76
  • Driver class for GUI-based TCP Client - page 42
  • HTML file for SiteSelector Applet - high-level networking API example - page 83
  • SiteSelector Applet for above - page 84
  • Note: Before the following will execute you will need to run keytool to set up a keystore and certificate for the SSL
    Also, these two classes are in package: securitystuff/jsse.
  • SSL Server Class - page 100
  • SSL Client Class - page 103

    A multi-threaded,networked client/server example
  • Multithreaded TicTacToe Server
  • Test Class for TicTacToe Server
  • Client side for client/server TicTacToe
  • Test Class for TicTacToe Client


  • JDBC
  • SQL script for creating the bike database used in many of the MySQL and JDBC Examples
  • Simple JDBC Example - page 20
  • DisplayBikes Application - page 27
  • ResultSetTableModel class - page 33
  • DisplayQueryResults Application - page 40
  • Displaying database information using PreparedStatement - page 52
  • JDBC RowSet example - page 62


  • SERVLETS
    Part 2: NOTE: All of these files are assumed to be part of a web application named "CNT4714".
  • index.html - "home page" for servlets
  • web.xml configuration file for CNT4714 webapp
  • User Friendly Welcome Servlet (welcome2) - HTML file
  • User Friendly Welcome Servlet - Java file
  • Welcome Servlet Using a Post Method (welcome3) - HTML file
  • Welcome Servlet Using a Post Method - Java file
  • Current Date/Time Servlet - Java file
  • ReDirection Servlet - HTML file
  • ReDirection Servlet - Java file
  • RepeatVisitor: Cookie Demonstration Servlet - HTML file
  • RepeatVisitor Servlet - Java file
  • CookieTest: Session and Persistent Cookie Demonstration Servlet - HTML file
  • CookieTest Servlet - Java file
  • CookieUtilities class is used by ClientAccessCounts class below - Java file
  • ClientAccessCounts Servlet - Java file (this one is not accessible from the index page - execute it directly with http://localhost:8080/CNT4714/cookieaccess)
  • ShowSession: Session Cookie Demonstration Servlet - HTML file
  • ShowSession Servlet - Java file
  • Part 3:

  • Servlet that returns an Excel spreadsheet - Java file
  • ImageContent: Servlet that returns both images and text - HTML file ***be sure to set the files properly for this to work!
  • ImageContent Servlet - Java file
  • Image of Eddy Merckx bike for ImageContent servlet
  • Image of Sprint Kart for ImageContent servlet
  • Color Survey MySQL Script
  • Color Survey (3-tier application) - HTML file
  • Survey Servlet - Java file


  • JSP
    Part 1:
  • clock2.jsp
  • welcome.jsp
  • ComputeLoan.html
  • ComputeLoan.jsp
  • Loan.java (required for ComputeLoan2.jsp)
  • ComputeLoan2.html
  • ComputeLoan2.jsp
  • include.jsp
  • banner.html
  • toc.html
  • clock2.jsp
  • forward1.jsp
  • forward2.jsp
  • Part 2:

    Be sure to set up the proper directory structure for the packages in these examples. See the notes for details.
  • picturerotator.jsp
  • Rotator JavaBean File
  • SQL Script to create guestbook database
  • GuestBean.java JavaBean File
  • GuestDataBean.java JavaBean File
  • guestBookLogin.jsp
  • guestBookView.jsp
  • guestBookErrorPage.jsp


  • PHP
    NOTE: All of these file should be loaded into your htdocs folder in your Apache server.

  • Images for use with the form.html application and others - (rename to "images" and locate in htdocs directory) - image1.jpg is the background image - put in htdocs
  • Basic php script with function call
  • Basic php script without function call
  • Displays PHP server variable values - change it around to display other superglobal values
  • Client side form
  • Server side php script for handling the form
  • Expression.php for regular expression test
  • Client side secure entry screen
  • Server side php script to handle password
  • Client side data entry for database query
  • Server side php script to handle database access (NOTE: rename with .php extension only)
  • Client side form to enter cookie values
  • Server side php script to handle the cookie
  • Server side php script to read cookie values
  • SQL script to create mailinglist DB
  • Client side database entry form
  • Server side php script to access database

  • Last updated: November 20, 2013
    Return to CNT 4714 home page