| |||||||||||
| |||||||||||
lapwing.java
Archived examples from previous versions of courses example from a Well House Consultants training course
More on Archived examples from previous versions of courses [link]
Source code: lapwing.java Module: J610
--- ARCHIVED EXAMPLE (may not be current) ---
--- See notes at http://www.wellho.net/mouth/2654.html --- import java.applet.*; import java.awt.*; import java.util.*; import java.lang.*; public class lapwing extends Applet implements Runnable{ Graphics g,goff; Image offscreen; Dimension app_size; Thread timer; boolean infocus; int clock_size; int yinset; int xinset; boolean pendulum; int swinger = 0; public void init() { g = this.getGraphics(); app_size = this.size(); offscreen = this.createImage(app_size.width,app_size.height); goff = offscreen.getGraphics(); clear(); clock_size = app_size.width-20; xinset = 10; yinset = app_size.height - 10 - clock_size; if (app_size.width > app_size.height) { clock_size = app_size.height-20; yinset = 10; xinset = (app_size.width - clock_size ) / 2; } pendulum = (app_size.width * 2 <= app_size.height); } public void start() { if (timer == null) { infocus = true; timer = new Thread(this); timer.start(); } } public void run() { long intval = 1000; if (pendulum) intval = 100; while (infocus) { paint(g); try { Thread.sleep(intval); } catch (Exception e) {;} } timer = null; } public void stop() { infocus = false; } public boolean mouseDown(Event e, int x, int y) { if (timer == null) {start();} else {infocus = false;} return true; } public void paint(Graphics gsc){ shape(); gsc.drawImage(offscreen,0,0,this); } /** Respond to key presses */ public boolean keyDown(Event e, int key) { if ((e.id == Event.KEY_PRESS) && (key == 'c')) { clear(); return true; } else return false; } public void update(Graphics g) {paint(g);} public void clear() { goff.setColor(Color.black); goff.fillRect(0, 0, bounds().width, bounds().height); } void shape() { clear(); Date clock = new Date(); int hours = clock.getHours()%12; int minutes = clock.getMinutes(); int seconds = clock.getSeconds(); if (pendulum) { swinger++; double a2 = 0.1* ((double) swinger); double pangle = 270.0 + 20 * Math.cos(a2); goff.setColor(Color.white); setpoly(3.0,0.5,pangle); } goff.setColor(Color.darkGray); goff.fillOval(xinset,10,clock_size,clock_size); goff.setColor(Color.yellow); setpoly(1.0,0.5,90-seconds*6); goff.setColor(Color.cyan); setpoly(0.8,1.0,90-minutes*6); goff.setColor(Color.orange); setpoly(0.5,2.0,90-hours*30-minutes/2); } void setpoly(double out, double wide, int angle){ setpoly(out, wide, (double) angle);} void setpoly(double out, double wide, double angle){ double real_ang = angle /57.295779; double co = Math.cos(real_ang); double si = Math.sin(real_ang); double scale = (((double) clock_size ) * 0.5); double scale2 = scale * 0.03 * wide; double xc = (double) xinset + clock_size / 2; double yc = (double) 10 + clock_size / 2; int [] xpol = new int [4]; int [] ypol = new int [4]; int np; xpol[1]= (int) (xc + scale2 * si); ypol[1]= (int) (yc + scale2 * co); xpol[2]= (int) (xc - scale2 * si); ypol[2]= (int) (yc - scale2 * co); if (out > 1.0) { xpol[0]= (int) (xc + out*scale * co + scale2 * si); ypol[0]= (int) (yc - out*scale * si + scale2 * co); xpol[3]= (int) (xc + out*scale * co - scale2 * si); ypol[3]= (int) (yc - out*scale * si - scale2 * co); np = 4; } else { xpol[0]= (int) (xc + out*scale * co); ypol[0]= (int) (yc - out*scale * si); np = 3; } goff.fillPolygon(xpol,ypol,np); } } Learn about this subject
This module and example are covered on our public Java Extra course. If you have a group of
three or more trainees who need to learn the subject, we can also arrange a
private or on site course for you.
Books covering this topic
Yes. We have over 700 books in our library. Books
covering Java and associated technologies are listed here and when you've selected a
relevant book we'll link you on to Amazon to order.
Other Examples
This example comes from our "Archived examples from previous versions of courses" training module. You'll find a description of the topic and some
other closely related examples on the "Archived examples from previous versions of courses" module index page.
Full description of the source code
You can learn more about this example on the training courses listed on this page,
on which you'll be given a full set of training notes.
Many other training modules are available for download (for limited use) from our download centre under an Open Training Notes License. Other resources
• Our Solutions centre provides a number of longer technical articles.
• Our Opentalk forum archive provides a question and answer centre. • The Horse's mouth provides a daily tip or thought. • Further resources are available via the resources centre. • All of these resources can be searched through through our search engine • And there's a global index here. Purpose of this website
This is a sample program, class demonstration or answer from a
training course. It's main purpose
is to provide an after-course service to customers who have attended our
public private or
on site courses, but the examples are made
generally available under conditions described below.
Web site author
Conditions of use
Past attendees on our training courses are welcome to use individual
examples in the course of their programming, but must check
the examples they use to ensure that they are suitable for their
job. Remember that some of our examples show you how not to do
things - check in your notes. Well House Consultants take no responsibility
for the suitability of these example programs to customer's needs.
This program is copyright Well House Consultants Ltd. You are forbidden from using it for running your own training courses without our prior written permission. See our page on courseware provision for more details. Any of our images within this code may NOT be reused on a public URL without our prior permission. For Bona Fide personal use, we will often grant you permission provided that you provide a link back. Commercial use on a website will incur a license fee for each image used - details on request. |
| ||||||||||
PH: 01144 1225 708225 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho PAGE: http://www.wellho.net/resources/ex.php4 • PAGE BUILT: Sun Oct 11 14:50:09 2020 • BUILD SYSTEM: JelliaJamb |