Chris Pollett>Old Classes>PIC 20, Winter 2000>Practice Final
The final cover from Chapter 9 page 427 on interfaces through Chapter 16 on animation (page 794). You are not respsonsible for Chapter 10 on Strings, nor are you responsible for pages 661--687 in Chapter 13.
1* 2* 3* 4*Explain how the Jarvis' Gift-Wrapping algorithm would compute the convex hull of this figure.
ANS: In preemptive threading if a thread of higher priority than the currently running thread becomes ready then the scheduler will preempt the currently running thread and execute the thread of higher priority. In time-slicing, each ready thread gets a slice out of some fixed amount of time in which the scheduler will let it run. This slice of time is larger for threads of higher priority. A monitor is part of the scheduling program that ensures that only one thread can execute a synchronized method at a time. To make a class that uses threads without extending threads one can use the Runnable interface. i.e., class MyClass extends SomeOtherClass implements Runnable { public MyClass() { Thread t = new Thread(this); } public void run() { //whatever want in run method } }
In the init method of an applet one could call AudioClip au = getAudioClip( getDocumentBase(),"filename"); For a application in its constructor you could do: try{ AudioClip au = Applet.newAudioClip(new URL( "http://whatever")); } catch (MalformedURLException e) { // handle it } The syntax for loading a .jpg (in same directory as application) on a not as yet constructed ImageIcon is: ImageIcon im = new ImageIcon("filename.jpg");
ANS: public class MyApplet extends JApplet { String abc[] = "abcdefghijklmnopqrstuvwxyz"; int i=0; Container c; public void init() { c= getContentPane(); Timer t = new Timer(500, new ActionListener(){ public void actionPerformed(ActionEvent e) { i = (i+1)%26; c.repaint(); } }); } public void paint(Graphics g) { g.drawString(""+abc.charAt(i), 10,10); } }