/** * @file RotateDialog.java * @author Robert S. Laramee * @version 1.0 * @see AutoRotate.java, NameDialog.java * start date Thursday 03 Dec 98 * "finish date" Thursday 03 Dec 98 *

* description This is the class that pops up the dialog box when the user * uses the AutoRotate menu. It is used to adjust the rotation * speed * modified on Thursday 10 Dec 1998 * Dialog --> JDialog * Panel --> JPanel * Label --> JLabel */ import java.awt.*; import java.awt.event.*; import javax.swing.*; class JRotateDialog extends JDialog implements AdjustmentListener { private JLabel rotateLabel; // rotate label private JScrollBar rotate; // rotate scrollbar private DrawCanvas canvas; // a reference to the drawing canvas public JRotateDialog(JFrame frame, DrawCanvas dc) { super(frame, "AutoRotate Dialog", false); canvas = dc; /** * Create Scrollbars * page 400 of Core Java */ JPanel p = new JPanel(); p.setLayout(new GridLayout(1, 2)); p.add(rotateLabel = new JLabel("rotate : 5 revolutions/minute")); p.add(rotate = new JScrollBar(JScrollBar.HORIZONTAL, 10, 0, 0, 60)); rotate.setBlockIncrement(1); rotate.addAdjustmentListener(this); getContentPane().add(p, "Center"); setSize(500, 50); // width, height /** * bob tries to place the window in a good location */ Toolkit toolkit = Toolkit.getDefaultToolkit(); Dimension dimension = toolkit.getScreenSize(); int screenHeight = dimension.height; int screenWidth = dimension.width; setLocation(screenWidth/2, screenHeight/7); } public void adjustmentValueChanged(AdjustmentEvent evt) { if (evt.getSource() == rotate) { rotateLabel.setText("rotate: " + ((rotate.getValue()+2)/2) + " revolutions/minute"); Graphics g = canvas.getGraphics(); canvas.setSleepTime(60-rotate.getValue()); } } }