| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 437 人关注过本帖
标题:求助 一个miniproject
只看楼主 加入收藏
kategreat
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2006-6-4
收藏
 问题点数:0 回复次数:0 
求助 一个miniproject

下面是我碰到的一个java问题
A list of Web safe colours has been generated to guarantee that computers would display colours
correctly when using a 256 colour palette. There are many charts of such colours available, eg
http://www.web-source.net/216_color_chart.htm. Web safe colours can have only the following
hexadecimal values: FF, CC, 99, 66, 33, 00 – you should work out the corresponding values in RGB
notation. So #FF00FF and #CCFF99 are examples of Web safe colours while FF00BB or FFF0FF are
not. Create an applet that generates the red-based Web safe colours. These are identified as having red
value 255 (in RGB notation) or starting FF (in hexadecimal). For example, the colour Red is generated
by using RGB notation R=255, G=0, B=0 or the hexadecimal value #FF0000.
When a user presses the “generate colour” button a random colour (as described above) is produced.
After the colour has been displayed to the user, your GUI should have some method of allowing the user
to choose what colour the displayed colour most represents. For example, one method might be to have
buttons which the user could press labelled “red”, “pink”, “orange” or “yellow”. Your GUI should
ensure that the user cannot generate a new colour until they have decided what category the current
colour falls into. Your program should save this colour so that it cannot be generated again.
Note: The English spelling ‘colour’ is used when referring to colours, eg the colour red. The
American spelling Color is used when referring specifically to the Java Color class.
The applet should:
• Draw a window of 500 by 500 pixels with a BLACK background
• Have widgets for:
o Generating a colour
o Colour selection (ie. Red, Pink, Yellow and Orange)
• Contain an area that will change colour when the “generate colour” button is pressed
• Never display white in the colour changing area (ie RGB 255,255,255)
• Only allow the system to store a colour once
• Use inner classes for any event handling.
When all the colours have been sorted the GUI should be modified:
• The background of the applet should change to that of the final colour.
• The user should no longer be able to generate a colour.
• The applet should indicate how many colours the user identified as red, orange, yellow and pink
respectively.
• The RGB and hexadecimal values, plus the name (eg red) of the final colour should be displayed.
You should provide:
• A class called MyColour.java that subclasses Color with the following functionality:
o Indicating if a colour is white
o Returning the hexadecimal value of a colour.
• An applet class called ColourApplet.java
• An html file ColourApplet.html that loads the applet
-------------------------------------------------


下面是同学给我提供的他做的Colour.java文档
import java.awt.Color;
import java.lang.Integer;
import java.math.*;
public class MyColour
{
/**
* @param colourRGBParameter int[]
* @param colourHexParameter String[]
* @param ColourName String[]
* colourRGBParameter is use to store six parameters of the RGB colour form;
* colourHexParameter is use to store six parameters of the Hex colour form;
* ColourName is use to store five nouns of five different colours;
*/
int[] colourRGBParameter = {-1,255,204,153,102,51,0};
String[] colourHexParameter = {"","FF","CC","99","66","33","00"};
String[] ColourName = {"","Red","Orange","Yellow","Pink","Purple"};

/**
* @param colourCheck boolean[]
* colourCheck is use to store the estate of each colours,there is 36 colours in red-based web safe colour.
* each colour have two estate:true or false, and the default estate is false. It means that the colour never been generated before.
* if one colour has been generated, its estate will change to true and it will never been generated again.
*/
boolean[] colourCheck = new boolean[37];

/**
* @param pareGhex String
* @param pareBhex String
* @param pareGRGB String
* @param pareBRGB String
* pareGhex store the Hex number of G parameter get from the colourHexParameter;
* pareBhex store the Hex number of B parameter get from the colourHexParameter;
* pareGRGB store the decimal number of G parameter get from the colourHexParameter;
* pareBRGB store the decimal number of B parameter get from the colourHexParameter;
* Initialize those four variables.
*/
String pareGhex = "";
String pareBhex = "";
String pareGRGB = "";
String pareBRGB = "";

/**
* Initialize pareG and pareB.
*/
int pareG = 0;
int pareB = 0;

/**
* @param generateNew Color
* generateNew is use to store the colour that just generating from the method getNewColourRGB();
* Initialize it in black.
*/
Color generateNew = new Color(0,0,0);

/**
* This is the method to initialize colourCheck;
* colourCheck[0] and [1] will initialize to true so the colour white will never generate;
* from 2 to 36, it point to the 35 colours that will generate and initialize them to estate "false";
*/
public MyColour()
{
colourCheck[0] = true;
colourCheck[1] = true;
for(int i = 2; i <= 36; i++)
{
colourCheck[i] = false;
}
}

/**
* @param succeedGenerate boolean
* @param strX String
* @param strY String
* @param strXY String
* @param xyInt int
* @param colourNumber int
* this is the method generate a new colour both of its decimal form and Hex form.
* the colour is generated from red-based web safe colour without white colour(RGB 255,255,255) randomly.
*/
public void getNewColourRGB()
{
/**
* succeedGenerate is the condition variable of the while loop below;
* initialize it to false means that the new colour haven't generate successfully;
*/
boolean succeedGenerate = false;

/**
* the while loop will running until generate a new colour.
* one colour can only generate for one time.
*/
while(succeedGenerate == false)
{
/**
* pareG and pareB are random integer between 1 and 6.
*/
pareG = (int)(Math.random()*6 + 1);
pareB = (int)(Math.random()*6 + 1);

/**
* use Integer.toString(int) method the return a string of the integer;
* strX is the string of pareG;
* strY is the string of pareB;
* strXY is combination of strX and strY.
*/
String strX = Integer.toString(pareG);
String strY = Integer.toString(pareB);
String strXY = strX + strY;

/**
* use Integer.parseInt(string) to return a integer of the string strXY.
* colourNumber is the new sequence number of the 35 red-based web safe colour.
*/
int xyInt = Integer.parseInt(strXY);
int colourNumber = ((xyInt/10-1)*6 + (xyInt%10));

/**
* colourCheck[colourNumber] is the condition of if sentence.
* "colourCheck[colourNumber] = false" means that the colour of sequence number(colourNumber) never generate before.
*/
if(colourCheck[colourNumber] == false)
{
/**
* new colour generate and pass to variable generateNew;
* two parameter colourRGBParameter[pareG] and colourRGBParameter[pareB] deciding the colour.
*/
generateNew = new Color(255,colourRGBParameter[pareG],colourRGBParameter[pareB]);
//change the estate in colourCheck[] of this colour and it will never be generate again.
colourCheck[colourNumber] = true;
//change succeedGenerate to true then the loop will stop.
succeedGenerate = true;
/**
* pass the Hex number form in G of new colour to pareGhex;
* pass the Hex number form in B of new colour to pareBhex;
* use Integer.toString to pass the dicimal number form in G of the new colour to pareGRGB in the data type of string;
* use Integer.toString to pass the dicimal number form in B of the new colour to pareBRGB in the data type of string;
*/
pareGhex = colourHexParameter[pareG];
pareBhex = colourHexParameter[pareB];
pareGRGB = Integer.toString(colourRGBParameter[pareG]);
pareBRGB = Integer.toString(colourRGBParameter[pareB]);
}
}
}

/**
* @param colourHex String
* @return colourHex
* this is the method to get the Hex number of the new colour in data type string.
* colourHex is the Hex form of the new colour in data type of string.
* it is the combination of colourHexParameter[1], pareGhex and pareBhex.
*/
public String getNewColourHex()
{
String colourHex = "#" + colourHexParameter[1] + pareGhex + pareBhex;
return colourHex;
}

/**
* @param colourRGBString String
* @return colourRGBString
* this is the method to get the decimal number of the new colour in data type string.
* colourRGBString is the deciaml form of the new colour in data type of string.
* it is the combination of "R", colourRGBParameter[1], "G", pareGRGB, "B" and pareBRGB.
*/
public String getNewColourRGBString()
{
String colourRGBString = "R" + colourRGBParameter[1] + "G" + pareGRGB + "B" + pareBRGB;
return colourRGBString;
}

/**
* @return generateNew
* this is the method to get the new generated colour.
*/
public Color getNewColour()
{
return generateNew;
}

/**
* @return ColourName[int]
* this is the method to get the name of new colour.
* five if sentences are use to estimate the name of the colour.
*/
public String getNewColourName()
{
if(pareG == 1)
return ColourName[3];
else if(pareG >= 4 && pareB >= 5)
return ColourName[1];
else if(pareG <= 3 && pareG >= 2 && pareB >= 4)
return ColourName[2];
else if(pareG <= 3 && pareG >= 2 && pareB == 3)
return ColourName[4];
else if(pareG >= 4 && pareB == 4)
return ColourName[4];
else
return ColourName[5];
}
}


我在中间的关于定义的
String strX = Integer.toString(pareG);
String strY = Integer.toString(pareB);
String strXY = strX + strY;

/**
* use Integer.parseInt(string) to return a integer of the string strXY.
* colourNumber is the new sequence number of the 35 red-based web safe colour.
*/
int xyInt = Integer.parseInt(strXY);
int colourNumber = ((xyInt/10-1)*6 + (xyInt%10));
这一部分和最后的
/**
* @return ColourName[int]
* this is the method to get the name of new colour.
* five if sentences are use to estimate the name of the colour.
*/
public String getNewColourName()
{
if(pareG == 1)
return ColourName[3];
else if(pareG >= 4 && pareB >= 5)
return ColourName[1];
else if(pareG <= 3 && pareG >= 2 && pareB >= 4)
return ColourName[2];
else if(pareG <= 3 && pareG >= 2 && pareB == 3)
return ColourName[4];
else if(pareG >= 4 && pareB == 4)
return ColourName[4];
else
return ColourName[5];
}
不太理解
那个colourname是随机出来的两个数对应的一个固定的值好像 在后面的如果遇到的话可以判断为出现过了 就不会出现于是随机出来的两个颜色的GB值就不会重复但知道意思看不懂内容。。。
后面的那些if else据说用在applet里面。。但我研究了好几天 这个还没看懂。。。
有高手能指导一下 或者提供下更简单的程序吗?
ps:那个colour中的while部分个人感觉前一部分的随机数一直在生成只是后面的if才没继续下去 缺点很大
另外colour我差不多懂了 有高手能联系提供的内容提供个applet吗 或者是不拘泥已经提供的colour的个人设计


深夜求助 忘高手献身。。。
找了好久逛了好多论坛 一直没找到类似的课题 谢谢大家了 ^_^

搜索更多相关主题的帖子: miniproject 
2006-06-04 01:36
快速回复:求助 一个miniproject
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.020360 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved