Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 8 of 8

Thread: ERROR, I CANT DEFINE IT

  1. #1
    Java kindergarten chronoz13's Avatar
    Join Date
    Mar 2009
    Location
    Philippines
    Posts
    659
    Thanks
    177
    Thanked 30 Times in 28 Posts

    Default ERROR, I CANT DEFINE IT

    ill show the first two classes that my main class use

    the DrawingBoard class

    package preDefinedClassesSamples;
     
    import java.awt.*;
    import javax.swing.*;
    import java.util.*;
     
    /*
        Introduction to OOP with Java 4th Ed, McGraw-Hill
     
        Wu/Otani
     
        Chapter 5 The DrawingBoard class
     
        File: DrawingBoard.java
    */
     
    public class DrawingBoard extends JFrame implements Runnable
    {
     
    //----------------------------------
    //    Data Members:
    //----------------------------------
     
        /**
         * Enumerated constants for the movement of the shape
         */
        public static enum Movement {
     
            SMOOTH, RANDOM, STATIONARY;
        }
     
        /**
         * Constant for delay time (in seconds) between drawing
         */
        private static final double DEFAULT_DELAY_TIME = 0.15;
     
        /**
         * Constant for default background color
         */
        private static final Color DEFAULT_BACKGROUND = Color.black;
     
        /**
         * List to remember the shapes for drawing
         */
        private java.util.List shapeList;
     
        /**
         * List of (deltaX,deltaY) pairs represented as Point
         */
        private java.util.List offsetList;
     
        /**
         * Delay time (in seconds) between drawing
         */
        private double      delayTime;
     
        /**
         * Type of drawing -- SMOOTH, RANDOM, or STATIONARY
         */
        private Movement         drawingType;
     
        /**
         * Size of this window
         */
        private Dimension   windowSize;
     
        /**
         * Border size of this frame
         */
        private Insets      inset;
     
        /**
         * An Image used for double-buffering.
         */
        private Image       offScreenImage;
     
        /**
         * A Graphics object associated to the offscreen Image used for double-buffering.
         */
        private Graphics    offScreenGraphics;
     
        /**
         * Background color
         */
        private Color       bkcolor;
     
    //-----------------------------------------
    //
    //    Constructors:
    //
    //-----------------------------------------
     
        /**
         * Default Constructor.
         *
         */
        public DrawingBoard( ) {
     
            this(DEFAULT_DELAY_TIME, Movement.STATIONARY);
        }
     
        /**
         * Sets the delay time to the given parameter.
         *
         * @param delayTime delay time between drawings
         * @param type      drawing type -- SMOOTH, RANDOM, STATIONARY
         */
        public DrawingBoard(double delayTime, Movement type) {
     
            this.delayTime   = delayTime;
            this.drawingType = type;
     
            shapeList = new ArrayList();
     
            Toolkit toolkit = Toolkit.getDefaultToolkit();
            windowSize      = toolkit.getScreenSize();
            setBounds(0, 0, windowSize.width, windowSize.height);
     
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            setResizable(false);
     
            bkcolor = DEFAULT_BACKGROUND;
        }
     
    //-------------------------------------------------
    //      Public Methods:
    //
    //           public void  addShape(DrawableShape)
    //           public void  draw(Graphics)
    //
    //           public void  setBackground(Color)
    //           public void  setDelayTime(double)
    //           public void  setMovement(int)
    //           public void  setVisible(boolean)
    //
    //           public void  paint(Graphics)
    //           public void  run( )
    //           public void  start( )
    //
    //           public Point getCenterPoint()
    //
    //
    //------------------------------------------------
     
     
        /**
         * Adds the shape to be drawn on this drawing board
         *
         * @param shape the shape to be drawn
         */
        public void addShape(DrawableShape shape) {
     
            shapeList.add(shape);
     
            //assign a random point as the shape's center point
            //if one is not defined yet
            Point pt = shape.getCenterPoint();
            if (pt == null) {
                Dimension dim = shape.getDimension();
     
                int xMargin = (int) Math.round(dim.width / 2);
                int yMargin = (int) Math.round(dim.height / 2);
     
                pt = new Point(getRandom(xMargin, windowSize.width  - xMargin), getRandom(yMargin, windowSize.height - yMargin));
     
                shape.setCenterPoint(pt);
            }
        }
     
        /**
         * Sets the background color.
         *
         * @param background background color
         */
        @Override
        public void setBackground(Color background) {
     
            super.setBackground(background);
            bkcolor = background;
        }
     
     
        /**
         * Sets the delay time between the drawings.
         *
         * @param delayTime the delay time
         */
        public void setDelayTime(double delayTime) {
     
            if (delayTime < 0) {
     
                delayTime = -delayTime;
            }
     
            this.delayTime = delayTime;
        }
     
        /**
         * Sets the drawing type. Invalid parameter will
         * be ignored causing no changes.
         *
         * @param drawingType the drawing type
         */
        public void setMovement(Movement drawingType) {
     
                this.drawingType = drawingType;       
        }
     
        /**
         * Overrides the inherited setVisible to make
         * this frame appear on the screen as maximized and
         * with the black background.
         *
         * @param state true for visible; false for invisible
         */
        @Override
        public void setVisible(boolean state) {
     
            super.setVisible(state);
            inset  = getInsets();
     
            offScreenImage    = createImage(windowSize.width, windowSize.height);
            offScreenGraphics = offScreenImage.getGraphics();
     
            repaint();
        }
     
     
        /**
         * Paint the contents by asking shapes to draw themselves
         *
         * @param Graphics the graphics object to draw lines
         */
        @Override
        public void paint(Graphics g) {
     
            if (offScreenGraphics != null) {
     
                offScreenGraphics.setColor(bkcolor);
                offScreenGraphics.fillRect( 0, 0,
                                             windowSize.width,
                                             windowSize.height );
     
                switch (drawingType) {
     
                    case SMOOTH:     smoothDrawing(offScreenGraphics);
                                     break;
     
                    case RANDOM:     randomDrawing(offScreenGraphics);
                                     break;
     
                    case STATIONARY: stationaryDrawing(offScreenGraphics);
                                     break;
                }
     
                g.drawImage ( offScreenImage, 0, 0, this );
            }
        }
     
     
        /**
         * Implements the Runnable interface.
         */
        public void run( ) {
     
            while (true) {
     
                try {
                    Thread.sleep((long)(delayTime * 1000));
     
                } catch (Exception e) { }
     
                repaint();
            }
        }
     
     
        /**
         * Starts the drawing
         */
        public void start( ) {
     
            if (!isVisible()) {
                this.setVisible(true);
            }
     
            Thread thread = new Thread(this);
     
            thread.start();
        }
     
     
    //-------------------------------------------------
    //      Private Methods:
    //
    //           public void  createOffsetList( )
    //           public int   getRandom(int, int)
    //
    //           public void  randomDrawing(Graphics)
    //           public void  smoothDrawing(Graphics)
    //           public void  stationaryDrawing(Graphics)
    //
    //------------------------------------------------
     
     
        /**
         * Creates the offset list of (deltaX,deltaY).
         */
        private void createOffsetList( ) {
     
            if (offsetList == null) {
     
                offsetList = new ArrayList();
     
                for (int i = 0; i < shapeList.size(); i++) {
     
                    Point pt = new Point(getRandom(10, 20),
                                         getRandom(10, 20));
     
                    pt.x *= Math.round(Math.random()) == 0 ? 1 : -1;
                    pt.y *= Math.round(Math.random()) == 0 ? 1 : -1;
     
                    offsetList.add(pt);
                }
            }
        }
     
        /**
         * Returns a random number between
         * the passed parameters min and max.
         *
         * @param min the lower bound of the random number
         * @param max the upper bound of the random number
         */
        private int getRandom(int min, int max) {
     
            double temp = Math.random() * (max - min + 1);
            return (int) Math.floor(temp) + min;
        }
     
     
        /**
         * Draws the shapes at random locations
         *
         * @param Graphics the graphics context
         */
        private void randomDrawing(Graphics g) {
     
            Iterator itr = shapeList.iterator();
     
            while (itr.hasNext()) {
     
                DrawableShape s = (DrawableShape) itr.next();
     
                s.draw(g);
     
                Dimension dim = s.getDimension();
                int xMargin = dim.width / 2;
                int yMargin = dim.height / 2;
     
                //update the center point for next drawing
                s.setCenterPoint(
                    new Point(getRandom(xMargin, windowSize.width - xMargin),
                              getRandom(yMargin, windowSize.height- yMargin))
                                 );
            }
     
        }
     
        /**
         * Draws the shapes at continuous locations
         *
         * @param Graphics the graphics context
         */
        private void smoothDrawing(Graphics g) {
     
            int tempX, tempY;
     
            createOffsetList( );
     
            Iterator itr  = shapeList.iterator();
            Iterator oItr = offsetList.iterator();
     
            while (itr.hasNext()) {
     
                DrawableShape s = (DrawableShape) itr.next();
                Point         delta = (Point) oItr.next();
     
                Dimension dim = s.getDimension();
                int xMargin = (int) Math.round(dim.width / 2);
                int yMargin = (int) Math.round(dim.height / 2);
     
                s.draw(g);
     
                //update the center point for the next drawing
                Point pt = s.getCenterPoint( );
     
                pt.x += delta.x;
                pt.y += delta.y;
     
                //adjust for the boundary case
                if (pt.x > windowSize.width - xMargin - inset.right) {
     
                    pt.x = windowSize.width - xMargin - inset.right;
                    delta.x = -delta.x;
     
                } else if ( pt.x < inset.left + xMargin) {
     
                    pt.x = inset.left + xMargin;
                    delta.x = -delta.x;
     
                } else if (pt.y > windowSize.height - yMargin - inset.bottom) {
     
                    pt.y = windowSize.height - yMargin - inset.bottom;
                    delta.y = -delta.y;
     
                } else if (pt.y < inset.top + yMargin)  {
     
                    pt.y = inset.top + yMargin;
                    delta.y = -delta.y;
                }
            }
        }
     
        /**
         * Draws the shapes at fixed, stationary locations
         *
         * @param Graphics the graphics context
         */
        private void stationaryDrawing(Graphics g) {
     
            Iterator itr = shapeList.iterator();
     
            while (itr.hasNext()) {
     
                DrawableShape s = (DrawableShape) itr.next();
     
                s.draw(g);
            }
        }
    }


    the DrawableShape class

    package preDefinedClassesSamples;
     
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.Graphics;
    import java.awt.Point;
     
     
    public class DrawableShape {
     
        public static enum Type {
     
            ELLIPSE, RECTANGLE, ROUNDED_RECTANGLE;
        }
     
        private static final Dimension DEFAULT_DIMENSION  = new Dimension (200, 200);
     
        private static final Point DEFUALT_CENTER_PT = new Point(350, 350);
     
        private static final Color DEFAULT_COLOR = Color.BLUE;
     
        private Color fillColor;
     
        private Point centerPoint;
     
        private Dimension dimension;
     
        private Type type;
     
        /**
         * Sets the properties of the shape to be drawn
         * 
         * @param sType     - the type of the shape to be drawn
         * @param sDim      - the dimension of the shape
         * @param sCenter   - the center point of the shape
         * @param sColor    - the color of the shape
         */
        public DrawableShape(Type sType, Dimension sDim, Point sCenter, Color sColor) {
     
            type = sType;
            dimension = sDim;
            centerPoint = sCenter;
            fillColor = sColor;
        }
     
        public void draw(Graphics g) {
     
            g.setColor(fillColor);
            drawShape(g);
        }
     
        public void setType(Type shapeType) {
     
            type = shapeType;
        }
     
     
        private void drawShape(Graphics g) {
     
            switch (type) {
     
                case ELLIPSE:
     
                    g.fillOval(centerPoint.x - dimension.width / 2, centerPoint.y - dimension.height / 2,
                               dimension.width, dimension.height);
                    break;
     
                case RECTANGLE:
     
                    g.fillRect(centerPoint.x - dimension.width / 2, centerPoint.y - dimension.height / 2,
                               dimension.width, dimension.height);
                    break;
     
                case ROUNDED_RECTANGLE:
     
                    g.fillRoundRect(centerPoint.x - dimension.width  / 2, centerPoint.y - dimension.height / 2,
                                    dimension.width, dimension.height, (int) (dimension.width * 0.3), (int) (dimension.height * 0.3));
                    break;
            }
        }
     
        public Point getCenterPoint() {
     
            return centerPoint;
        }
     
        public Dimension getDimension() {
     
            return new Dimension(200, 200);
        }
     
        public void setCenterPoint(Point point) {
     
            centerPoint = point;
        }
    }


    and my MAIN class that use this two

    package xTestx;
     
    import java.awt.Color;
    import javax.swing.JFrame;
    import javax.swing.JButton;
    import javax.swing.JSlider;
    import javax.swing.JLabel;
    import javax.swing.JOptionPane;
    import javax.swing.JRadioButton;
    import javax.swing.ButtonGroup;
    import javax.swing.Action;
    import javax.swing.AbstractButton;
    import javax.swing.SwingConstants;
    import javax.swing.SwingUtilities;
    import javax.swing.event.ChangeListener;
    import javax.swing.event.ChangeEvent;
     
    import java.awt.Font;
    import java.awt.Point;
    import java.awt.Dimension;
    import java.awt.Label;
    import java.awt.Container;
    import java.awt.event.KeyEvent;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.AbstractAction;
     
     
    import preDefinedClassesSamples.DrawingBoard;
    import preDefinedClassesSamples.DrawableShape;
     
     
     
    public class Properties  implements ChangeListener {
     
        DrawableShape shape;
        DrawingBoard drawingBoard;
     
        // type of the shape
        DrawableShape.Type shapeType;
     
        // movement of the shape;
        DrawingBoard.Movement shapeMovement;
     
        // main window
        JFrame propertiesWindow;
     
        // sliders for the geometrical properties of the shape
        JSlider widthSlider;
        JSlider heightSlider;
        JSlider pointXSlider;
        JSlider pointYSlider;
     
        // sliders for the color of the shape
        JSlider redSlider;
        JSlider greenSlider;
        JSlider blueSlider;
     
        // radio button options for the type of the shape
        JRadioButton ellipse;
        JRadioButton rectangle;
        JRadioButton roundRect;
     
        // radio button options for the movement of the shape
        JRadioButton smooth;
        JRadioButton random;        // NOT USED
        JRadioButton stationary;
     
        // button for the confirmation that will set all the properties of the shape
        JButton confirmation;
     
        // labels for the sliders
        JLabel widthLabel;
        JLabel heightLabel;
        JLabel pointXLabel;
        JLabel pointYLabel;
        JLabel redSliderLabel;
        JLabel greenSliderLabel;
        JLabel blueSliderLabel;
     
        /**
         * label which will be the representaion of the value that will be generated
         * by the sliders
         */
         JLabel widthFrequency;
         JLabel heightFrequency;
         JLabel pointXFrequency;
         JLabel pointYFrequency;
         JLabel redSliderFrequency;
         JLabel greenSliderFrequency;
         JLabel blueSliderFrequency;
     
         // shape group's label
         JLabel shapeGroupLabel;
     
         // shape movements group's label
         JLabel movementGroupLabel; 
     
         // button group for the shape selection radio buttons
         ButtonGroup shapeGroup;
     
         // button group for the shapes movement radio buttons
         ButtonGroup shapeMovementGroup; // not used
     
        // the spot where the slider color combination will be displayed
        Label colorSpot;
     
        // color spot label name
        Label colorSpotName;
     
        // color spot for each of the RGB sliders
        Label redSpot;
        Label greenSpot;
        Label blueSpot;
     
        // center point of the chape
        Point shapeCenterPoint;
     
        // dimension of the shape
        Dimension shapeDimension;
     
        // color of the shape
        Color shapeColor;
     
        // contant color for the RGB slider (Red)
        private static final Color RED = new Color(180, 0, 0);
     
        // contant color for the RGB slider (green)
        private static final Color GREEN = new Color(0, 180, 0);
     
        // contant color for the RGB slider (Blue)
        private static final Color BLUE = new Color(0, 0, 180);
     
        /**
         * minimum value for the width of the shape, and the initialized value
         * where the slider is pointing
         */
        private static final int WIDTH_MIN_VALUE = 100;
     
        // maximum value for width of the shape
        private static final int WIDTH_MAX_VALUE = 500;
     
        /**
         * minimum value for the height of the shape, and the initialized value
         * where the slider is pointing
         */
        private static final int HEIGHT_MIN_VALUE = 100;
     
        // maximum value for the height of the shape
        private static final int HEIGHT_MAX_VALUE = 500;
     
        /**
         * minimum value for the center point (point x) of the shape, and the
         * initialized value where the slider is pointing
         */
        private static final int MIN_POINT_X = 200;
     
        // maximum value for the center point (point x) of the shape
        private static final int MAX_POINT_X = 800;
     
        /**
         * minimum value for the center point (point y) of the shape, and the
         * initialized value where the slider is pointing
         */
        private static final int MIN_POINT_Y = 100;
     
        // maximum value for the center point (point  y) of the shape
        private static final int MAX_POINT_Y = 500;
     
        // constant value for color scheme slider's minor tick
        private static final int COLOR_SLIDER_MINOR_TICK = 5;
     
        // constant value for color scheme slider's major tick
        private static final int COLOR_SLIDER_MAJOR_TICK = 10;
     
        // constant value of minor tick for the geometric pattern sliders
        private static final int MINOR_TICK = 10;
     
        // constant value of major tick for the geometric pattern sliders
        private static final int MAJOR_TICK = 100;
     
        // temporary placeholder for the shape selection
        private String tempShape;
     
        // constructs the components of this window
        public Properties() {
     
            drawingBoard = new DrawingBoard();
            propertiesWindow = new JFrame("Screensaver Properties");
            widthSlider = new JSlider(WIDTH_MIN_VALUE, WIDTH_MAX_VALUE, WIDTH_MIN_VALUE);
            heightSlider = new JSlider(HEIGHT_MIN_VALUE, HEIGHT_MAX_VALUE, HEIGHT_MIN_VALUE);
            pointXSlider = new JSlider(MIN_POINT_X, MAX_POINT_X, MIN_POINT_X);
            pointYSlider = new JSlider(MIN_POINT_Y, MAX_POINT_Y, MIN_POINT_Y);
            redSlider = new JSlider(SwingConstants.VERTICAL, 0, 255, 0);
            greenSlider = new JSlider(SwingConstants.VERTICAL, 0, 255, 0);
            blueSlider = new JSlider(SwingConstants.VERTICAL, 0, 255, 0);
            ellipse = new JRadioButton();
            rectangle = new JRadioButton();
            roundRect = new JRadioButton();
            smooth = new JRadioButton();
            random = new JRadioButton();
            stationary = new JRadioButton();
            widthLabel = new JLabel("Width  :  ");
            heightLabel = new JLabel("Height  :  ");
            pointXLabel = new JLabel("Center Point (point x)  :  ");
            pointYLabel = new JLabel("Center Point (point y)  :  ");
            redSliderLabel = new JLabel("Red  :  ");
            greenSliderLabel = new JLabel("Green  :  ");
            blueSliderLabel = new JLabel("Blue  :  ");
            colorSpot = new Label();
            widthFrequency = new JLabel("" + WIDTH_MIN_VALUE);
            heightFrequency = new JLabel("" + HEIGHT_MIN_VALUE);
            pointXFrequency = new JLabel("" + MIN_POINT_X);
            pointYFrequency = new JLabel("" + MIN_POINT_Y);
            redSliderFrequency = new JLabel("0");
            greenSliderFrequency = new JLabel("0");
            greenSliderFrequency = new JLabel("0");
            blueSliderFrequency = new JLabel("0");
            shapeGroupLabel = new JLabel();
            movementGroupLabel = new JLabel();  // not used
            shapeGroup = new ButtonGroup();
            shapeMovementGroup = new ButtonGroup();  // not used
            redSpot = new Label();
            greenSpot = new Label();
            blueSpot = new Label();
        }
     
        public void setTheShapeProperties(Container cont) {
     
            // set the slider labels properties and location
            widthLabel.setBounds(15, 10, 50, 50);
            heightLabel.setBounds(15, 130, 70, 50);
            pointXLabel.setBounds(15, 260, 200, 50);
            pointYLabel.setBounds(15, 385, 200, 50);
            redSliderLabel.setBounds(400, 20, 50, 30);
            greenSliderLabel.setBounds(580, 20, 50, 30);
            blueSliderLabel.setBounds(760, 20, 50, 30);
     
            // set the Red slider's color spot properties
            redSpot.setBounds(380, 30, 13, 11);
            redSpot.setBackground(Color.BLACK);
     
            // set the Green slider's color spot properties
            greenSpot.setBounds(560, 30, 13, 11);
            greenSpot.setBackground(Color.BLACK);
     
            // set the Blue slider's color spot properties
            blueSpot.setBounds(740, 30, 13, 11);
            blueSpot.setBackground(Color.BLACK);
     
            // set the sliders frequencies' location and dimension
            widthFrequency.setBounds(60, 10, 50, 50);
            heightFrequency.setBounds(60, 120, 70, 50);
            pointXFrequency.setBounds(145, 240, 40, 50);
            pointYFrequency.setBounds(145, 365, 40, 50);
            redSliderFrequency.setBounds(450, 10, 50, 50);
            greenSliderFrequency.setBounds(640, 10, 50, 50);
            blueSliderFrequency.setBounds(810, 10, 50, 50);
     
     
            // set the width slider properties
            widthSlider.setBounds(15, 60, 320, 50);
            widthSlider.setMinorTickSpacing(MINOR_TICK);
            widthSlider.setMajorTickSpacing(MAJOR_TICK);
            widthSlider.setPaintTicks(true);
            widthSlider.setPaintLabels(true);
            widthSlider.setToolTipText("Width");
            widthSlider.addChangeListener(this);
     
            // set the height slider properties
            heightSlider.setBounds(15, 170, 320, 50);
            heightSlider.setMinorTickSpacing(MINOR_TICK);
            heightSlider.setMajorTickSpacing(MAJOR_TICK);
            heightSlider.setPaintTicks(true);
            heightSlider.setPaintLabels(true);
            heightSlider.setToolTipText("Height");
            heightSlider.addChangeListener(this);
     
            // set the point x slider (center point x) properties
            pointXSlider.setBounds(15, 295, 320, 50);
            pointXSlider.setMinorTickSpacing(MINOR_TICK);
            pointXSlider.setMajorTickSpacing(MAJOR_TICK);
            pointXSlider.setPaintTicks(true);
            pointXSlider.setPaintLabels(true);
            pointXSlider.setToolTipText("Center Point (x)");
            pointXSlider.addChangeListener(this);
     
            // set the point y slider (centern point y) properties
            pointYSlider.setBounds(15, 420, 320, 50);
            pointYSlider.setMinorTickSpacing(MINOR_TICK);
            pointYSlider.setMajorTickSpacing(MAJOR_TICK);
            pointYSlider.setPaintTicks(true);
            pointYSlider.setPaintLabels(true);
            pointYSlider.setToolTipText("Center Point (y)");
            pointYSlider.addChangeListener(this);
     
            // set the red slider properties
            redSlider.setBounds(400, 50, 30, 420);
            redSlider.setForeground(RED);
            redSlider.setMinorTickSpacing(COLOR_SLIDER_MINOR_TICK);
            redSlider.setMajorTickSpacing(COLOR_SLIDER_MAJOR_TICK);
            redSlider.setPaintTicks(true);
            redSlider.setToolTipText("Red");
            redSlider.addChangeListener(this);
     
            // set the green slider properties
            greenSlider.setBounds(580, 50, 30, 420);
            greenSlider.setForeground(GREEN);
            greenSlider.setMinorTickSpacing(COLOR_SLIDER_MINOR_TICK);
            greenSlider.setMajorTickSpacing(COLOR_SLIDER_MAJOR_TICK);
            greenSlider.setPaintTicks(true);
            greenSlider.setToolTipText("Green");
            greenSlider.addChangeListener(this);
     
            // set the blue slider properties
            blueSlider.setBounds(760, 50, 30, 420);
            blueSlider.setForeground(BLUE);
            blueSlider.setMinorTickSpacing(COLOR_SLIDER_MINOR_TICK);
            blueSlider.setMajorTickSpacing(COLOR_SLIDER_MAJOR_TICK);
            blueSlider.setPaintTicks(true);
            blueSlider.setToolTipText("Blue");
            blueSlider.addChangeListener(this);
     
     
            // set the properties of the color spot
            colorSpot.setText("Shape's Color.");
            colorSpot.setFont(new Font("Monospaced",Font.CENTER_BASELINE ,30));
            colorSpot.setAlignment(Label.CENTER);
            colorSpot.setForeground(Color.WHITE);
            colorSpot.setBounds(400, 490, 400, 90);
            colorSpot.setBackground(Color.BLACK);
     
            // set the confirmation button's properties and actions
            Action action = new AbstractAction() {
     
                public void actionPerformed(ActionEvent e) {
     
                    shapeProperties();
                }
            };
            action.putValue(AbstractAction.NAME, "Procced To Screensaver");
            confirmation = new JButton(action);              
            confirmation.setBounds(900, 570, 175, 30);
            confirmation.setMnemonic(KeyEvent.VK_ENTER);
     
            // set the action for the radio buttons
            ActionListener shapeSelectionAction = new ActionListener() {
     
                public void actionPerformed(ActionEvent event) {
     
                    AbstractButton actionButton = (AbstractButton) event.getSource();
     
                    String tempShape = actionButton.getText();
     
                    /**
                     * lets make sure that whatever the string format that the
                     * button will return, it will still match the condition to
                     * set the proper shape type of the shape.
                     *
                     * So just in case, the string label of the radio button
                     * accidentally or intentionally changed, this condition will still
                     * generate matching string format.
                     *
                     * And a default shape will be generated, just in case.
                     */
                    if (tempShape.equalsIgnoreCase("Ellipse")) {
     
                        shapeType = DrawableShape.Type.ELLIPSE;
                    }
                    else if (tempShape.equalsIgnoreCase("Rectangle")) {
     
                        shapeType = DrawableShape.Type.RECTANGLE;
                    }
                    else if (tempShape.equalsIgnoreCase("Rounded Rectangle")) {
     
                        shapeType = DrawableShape.Type.ROUNDED_RECTANGLE;
                    }
                    else {
     
                        shapeType = DrawableShape.Type.ELLIPSE;
                    }
                }      
            };
            ellipse.addActionListener(shapeSelectionAction);
            rectangle.addActionListener(shapeSelectionAction);
            roundRect.addActionListener(shapeSelectionAction);
     
            // set the shape group's label's properties
            shapeGroupLabel.setText("Select A Shape  :");
            shapeGroupLabel.setBounds(880, 80, 100, 15);
     
            // set the properties of the ellipse radio button
            ellipse.setText("Ellipse");
            ellipse.setToolTipText("Ellise");
            ellipse.setBounds(890, 105, 65, 20);
     
            // set the properties of the rectangle radio button
            rectangle.setText("Rectangle");
            rectangle.setToolTipText("Rectangle");
            rectangle.setBounds(890, 135, 85, 20);
     
            // set the properties of the rounded rectangle radio button
            roundRect.setText("Rounded Rectangle");
            roundRect.setToolTipText("Rounded Rectangle");
            roundRect.setBounds(890, 165, 135, 20);
     
            // make the group for the shapes' radio buttons
            shapeGroup.add(ellipse);
            shapeGroup.add(rectangle);
            shapeGroup.add(roundRect);     
     
            // set the action and properties of the shape movement radio buttons
            ActionListener movementSelectionAction = new ActionListener() {
     
                public void actionPerformed(ActionEvent event) {
     
                    AbstractButton actionButton = (AbstractButton) event.getSource();
     
                    String tempMovement = actionButton.getText();
     
                    /**
                     * same style done in shape's type radio buttons
                     */
                    if (tempMovement.equalsIgnoreCase("Smooth")) {
     
                        shapeMovement = DrawingBoard.Movement.SMOOTH;
                    }
                    else if (tempMovement.equalsIgnoreCase("Random")) {
     
                        shapeMovement = DrawingBoard.Movement.RANDOM;
                    }
                    else if (tempMovement.equalsIgnoreCase("Stationary")) {
     
                        shapeMovement = DrawingBoard.Movement.STATIONARY;
                    }
                    // default shape will be generated just in case
                    else {
     
                        shapeMovement = DrawingBoard.Movement.SMOOTH;
                    } 
                }  
            };
            smooth.addActionListener(movementSelectionAction);
            random.addActionListener(movementSelectionAction);
            stationary.addActionListener(movementSelectionAction);
     
            // set the movement group's label's properties
            movementGroupLabel.setText("Select A Movement  :");
            movementGroupLabel.setBounds(880, 250, 120, 15);
            movementGroupLabel.setBackground(Color.RED);
     
            // set the properties of the "smooth" radio button
            smooth.setText("Smooth");
            smooth.setBounds(890, 280, 100, 20);
     
            // set the properties of the "random" radio button
            random.setText("Random");
            random.setBounds(890, 310, 100, 20);
     
            // set the properties of the "staionary" radio button
            stationary.setText("Stationary");
            stationary.setBounds(890, 340, 100, 20);
     
            // make the group for the shape's movement radio buttons
            shapeMovementGroup.add(smooth);
            shapeMovementGroup.add(random);
            shapeMovementGroup.add(stationary);
     
            /**
             * sets the layout to null, no layout will be used,
             * this is an absolute positioning of the components
             */
            cont.setLayout(null);
     
            // add the sliders
            cont.add(widthSlider);
            cont.add(heightSlider);
            cont.add(pointXSlider);
            cont.add(pointYSlider);
            cont.add(redSlider);
            cont.add(greenSlider);
            cont.add(blueSlider);
     
            // add the slider labels as well as their frequencies
            cont.add(widthLabel);
            cont.add(widthFrequency);
            cont.add(heightLabel);
            cont.add(heightFrequency);
            cont.add(pointXLabel);
            cont.add(pointXFrequency);
            cont.add(pointYLabel);
            cont.add(pointYFrequency);
            cont.add(redSliderLabel);
            cont.add(redSpot);
            cont.add(redSliderFrequency);
            cont.add(greenSliderLabel);
            cont.add(greenSpot);
            cont.add(greenSliderFrequency);
            cont.add(blueSliderLabel);
            cont.add(blueSpot);
            cont.add(blueSliderFrequency);
            cont.add(colorSpot);
     
            // add the confirmation button
            cont.add(confirmation);
     
            // add the label of the shape radio buttons group
            cont.add(shapeGroupLabel);
     
            // add the shape type radio buttons
            cont.add(ellipse);
            cont.add(rectangle);
            cont.add(roundRect);
     
            //add the label of the shape's movement radio button group
            cont.add(movementGroupLabel);
     
            // add the shape's movement type radio buttons
            cont.add(smooth);
            cont.add(random);
            cont.add(stationary);
        }
     
        public void stateChanged(ChangeEvent event) {
     
            if (event.getSource() == redSlider || event.getSource() == greenSlider ||
                event.getSource() == blueSlider) {
     
               int tempRed = redSlider.getValue();
               int tempGreen = greenSlider.getValue();
               int tempBlue = blueSlider.getValue();
     
               redSliderFrequency.setText("" + tempRed);
               greenSliderFrequency.setText("" + tempGreen);
               blueSliderFrequency.setText("" + tempBlue);
     
               /**
                * check if the color combination on the color spot is too light,
                * then the colorSpot's text must be black for the user to see the text
                */
               if ((tempRed >= 200) && (tempRed <= 255)) {
     
                   if ((tempGreen >= 200) && (tempGreen <= 255))  {
     
                       if ((tempBlue >= 200) && (tempBlue <= 255)) {
     
                           colorSpot.setForeground(Color.BLACK);
                       }
                   }
               }
               // else make it white
               else if ((tempRed <= 60) && (tempRed >= 0)) {
     
                   if ((tempGreen <= 60) && (tempGreen >= 0)) {
     
                       if ((tempBlue <= 60) && (tempBlue >= 0)) {
     
                           colorSpot.setForeground(Color.WHITE);
                       }
                   }
               }
     
               // sets the color of the shape
               shapeColor = new Color(tempRed, tempGreen, tempBlue);
     
               /** sets the color of the frequency,text labels and the color spot
                * for each of the color sliders
                */
               // for red:
               redSliderLabel.setForeground(new Color(tempRed, 0, 0));
               redSliderFrequency.setForeground(new Color(tempRed, 0, 0));
               redSpot.setBackground(new Color(tempRed, 0, 0));
     
               // for green:
               greenSliderLabel.setForeground(new Color(0, tempGreen, 0));
               greenSliderFrequency.setForeground(new Color(0, tempGreen, 0));
               greenSpot.setBackground(new Color(0, tempGreen, 0));
     
               // for blue:
               blueSliderLabel.setForeground(new Color(0, 0, tempBlue));
               blueSliderFrequency.setForeground(new Color(0, 0, tempBlue));
               blueSpot.setBackground(new Color(0, 0, tempBlue));
     
               /**
                * set the color of the color spot corresponding to the color combination
                * generated by the RGB color sliders.
                */
               colorSpot.setBackground(shapeColor);
            }
     
            if (event.getSource() == widthSlider || event.getSource() == heightSlider) {
     
                int shapeWidth = widthSlider.getValue();
                int shapeHeight = heightSlider.getValue();
     
                widthFrequency.setText("" + shapeWidth);
                heightFrequency.setText("" + shapeHeight);
     
                /**
                 * set the dimension of the shape, the default dimension as well,
                 * if the width and heigh sliders hasn't moved
                 */
                shapeDimension = new Dimension(shapeWidth, shapeHeight);
            }
     
            if (event.getSource() == pointXSlider || event.getSource() == pointYSlider) {
     
                int shapePointX = pointXSlider.getValue();
                int shapePointY = pointYSlider.getValue();
     
                pointXFrequency.setText("" + shapePointX);
                pointYFrequency.setText("" + shapePointY);
     
                /**
                 * set the center point of the shape, the deafult centerpoint as well,
                 * if the centerpoint (x,y) sliders has'nt moved
                 */
                shapeCenterPoint = new Point(shapePointX, shapePointY);
            }
        }
     
        /**
         * set the properties of the shape, and use default properties if there will
         * be any error occured.
         */
        private void shapeProperties() {
     
            // count for the properties that will be selected
            int selectedCount = 0;
     
            /**
             * temporary place holder for string representaion of any properties
             * that will be selected
             */
            String tempSelected[];
     
            /**
             * temporary place holder for the string representaion of the properties
             * that will not be selected
             */
            String tempNull[];
     
            int count = 0;
     
            tempSelected = new String[5];
            tempNull = new String[5];
     
            /**
             * check if the shape's type is selected, then add a string representaion
             * that will correspond to this selected property
             */
            if (shapeType != null) {
     
                for (int x = 0; x < 5; x++) {            
     
                    if (tempSelected[x] == null) {
     
                        count++;
     
                        if (count == 1) {
     
                            tempSelected[x] = "type";
                        }
                    }
                }
     
                selectedCount++;
            }
            /**
             * else if the shape type is null, then use a default shape type, and
             * add a string representaion that will correspond to this unselected
             * property
             */
            else {
     
                for (int x = 0; x < 5; x++) {
     
                    if (tempNull[x] == null) {
     
                        count++;
     
                        if (count == 1) {
     
                            tempNull[x] = "type";
                        }
                    }
                }
     
                shapeType = DrawableShape.Type.ELLIPSE;
            }
     
            /**
             * check if the shape's movement is selected, add a string representaion
             * that will correspond to this selected property
             */
            if (shapeMovement != null) {
     
                count = 0;
     
                for (int x = 0; x < 5; x++) {
     
                    if (tempSelected[x] == null) {
     
                        count++;
     
                        if (count == 1) {
     
                            tempSelected[x] = "movement";
                        }
                    }
                }
     
                selectedCount++;
            }
            /**
             * else if shape's movement is null, use a default instead and add a string
             * representaion that will represent this unselected property
             */
            else {
     
                count = 0;
     
                for (int x = 0; x < 5; x++) {
     
                    if (tempNull[x] == null) {
     
                        count++;
     
                        if (count == 1) {
     
                            tempNull[x] = "movement";
                        }
                    }
                }
     
                shapeMovement = DrawingBoard.Movement.SMOOTH;
            }
     
            /**
             * check if the shape's dimension has been selected, add a string
             * representaion that will represent this selected property
             */
            if (shapeDimension != null) {
     
                count = 0;
     
                for (int x = 0; x < 5; x++) {
     
                    if (tempSelected[x] == null) {
     
                        count++;
     
                        if (count == 1) {
     
                            tempSelected[x] = "dimension";
                        }
                    }
                }
     
                selectedCount++;
            }
            /**
             * else if shape's dimension is null, use a default instead and add
             * a string representaion that will represent this unselected property
             */
            else {
     
                count = 0;
     
                for (int x = 0; x < 5; x++) {
     
                    if (tempNull[x] == null) {
     
                        count++;
     
                        if (count == 1) {
     
                            tempNull[x] = "dimension";
                        }
                    }
                }
     
                shapeDimension = new Dimension(WIDTH_MIN_VALUE, HEIGHT_MIN_VALUE);
            }
     
     
            /**
             * check if this property has been selected, add a string representation
             * that will represent this selected property;
             */
            if (shapeCenterPoint != null) {
     
                count = 0;
     
                for (int x = 0; x < 5; x++) {
     
                    if (tempSelected[x] == null) {
     
                        count++;
     
                        if (count == 1) {
     
                            tempSelected[x] = "center point";
                        }
                    }
                }
     
                selectedCount++;
            }
            /**
             * else if this property is null, use a default instead, then add a
             * string representaion that will represent this unselected property
             */
            else {
     
                count = 0;
     
                for (int x = 0; x < 5; x++) {
     
                    if (tempNull[x] == null) {
     
                        count++;
     
                        if (count == 1) {
     
                            tempNull[x] = "center point";
                        }
                    }
                }
     
                shapeCenterPoint = new Point(MIN_POINT_X, MIN_POINT_Y);
            }
     
            /**
             * check if this property has been selected, add a string representaion
             * that will represent this selected property
             */
            if (shapeColor != null) {
     
                count = 0;
     
                for (int x = 0; x < 5; x++) {
     
                    if (tempSelected[x] == null) {
     
                        count++;
     
                        if (count == 1) {
     
                            tempSelected[x] = "color";
                        }
                    }
                }
     
                selectedCount++;
            }
            /**
             * else if this property is null, add a string representation that
             * will represent this unselected property
             */
            else {
     
                count = 0;
     
                for (int x = 0; x < 5; x++) {
     
                    if(tempNull[x] == null) {
     
                        count++;
     
                        if (count == 1) {
     
                            tempNull[x] = "color";
                        }
                    }
                }
     
                shapeColor = Color.WHITE;
            }
     
            System.out.println(tempSelected[0]);
            System.out.println(tempSelected[1]);
            System.out.println(tempSelected[2]);
            System.out.println(tempSelected[3]);
            System.out.println(tempSelected[4]);
     
            System.out.println("\n\n\n\n\n");
     
            System.out.println(tempNull[0]);
            System.out.println(tempNull[1]);
            System.out.println(tempNull[2]);
            System.out.println(tempNull[3]);
            System.out.println(tempNull[4]);
     
            /**
             * this will serve as the count for the indexes in the array that holds
             * the string value that will be displayed
             */
            int value = 0;
     
            if (selectedCount == 1) {
     
                JOptionPane.showMessageDialog(null, "You only selected the shape's " + tempSelected[value],
                                              "Message", JOptionPane.WARNING_MESSAGE);
     
                int response = JOptionPane.showConfirmDialog(null, "Use Default " + tempNull[value++] + ", " + tempNull[value++] + ", " +
                                                             tempNull[value++] + " and " + tempNull[value++] + " ?", "Default",
                                                             JOptionPane.YES_NO_OPTION);
     
                if (response == JOptionPane.YES_OPTION) {
     
                    shape = new DrawableShape(shapeType, shapeDimension, shapeCenterPoint, shapeColor);
                    proceedToScreensaver();
                }
                else if (response == JOptionPane.NO_OPTION) {
     
                    // NOT YET IMPLEMENTED
                }
            }
            else if (selectedCount == 2) {
     
                JOptionPane.showMessageDialog(null, "You only selected the shape's " + tempSelected[value++] +
                                              " and " + tempSelected[value++]);
            }
            else if (selectedCount == 3) {
     
                JOptionPane.showMessageDialog(null, "You only selected the shape's " + tempSelected[value++] + ", " +
                                              tempSelected[value++] + " and " + tempSelected[value++]);
            }
            else if (selectedCount == 4) {
     
                JOptionPane.showMessageDialog(null, "You only selected the shape's " + tempSelected[value++] + ", " +
                                              tempSelected[value++] + ", " + tempSelected[value++] + " and " + tempSelected[value++]);
            }
            else if (selectedCount == 5) {
     
                JOptionPane.showMessageDialog(null, "You did not select anything", "Message",
                                              JOptionPane.WARNING_MESSAGE);
            }
        }
     
        private void proceedToScreensaver() {
     
     
            drawingBoard.setDelayTime(0.000000009);
            drawingBoard.addShape(shape);
            drawingBoard.setMovement(shapeMovement);
            drawingBoard.setVisible(true);
            drawingBoard.start();
        }
        /**
         * just to lessen the coding time if the there is an error occured
         * when modifying the properties of the shape
         */
        private void noOption() {
     
            JOptionPane.showMessageDialog(null, "Unable to proceed due to inconsistency of the properties.",
                                          "Error", JOptionPane.ERROR_MESSAGE);
     
            System.exit(0);
        }
     
        public void showTheScreensaverWindow() {
     
            setTheShapeProperties(propertiesWindow.getContentPane());
     
            propertiesWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            propertiesWindow.setSize(1100, 650);
            propertiesWindow.setLocation(275, 100);
            propertiesWindow.setResizable(true);
            propertiesWindow.setVisible(true);
     
        }
     
        // main
        public static void main(String[] args) {
     
            SwingUtilities.invokeLater(new Runnable() {
     
                Properties screenSaver = new Properties();
     
                public void run() {
     
                    screenSaver.showTheScreensaverWindow();
                }
            });
        }
    }



    now ill state the problem ..

    try to run the MAIN class. and press the only button in the frame "Proceed to screensaver" ,
    press it without moving anything in the frame... dont select anything, just press the JButton,

    my question is.... why is is the program is still running? the whole program supposed to HANG ..
    coz i made a modification that when i press the JButton without selecting anything on the frame..
    the whole program HANGS...


    whats going on here? is it because of the datamember "shape" -- DrawableShape shape;


    PLEASE I NEED HELP HERE,
    Last edited by chronoz13; December 1st, 2009 at 03:34 AM.


  2. #2
    Super Moderator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,099
    Thanks
    169
    Thanked 779 Times in 725 Posts
    Blog Entries
    5

    Default Re: ERROR, I CANT DEFINE IT

    Thats a lot of code, and I commend you on posting well commented code that is self contained and compileable. If you have access to a debugger, set breakpoints in the shapeProperties function and step through it: with nothing selected the shapeProperties variable is zero, and so the method exits without doing anything.
    Something else I noticed by chance is the thread based drawing in your DrawingBoard class, which updates the GUI from a thread. Read up upon threads and swing:
    Threads and Swing
    It might be easier in this case to use a SwingTimer, but either way you should update the gui (the repaint call) from the EDT (for example using SwingUtilities.invokeLater)

  3. The Following User Says Thank You to copeg For This Useful Post:

    chronoz13 (December 1st, 2009)

  4. #3
    Java kindergarten chronoz13's Avatar
    Join Date
    Mar 2009
    Location
    Philippines
    Posts
    659
    Thanks
    177
    Thanked 30 Times in 28 Posts

    Default Re: ERROR, I CANT DEFINE IT

    tnx copeg ..... for giving your time looking for the mistake ive done.... but i found it as well..


    i found out ...

    1.) the gui wont terminate if encountered any errors
    2.) my program doesnt have any statement that will execute if there is any errors...


    tnx for that copeg... and by the way.. what do you mean by a breakpoint?? whats that?

    any way copeg.. im not the one who wrote the DrawingBoard class, im read a book and im
    on a chapter that teaches about selection statements,
    and thats the exercise, unfortunately, the book didnt give me the code for the
    DrawingBoard class.. so i search the author's name in the net and i found the whole code for the DrawingBoard class,

    in otherwords.. i dont know how the DrawingBoard works.... how does it make the shpaes moving....
    its not yet easy for me to understand how this class works....


    any sir... is there any EASIER way to make the shapes move? i want to write my own., rather than
    push myself to understand this complex Class that ive got from the book..


    but any way.. the only classes that i wrote are the DrawableShape ,,, and the properties...


    tnx for that sir!

  5. #4
    Java kindergarten chronoz13's Avatar
    Join Date
    Mar 2009
    Location
    Philippines
    Posts
    659
    Thanks
    177
    Thanked 30 Times in 28 Posts

    Default Re: ERROR, I CANT DEFINE IT

    t might be easier in this case to use a SwingTimer, but either way you should update the gui (the repaint call) from the EDT (for example using SwingUtilities.invokeLater)
    is it on my Properties class? ...should i not use the SwingUtilities.invokeLater() in my Main method?

  6. #5
    Super Moderator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,099
    Thanks
    169
    Thanked 779 Times in 725 Posts
    Blog Entries
    5

    Default Re: ERROR, I CANT DEFINE IT

    Quote Originally Posted by chronoz13 View Post
    tnx copeg ..... for giving your time looking for the mistake ive done.... but i found it as well..


    i found out ...

    1.) the gui wont terminate if encountered any errors
    2.) my program doesnt have any statement that will execute if there is any errors...


    tnx for that copeg... and by the way.. what do you mean by a breakpoint?? whats that?

    any way copeg.. im not the one who wrote the DrawingBoard class, im read a book and im
    on a chapter that teaches about selection statements,
    and thats the exercise, unfortunately, the book didnt give me the code for the
    DrawingBoard class.. so i search the author's name in the net and i found the whole code for the DrawingBoard class,
    ahh I see.
    Breakpoints have to do with debugging. Although they won't solve all bugs, they allow you to stop at certain points and step through/into/and over methods and code during the execution to analyze variables and behavior. Read up on debugging and you'll get the idea. If you are using an IDE like Eclipse you can readily debug. I don't want to throw too many concepts out there at once so this isn't your code, don't worry too much about the GUI thread updating point, just keep it in the back of your mind for future reference.

  7. The Following User Says Thank You to copeg For This Useful Post:

    chronoz13 (December 1st, 2009)

  8. #6
    Java kindergarten chronoz13's Avatar
    Join Date
    Mar 2009
    Location
    Philippines
    Posts
    659
    Thanks
    177
    Thanked 30 Times in 28 Posts

    Default Re: ERROR, I CANT DEFINE IT

    ahhh .. thats an ease copeg... tnx sir........

    so i think what i red about Using swings. is that... it is better to use the SwingUtilities.invokeLater() when
    coding a GUI...

    tnx for that copeg.....

  9. #7
    Super Moderator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,099
    Thanks
    169
    Thanked 779 Times in 725 Posts
    Blog Entries
    5

    Default Re: ERROR, I CANT DEFINE IT

    Quote Originally Posted by chronoz13 View Post
    t is better to use the SwingUtilities.invokeLater() when
    coding a GUI...
    Only when using threads OTHER than the event dispatch thread. Its a long and somewhat complicated explanation that Sun microsystems can probably explain better than I can (see the link above), but suffice it to say Swing was written so that most functions/updates/etc..(unless otherwise stated in the API) should be handled in the event dispatch thread (EDT). As a general rule, if you spawn a new Thread, anything within the runnable interface of that thread that calls updates to Swing should be directed to the EDT using things like SwingUtilities.
    Last edited by copeg; December 1st, 2009 at 08:58 PM.

  10. The Following User Says Thank You to copeg For This Useful Post:

    chronoz13 (December 1st, 2009)

  11. #8
    Java kindergarten chronoz13's Avatar
    Join Date
    Mar 2009
    Location
    Philippines
    Posts
    659
    Thanks
    177
    Thanked 30 Times in 28 Posts

    Default Re: ERROR, I CANT DEFINE IT

    oh anyway.. i asked about the SwingUtilities.. because it happened to be that i was working on a simple GUI framei..

    a simple frame with JSliders... JButtons.... and i got a problem with adding the components,
    like setting the Bounds.. the appearance and disappearance of one J-object because of another
    J-object..,
    then one told me.. it has something to do with Layouts (i noticed it too)... then i search on sun's references then i saw
    section titled- AbsolutePositioning (no Layout manager) ..

    thats when i first encountered the SwingUtiliy class.. the .invokeLater() method...
    so now .. im using it in my main method... to call the GUI's .. then everything goes fine....