import java.applet.*; import java.awt.*; import java.awt.image.MemoryImageSource; public class rigid_rotor extends Applet implements Runnable { Thread m_rigid_rotor = null; public boolean running = false; private Font font; private Font titleFont; private FontMetrics fm; private FontMetrics titleFm; private Graphics Fig1Graphics; private Image Fig1; private Graphics Fig2Graphics; private Image Fig2; private Image Atom_A; private atom1 atom_A = new atom1(); private Image Atom_B; private atom1 atom_B = new atom1(); private Image Reduced_Mol; private atom1 reduced_Mol = new atom1(); private atom1 label_Pos = new atom1(); // Parameter names. To change a name of a parameter, you need only make // a single change. Simply modify the value of the parameter string below. //-------------------------------------------------------------------------- private final String PARAM_ProfPass = "ProfPass"; public rigid_rotor() { } public String getAppletInfo() { return "Name: rigid_rotor\r\n" + "Author: Dr. P. Bird\r\n" + "Copyright, September 1997\r\n" + "Created with Microsoft Visual J++ Version 1.0"; } public void init() { resize(550, 250); font = new Font("Courier",Font.BOLD,14); titleFont = new Font("TimesRoman",Font.BOLD,16); titleFm = getFontMetrics(titleFont); setFont(titleFont); setBackground(Color.white); setForeground(Color.black); Fig1 = createImage(250,200); //Create off screen images Fig1Graphics = Fig1.getGraphics(); Fig2 = createImage(250,200); //Create off screen images Fig2Graphics = Fig2.getGraphics(); MediaTracker tracker = new MediaTracker(this); //Get .gifs Atom_A = getImage(getDocumentBase(), "Atom_A.gif"); tracker.addImage(Atom_A,1); Atom_B = getImage(getDocumentBase(), "Atom_B.gif"); tracker.addImage(Atom_B,2); Reduced_Mol = getImage(getDocumentBase(), "Reduced_Mol.gif"); tracker.addImage(Reduced_Mol,3); try { tracker.waitForAll(); if (tracker.isErrorAny()) { showStatus("Error loading the images"); stop(); } } catch(InterruptedException e) { showStatus("InterruptedException (Tracker)"); stop(); } atom_A.pathRadius = 30.0; atom_B.pathRadius = 50.0; reduced_Mol.pathRadius = 80.0; label_Pos.pathRadius = 40; } public void destroy() { } public void paint() { } public synchronized void update(Graphics g) { if (!running) { // g.setColor(Color.white); // g.fillRect(0,0,550,250); // g.setColor(Color.black); } g.drawImage(Fig1,0,0,null); g.drawImage(Fig2,275,0,null); g.setColor(Color.black); g.drawString("Figure 1.",100,245); g.drawString("Figure 2.",370,245); } public void start() { if (m_rigid_rotor == null) { m_rigid_rotor = new Thread(this); m_rigid_rotor.start(); } } public void stop() { if (m_rigid_rotor != null) { m_rigid_rotor.stop(); m_rigid_rotor = null; } } public void run() { double angle = 0.0; running = false; repaint(); running = true; Fig1Graphics.setFont(font); Fig2Graphics.setFont(font); while (true) { try { Fig1Graphics.setColor(Color.white); Fig1Graphics.clearRect(0,0,250,200); atom_A.atomPosition(angle); atom_B.atomPosition(angle+180.0); label_Pos.atomPosition(angle+180); Fig1Graphics.setColor(Color.red); Fig1Graphics.drawLine (atom_A.xpos+125,atom_A.ypos+100,atom_B.xpos+125,atom_B.ypos+100); Fig1Graphics.setColor(Color.black); Fig1Graphics.drawImage(Atom_A,atom_A.xpos+125-10,atom_A.ypos+100-10,null); Fig1Graphics.drawImage(Atom_B,atom_B.xpos+125-10,atom_B.ypos+100-10,null); // Fig1Graphics.fillOval(123,123,5,5); Fig1Graphics.drawString("m",atom_A.xpos+125-15,atom_A.ypos+100+15); Fig1Graphics.drawString("1",atom_A.xpos+125-5,atom_A.ypos+100+20); Fig1Graphics.drawString("m",atom_B.xpos+125-15,atom_B.ypos+100+15); Fig1Graphics.drawString("2",atom_B.xpos+125-5,atom_B.ypos+100+20); Fig1Graphics.drawString("r",123,102); Fig2Graphics.setColor(Color.white); Fig2Graphics.clearRect(0,0,250,200); reduced_Mol.atomPosition(angle+180.0); Fig2Graphics.setColor(Color.red); Fig2Graphics.drawLine (reduced_Mol.xpos+125,reduced_Mol.ypos+100,125,100); Fig2Graphics.setColor(Color.black); Fig2Graphics.drawImage(Reduced_Mol,reduced_Mol.xpos+125-10,reduced_Mol.ypos+100-10,null); // Fig2Graphics.fillOval(123,123,5,5); Fig2Graphics.drawString("M",reduced_Mol.xpos+125+10,reduced_Mol.ypos+100-10); Fig2Graphics.drawString("r",label_Pos.xpos+123,label_Pos.ypos+102); angle = angle + 2.0; if (angle >= 360.0) angle = 0.0; repaint(); Thread.sleep(60); // repaint(275,0,250,200); } catch (InterruptedException e) { stop(); } } } public boolean mouseDown(Event evt, int x, int y) { return true; } public boolean mouseUp(Event evt, int x, int y) { return true; } }