import java.lang.*; import java.awt.*; import javax.swing.*; import java.util.*; import javax.swing.border.*; import java.awt.event.*; import javax.swing.event.*; public class ScalePanel extends JPanel implements ChangeListener { JMeter meter; JScale scale; float value; /** The ScalePanel class takes in three parameters a Meter, a Scale and a Rectangle which * stores the size of how big you want to make the ScalePanel. It then uses these three * parameters and places them in their rightful positions. */ public ScalePanel(JMeter m, JScale s, Rectangle rect) { super(); this.setLayout(null); // this just sets the layout and size of the panel this.setBounds(rect); // this sets the size of the ScalePanel this.meter = m; this.scale = s; int pheight = (int) rect.getHeight(); // gets the height and width of the panel int pwidth = (int) rect.getWidth(); this.scale.setBounds(0,pheight/6,pwidth,(pheight-(pheight/6))); // this makes the size of the scale a fraction of //the panel this.scale.addChangeListener(this); // adds a listner to the scale meter.setBounds(0,0,pwidth,pheight/6); // this creates the meter and places it on top of the scale this.add(meter); this.add(scale); // this adds them on the panel value = scale.returnValue(); // takes the current value and places it on the meter meter.setValue(value); } public void stateChanged(ChangeEvent e) { value = scale.returnValue(); // this updates the meter when the scale is changed meter.setValue(value); } }