Link to Computing Science and Mathematics home page Link to University of Stirling home page
Go back Go back CSC932 home CSC932 home

CSC932/CSCM32: Programming and User Accessibility
Java examples

Most of these come from "Java for Students" by Bell & Parr, 5th edition, indicated by "B&P". Extensions and extras by Simon Jones. They are roughly in the order that the Java concepts are dealt with in the book and the lectures. Source code and runnable versions are both provided.

In order to run the examples you will need a recent Java installation - at least Java 1.5.0. You can obtain a Java installation kit from here - you will need at least the Java Runtime Environment (JRE), and the full Java Development Kit (JDK) instead if you wish to develop your own Java programs.

  • Hello: Displays a simple greeting in a pop up box (B&P)
  • Greeting: Displays a simple greeting in a text field (B&P)
  • DrawExample: Draws a single line when a button is pressed (B&P)
  • SomeShapes: Displays several graphical shapes on the screen (B&P)
  • AreaCalculation: Displays the result of a simple calculation in a dialogue box (B&P)
  • AreaDialogs: Uses dialogue boxes to prompt for the input of a length and a width, and then displays the result of the area calculation in a dialogue box (B&P)
  • LogoMethod: Displays two simple logos on the screen, using a method (B&P)
  • TriangleMethod: Displays two simple logos and two triangles on the screen, using methods (B&P)
  • HouseDemo: Displays two simple lean-to houses on the screen, using methods (B&P)
  • AreaMethod: Displays the result of a simple calculation in a dialogue box, but using a non-void method (B&P)
  • CarCounter: Increments a counter each time a button is pressed, and displays the result in a dialogue box (B&P)
  • CarCounter2: Increments a counter each time a button is pressed, and displays the result in a text field (SBJ)
  • CarCounter3: Increments a counter each time a button is pressed, and displays the result in a graphics panel - but without clearing the panel first (SBJ)
  • CarCounter3b: Increments a counter each time a button is pressed, and displays the result in a graphics panel - but properly clearing the panel first (SBJ)
  • SimpleSlider: The value selected by a simple slider is displayed in a text field (SBJ)
  • WindowBlind: Displays a window with blind adjustable by a slider (B&P/SBJ)
  • Safe: Only unlock the safe if the correct number is entered (B&P)
  • Voting: Tell user whether they can vote or not, based on their age (B&P)
  • SimpleShopSign: Control a shop sign: Open/Closed (B&P/SBJ)
  • ShopSign: Control a shop sign: On/Off/Open/Closed (B&P)
  • DiceTotal: Display two sliders and total of dice (SBJ)
  • QuickBlind: The WindowBlind example with quick "Open" and "Close" buttons (SBJ)
  • SwitchDay: Displays messages describing the day selected by a slider (B&P/SBJ)
  • TenBoxes: Draws ten boxes (B&P/SBJ)
  • Boxes: Draws boxes - number selected by a slider (B&P/SBJ)
  • Squares (interactive): Displays the squares of numbers entered by the user until a -ve is entered (SBJ)
  • Squares: Displays square numbers, up to a limit entered in a text box (B&P/SBJ)
  • BoxesFor: Draws boxes using a for loop (SBJ)
  • SumUp: Displays the sum of integers in a range (SBJ)
  • Drunk: Displays a random drunken walk (B&P/SBJ)
  • Lottery: Displays two random lottery numbers (B&P)
  • Apartments: Draws an apartment block (B&P)
  • ApartmentsSlow: Draws an apartment block slowly (B&P/SBJ)
  • Band: Displays the names of the Beatles (from an array) (SBJ)
  • Rainfall: Manages a table of rainfalls for a week (B&P/SBJ)
  • JumpingWorld: Message moves with mouse clicks (SBJ)
  • OvenGuide: Shows temperature zones (SBJ)
  • Censor: A simple text censoring application (SBJ)
  • ExceptionDemo1: A simple demonstration of unhandled exceptions (SBJ)
  • ExceptionDemo2: The same, but with the exceptions handled using try/catch (SBJ)
  • AreaDialogsSafe: Like the AreaDialogs example, but catches NumberFormatExceptions due to faulty data entered, and gives sensible warnings, repeating the inputs until valid data is entered. (SBJ)
  • Database: A simple database for one student - naive version (SBJ)
  • Database: A simple database for one student - object oriented version (SBJ)
  • UseBalloon:Displays a balloon and allows size adjustment - uses an extra Balloon class (B&P)
  • QuickBlind: but doing screen refreshes properly (SBJ)
  • SimpleGardenDesign: Add trees with mouse clicks (SBJ)
  • GardenDesign: More advanced garden design: Add and delete trees with mouse clicks (SBJ) (also has more interesting internal workings: a TreeList class, an enum type, Graphics2D antialiasing for smoother drawing)

(Old applet based examples can be found here)


Go back Go back CSC932 home CSC932 home

If you have any difficulties accessing this page, or you have any queries/suggestions arising from this page, please email:

Link to Computing Science and Mathematics home page
© University of Stirling 2017           Last updated: Thursday, 18-Mar-2010 22:41:01 GMT
The University of Stirling is a charity registered in Scotland, number SCO11159