//****************************************************************************** // Circle.java: Applet // //****************************************************************************** import java.applet.*; import java.awt.*; import ColorBars; //============================================================================== // Main Class for applet Circle // //============================================================================== public class Circle extends Applet { // PARAMETER SUPPORT: // Parameters allow an HTML author to pass information to the applet; // the HTML author specifies them using the tag within the // tag. The following variables are used to store the values of the // parameters. //-------------------------------------------------------------------------- // Members for applet parameters // = //-------------------------------------------------------------------------- private int m_r = 0; private int m_g = 0; private int m_b = 0; private int red = 0; private int green = 0; private int blue = 0; ColorBars m_bars; // 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_r = "r"; private final String PARAM_g = "g"; private final String PARAM_b = "b"; // Circle Class Constructor //-------------------------------------------------------------------------- public Circle() { // TODO: Add constructor code here } // APPLET INFO SUPPORT: // The getAppletInfo() method returns a string describing the applet's // author, copyright date, or miscellaneous information. //-------------------------------------------------------------------------- public String getAppletInfo() { return "Name: Circle\r\n" + "Author: Bruce Maxim\r\n" + "Created with Microsoft Visual J++ Version 1.0"; } // PARAMETER SUPPORT // The getParameterInfo() method returns an array of strings describing // the parameters understood by this applet. // // Circle Parameter Information: // { "Name", "Type", "Description" }, //-------------------------------------------------------------------------- public String[][] getParameterInfo() { String[][] info = { { PARAM_r, "int", "Parameter description" }, { PARAM_g, "int", "Parameter description" }, { PARAM_b, "int", "Parameter description" }, }; return info; } // The init() method is called by the AWT when an applet is first loaded or // reloaded. Override this method to perform whatever initialization your // applet needs, such as initializing data structures, loading images or // fonts, creating frame windows, setting the layout manager, or adding UI // components. //-------------------------------------------------------------------------- public void init() { // PARAMETER SUPPORT // The following code retrieves the value of each parameter // specified with the tag and stores it in a member // variable. //---------------------------------------------------------------------- String param; // r: Parameter description //---------------------------------------------------------------------- param = getParameter(PARAM_r); if (param != null) m_r = Integer.parseInt(param); // g: Parameter description //---------------------------------------------------------------------- param = getParameter(PARAM_g); if (param != null) m_g = Integer.parseInt(param); // b: Parameter description //---------------------------------------------------------------------- param = getParameter(PARAM_b); if (param != null) m_b = Integer.parseInt(param); // If you use a ResourceWizard-generated "control creator" class to // arrange controls in your applet, you may want to call its // CreateControls() method from within this method. Remove the following // call to resize() before adding the call to CreateControls(); // CreateControls() does its own resizing. //---------------------------------------------------------------------- // resize(60, 60); m_bars = new ColorBars(this); m_bars.CreateControls(); // TODO: Place additional initialization code here } // Place additional applet clean up code here. destroy() is called when // when you applet is terminating and being unloaded. //------------------------------------------------------------------------- public void destroy() { // TODO: Place applet cleanup code here } // Circle Paint Handler //-------------------------------------------------------------------------- public void paint(Graphics g) { // g.drawString("Created with Microsoft Visual J++ Version 1.0", 10, 20); g.setColor(new Color(m_r, m_g, m_b)); g.fillOval(10, 10, 40, 40); } // The start() method is called when the page containing the applet // first appears on the screen. The AppletWizard's initial implementation // of this method starts execution of the applet's thread. //-------------------------------------------------------------------------- public void start() { // TODO: Place additional applet start code here } // The stop() method is called when the page containing the applet is // no longer on the screen. The AppletWizard's initial implementation of // this method stops execution of the applet's thread. //-------------------------------------------------------------------------- public void stop() { } // TODO: Place additional applet code here public void setCircleColor(int red, int green, int blue) { m_r = red; m_g = green; m_b = blue; repaint(); } public boolean handleEvent(Event e) { if (e.target == m_bars.Red_Bar) { red = m_bars.Red_Bar.getValue(); setCircleColor(red, green, blue); repaint(); }; if (e.target == m_bars.Green_Bar) { green = m_bars.Green_Bar.getValue(); setCircleColor(red, green, blue); repaint(); }; if (e.target == m_bars.Blue_Bar) { blue = m_bars.Blue_Bar.getValue(); setCircleColor(red, green, blue); repaint(); }; if (e.target == m_bars.CButton) { red = 0; green = 0; blue = 0; m_bars.Red_Bar.setValue(0); m_bars.Green_Bar.setValue(0); m_bars.Blue_Bar.setValue(0); setCircleColor(red, green, blue); repaint(); } return true; } }