From ggc
|
001 packagepackage is used to name the directory or folder a class is in jam;
002
003 importimport means to make the classes and/or packages available in this program fang.*;
004 importimport means to make the classes and/or packages available in this program java.awt.*;
005 importimport means to make the classes and/or packages available in this program java.awt.geom.*;
006
007 importimport means to make the classes and/or packages available in this program java.awt.Color;
008 importimport means to make the classes and/or packages available in this program java.util.ArrayList;
009 importimport means to make the classes and/or packages available in this program java.util.Map;
010
011 /**
012 * This program shows all of the colors
013 * that have names.
014 * @authorthis is the Javadoc tag for documenting who created the source code Jam Jenkins
015 *
016 */
017 publicpublic is used to indicate unrestricted access (any other class can have access) classclass is a group of fields and methods used for making objects PaletteTest extendsextends means to customize or extend the functionality of a class Game
018 {open braces start code blocks and must be matched with a close brace
019 /**the color swatches*/
020 privateprivate is used to restrict access to the current class only ArrayList<Sprite> square;
021 /**the name of the color*/
022 privateprivate is used to restrict access to the current class only StringSprite colorLabel;
023 /**sample code*/
024 privateprivate is used to restrict access to the current class only StringSprite codeLabel;
025
026 /**makes and adds the sprites*/
027 @Override
028 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value setup()
029 {open braces start code blocks and must be matched with a close brace
030 makeSprites();
031 addSprites();
032 //setHelp("resources/RainbowHelp.txt");
033 //startGameImmediately();
034 }close braces end code blocks and must match an earlier open brace
035
036 /**makes a sprite square forfor is a looping structure for repeatedly executing a block of code each color and
037 * adds the to the screen in a matrix.
038 */
039 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value makeSprites()
040 {open braces start code blocks and must be matched with a close brace
041 //adds a color to the palette
042 addColor("Custom Added", "#e0E68C");
043
044 //holds all of the square colors
045 square =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor ArrayList<Sprite>();
046
047 //makes a square per color
048 Map<String, Color> map =this assignment operator makes the left side equal to the right side Palette.getColorMap();
049 longlong is the type for whole numbers (they have a larger range than int) rows =this assignment operator makes the left side equal to the right side Math.round(0.5 +adds two numbers together or concatenates Strings together Math.sqrt(map.size()));
050 longlong is the type for whole numbers (they have a larger range than int) cols =this assignment operator makes the left side equal to the right side rows;
051 intint is the type for whole numbers and it is short for integer r =this assignment operator makes the left side equal to the right side 0;
052 intint is the type for whole numbers and it is short for integer c =this assignment operator makes the left side equal to the right side 0;
053 forfor is a looping structure for repeatedly executing a block of code (Color color: map.values())
054 {open braces start code blocks and must be matched with a close brace
055 Sprite sprite =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor RectangleSprite(1, 0.75);
056 sprite.setScale(1.0 / rows);
057 sprite.setLocation((r +adds two numbers together or concatenates Strings together 0.5) / rows,
058 0.75*(c +adds two numbers together or concatenates Strings together 0.5) / cols);
059 sprite.setColor(color);
060 square.add(sprite);
061 r++this is the increment operator, which increases the variable by 1;
062 ifif executes the next statement only if the condition in parenthesis evaluates to true (r >=this evaluates to true if the left side is not less than the right side rows)
063 {open braces start code blocks and must be matched with a close brace
064 r =this assignment operator makes the left side equal to the right side 0;
065 c++this is the increment operator, which increases the variable by 1;
066 }close braces end code blocks and must match an earlier open brace
067 }close braces end code blocks and must match an earlier open brace
068 colorLabel =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor StringSprite("Color");
069 colorLabel.bottomJustify();
070 colorLabel.setLocation(0.5, 0.9);
071 colorLabel.setHeight(0.1);
072 codeLabel=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor StringSprite("sprite.setColor(Palette.getColor(\""+adds two numbers together or concatenates Strings together"Color"+adds two numbers together or concatenates Strings together"\"));");
073 codeLabel.setWidth(0.9);
074 codeLabel.bottomJustify();
075 codeLabel.leftJustify();
076 codeLabel.setLocation(0.05, 0.95);
077 codeLabel.setColor(Palette.getColor("White"));
078 ifif executes the next statement only if the condition in parenthesis evaluates to true (colorLabel.getWidth() > 0.9)
079 {open braces start code blocks and must be matched with a close brace
080 colorLabel.setWidth(0.9);
081 }close braces end code blocks and must match an earlier open brace
082 colorLabel.setColor(Palette.getColor("white", 200));
083 }close braces end code blocks and must match an earlier open brace
084
085 /**adds all of the sprites*/
086 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value addSprites()
087 {open braces start code blocks and must be matched with a close brace
088 addSprite(square.toArray(newnew is used to create objects by calling the constructor Sprite[brackets are typically used to declare, initialize and index (indicate which element of) arrays0]brackets are typically used to declare, initialize and index (indicate which element of) arrays));
089 addSprite(colorLabel);
090 addSprite(codeLabel);
091 }close braces end code blocks and must match an earlier open brace
092
093 /**makes the mouse moving over a color
094 * display the color's name
095 * @paramthis is the Javadoc tag for documenting the purpose of parameters timePassed not used
096 */
097 @Override
098 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value advance()
099 {open braces start code blocks and must be matched with a close brace
100 //System.out.println("Game is "+getCurrentGame());
101 forfor is a looping structure for repeatedly executing a block of code (Sprite sprite: square)
102 {open braces start code blocks and must be matched with a close brace
103 ifif executes the next statement only if the condition in parenthesis evaluates to true (sprite.intersects(getMouse2D()))
104 {open braces start code blocks and must be matched with a close brace
105 //System.out.println("colorLabel: "+colorLabel);
106 colorLabel.setText(getColorName(sprite.getColor()));
107 colorLabel.setHeight(0.1);
108 ifif executes the next statement only if the condition in parenthesis evaluates to true (colorLabel.getWidth() > 0.9)
109 {open braces start code blocks and must be matched with a close brace
110 colorLabel.setWidth(0.9);
111 }close braces end code blocks and must match an earlier open brace
112 codeLabel.setText("sprite.setColor(Palette.getColor(\""+adds two numbers together or concatenates Strings together
113 colorLabel.getText()+adds two numbers together or concatenates Strings together"\"));");
114 codeLabel.setWidth(0.9);
115
116 }close braces end code blocks and must match an earlier open brace
117 }close braces end code blocks and must match an earlier open brace
118 }close braces end code blocks and must match an earlier open brace
119 }close braces end code blocks and must match an earlier open brace
|
Download/View jam/PaletteTest.java