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

让你输入一段英文,然后利用Scrollbar控制RGB来改变里面元音的颜色,显示出来,最后还要显示出输入英文中各个元音的数量~~~~

题目大概如此吧,最后一步显示出元音的数量我不知道怎么解决~~~~~~~~~~~~~~查啦一些资料也没有找到类似的东西

希望有高人指点一下~~~~~`

[此贴子已经被作者于2006-1-19 20:06:17编辑过]

搜索更多相关主题的帖子: 英文 资料 
2006-01-12 22:19
Jhyvin
Rank: 2
等 级:新手上路
威 望:4
帖 子:81
专家分:0
注 册:2005-12-29
收藏
得分:0 

static int k=0;
String text=得到输入的英文;
for(i=0;i<text.lenth;i++){
if(text[i]==a||text[i]==A)
k++;
if(text[i]==e||text[i]==E)
k++;
if(text[i]==i||text[i]==I)
k++;
if(text[i]==o||text[i]==O)
k++;
if(text[i]==u||text[i]==U)
k++;
}
System.out.println("元音个数="+k);


一万年太久,只争朝夕! 从此不再乱翻书!!!
2006-01-13 10:07
nestor333
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2006-1-12
收藏
得分:0 

请问一下,可以写出完全的么

我是个新手,有些看不懂

不过还是谢谢啦

2006-01-13 20:48
nestor333
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2006-1-12
收藏
得分:0 

import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;

public class Oo extends Applet implements TextListener,AdjustmentListener,ActionListener{
Label title;
Label vowels;
TextField msginput;
String msg=null;
Button submit;
Scrollbar sliderred;
Scrollbar slidergreen;
Scrollbar sliderblue;
int sliderredValue=0;
int slidergreenValue=0;
int sliderblueValue=0;

public void init() {
title=new Label("INPUT TEXT");
msginput=new TextField();
vowels=new Label("COLOR OF VOWELS");
add(title);
add(msginput);
add(vowels);
sliderred= new Scrollbar(Scrollbar.HORIZONTAL,0,1,0,256);
add(sliderred);
slidergreen= new Scrollbar(Scrollbar.HORIZONTAL,0,1,0,256);
add(slidergreen);
sliderblue= new Scrollbar(Scrollbar.HORIZONTAL,0,1,0,256);
add(sliderblue);
submit=new Button("submit");
add(submit);
msginput.addTextListener(this);
sliderred.addAdjustmentListener(this);
slidergreen.addAdjustmentListener(this);
sliderblue.addAdjustmentListener(this);
submit.addActionListener(this);

}

public void textValueChanged(TextEvent event){
msg=msginput.getText();
repaint();
}

public void adjustmentValueChanged(AdjustmentEvent event){
sliderredValue=sliderred.getValue();
slidergreenValue=slidergreen.getValue();
sliderblueValue=sliderblue.getValue();
repaint();
}

public void actionPerformed(ActionEvent event){

sliderredValue=Integer.parseInt(msginput.getText());
slidergreenValue=Integer.parseInt(msginput.getText());
sliderblueValue=Integer.parseInt(msginput.getText());
repaint();

}

public void paint(Graphics g){
g.setColor(new Color(sliderredValue,slidergreenValue,sliderblueValue));
g.drawString("Vowels are displayed id RCB color of "+""+sliderredValue+","
+slidergreenValue+","+sliderblueValue+")",100,50);
g.drawString(msg,50,70);
}

}
我想用button去控制它,但有问题,希望高手能指教一下,谢谢啦~

[此贴子已经被作者于2006-1-15 21:44:03编辑过]

2006-01-14 10:11
Jhyvin
Rank: 2
等 级:新手上路
威 望:4
帖 子:81
专家分:0
注 册:2005-12-29
收藏
得分:0 
以下是引用nestor333在2006-1-13 20:48:00的发言:

请问一下,可以写出完全的么

我是个新手,有些看不懂

不过还是谢谢啦

最近考试 没空


一万年太久,只争朝夕! 从此不再乱翻书!!!
2006-01-14 23:13
nestor333
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2006-1-12
收藏
得分:0 

谢谢大家的帮助,这个我已经会啦,完成啦,大家看下还有什么可以简化的么

import java.awt.*;
import java.applet.*;
import java.awt.event.*;//import classes for handling of events
import javax.swing.*;

public class VowelAnalyzer extends Applet implements TextListener,AdjustmentListener,ActionListener {
Panel p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,p13;//declare new panels
Label input,color,red,green,blue;//declare the Label objects
TextField textfield;//declare textfield object
Scrollbar sliderred,slidergreen,sliderblue;//declare scrollbar objects
Button b1;//declare button object
String msg=null;//declare empty String msg
int count;//declare a loop variable
int sliderredValue,slidergreenValue,sliderblueValue=0;//initialize the integer to 0
int countA;//declare a loop variable
int countE;//declare a loop variable
int countI;//declare a loop variable
int countO;//declare a loop variable
int countU;//declare a loop variable

public void init() {//Initialize the applet
setBackground(Color.white);

input=new Label("Input Text : ");//create new label object
add(input);//add object to applet window

textfield=new TextField(30);//create new textfield object
add(textfield);//add object to applet window

color=new Label("Color Of Vowels : " );//create new label object
add(color);//add object to applet window

red=new Label("Red");//create new label object
add(red);//add object to applet window

green=new Label("Green");//create new label object
add(green);//add object to applet window

blue=new Label("Blue");//create new label object
add(blue);//add object to applet window

sliderred=new Scrollbar(Scrollbar.HORIZONTAL,0,1,0,256);//create new scrollbar object
add(sliderred);//add object to applet window

slidergreen=new Scrollbar(Scrollbar.HORIZONTAL,0,1,0,256);//create new scrollbar object
add(slidergreen);//add object to applet window

sliderblue=new Scrollbar(Scrollbar.HORIZONTAL,0,1,0,256);//create new scrollbar object
add(sliderblue);//add object to applet window

b1=new Button("Submit");//create new button object
add(b1);//add object to applet window
b1.addActionListener(this);//attach listener to object input

p1=new Panel();//create new panel
p2=new Panel();//create new panel
p3=new Panel();//create new panel
p4=new Panel();//create new panel
p5=new Panel();//create new panel
p6=new Panel();//create new panel
p7=new Panel();//create new panel
p8=new Panel();//create new panel
p9=new Panel();//create new panel
p10=new Panel();//create new panel
p11=new Panel();//create new panel
p12=new Panel();//create new panel
p13=new Panel();//create new panel


p10.setLayout(new FlowLayout(FlowLayout.CENTER,0,0));
p10.add(color);

p9.setLayout(new FlowLayout(FlowLayout.CENTER,0,0));
p9.add(textfield);

p8.setLayout(new FlowLayout(FlowLayout.CENTER,0,0));
p8.add(input);

p11.setLayout(new FlowLayout(FlowLayout.CENTER,0,0));
p11.add(red);

p12.setLayout(new FlowLayout(FlowLayout.CENTER,0,0));
p12.add(green);

p13.setLayout(new FlowLayout(FlowLayout.CENTER,0,0));
p13.add(blue);

p7.setLayout(new BorderLayout());//set Layout as BorderLayout
p7.add("North",p12);//add object to the Panel p6
p7.add("South",slidergreen);//add object to the Panel p6

p6.setLayout(new BorderLayout());//set Layout as BorderLayout
p6.add("North",p13);//add object to the Panel p5
p6.add("South",sliderblue);//add object to the Panel p5

p5.setLayout(new BorderLayout());//set Layout as BorderLayout
p5.add("North",p11);//add object to the Panel p4
p5.add("South",sliderred);//add object to the Panel p4

p4.setLayout(new GridLayout(1,3));//set Layout as BorderLayout
p4.add(p5);//add object to the Panel p3
p4.add(p7);//add object to the Panel p3
p4.add(p6);//add object to the Panel p3

p3.setLayout(new BorderLayout());//set Layout as BorderLayout
p3.add("North",p10);//add object to the Panel p2
p3.add("South",p4);//add object to the Panel p2

p2.setLayout(new BorderLayout());//set Layout as BorderLayout
p2.add("North",p8);//add object to the Panel p1
p2.add("South",p9);//add object to the Panel p1

p1.setLayout(new BorderLayout());//set Layout as BorderLayout
p1.add("North",p2);//add object to the Panel p
p1.add("Center",p3);//add object to the Panel p
p1.add("South",b1);//add object to the Panel p
add(p1);//add panel p to applet window

}//end init() method

public void textValueChanged(TextEvent e) {// to handle the text
repaint();//call for paint() method, refresh applet window
}//end of textValueChanged() method

public void adjustmentValueChanged(AdjustmentEvent event){ // to handle the scrollbar
repaint();//call for paint() method, refresh applet window
}//end of adjustmentValueChanged() method

public void actionPerformed(ActionEvent event){// to handle event
msg=textfield.getText();//read in text from user input
sliderredValue=sliderred.getValue();//get value from slider and store to sliderValue
slidergreenValue=slidergreen.getValue();//get value from slider1 and store to slider1Value
sliderblueValue=sliderblue.getValue();//get value from slider2 and store to slider2Value
reset();//call for reset() method
repaint();//call for paint() method, refresh applet window
}//end of actionPerformed() method

public void paint(Graphics g) {//paint method
g.drawString("Vowels are displayed in RGB color of ("+sliderredValue+","+slidergreenValue+","+sliderblueValue+").",0,200);
String Vowelx;//declare a String Vowelx
int location = 0;//declare and initialize location to 0
for(count=0;count<=msg.length()-1;count=count+1) {
Vowelx=msg.substring(count,count+1).toLowerCase();
if (Vowelx.equals("a") | Vowelx.equals("e") | Vowelx.equals("i") |
Vowelx.equals("o") | Vowelx.equals("u")) {
g.setColor(new Color(sliderredValue,slidergreenValue,sliderblueValue));//set color from values of individual scrollbars
}
else {//if above condition is FALSE
g.setColor(Color.black);//set color black
}
g.drawString(Vowelx + "", location,180);//execute statement after submit
location = location + 20;//increase value of location by 10
}//end for loop

g.setColor(Color.black);//set color black

//execute statement after submit
g.drawString("Occurrence of vowels: ", 0, 220 );//execute statement after submit

for(count=0;count<=msg.length()-1;count=count+1){
Vowelx=msg.substring(count,count+1).toLowerCase();
if (Vowelx.equals("a")) {
countA++;//count for vowel A
}
if (Vowelx.equals("e")) {
countE++;//count for vowel E
}
if (Vowelx.equals("i")) {
countI++;//count for vowel I
}
if (Vowelx.equals("o")) {
countO++;//count for vowel O
}
if (Vowelx.equals("u")) {
countU++;//count for vowel U
}
}//end for loop
if (countA!=0)
g.drawString("a: "+countA, 20, 240 );//execute statement after submit
if (countE!=0)
g.drawString("e: "+countE, 20, 260 );//execute statement after submit
if (countI!=0)
g.drawString("i: "+countI, 20, 280 );//execute statement after submit
if (countO!=0)
g.drawString("o: "+countO, 20, 300 );//execute statement after submit
if (countU!=0)
g.drawString("u: "+countU, 20, 320);//execute statement after submit

}//end paint() method

public void reset() {
countA = 0; // keep A
countE = 0; // keep E
countI = 0; // keep I
countO = 0; // keep O
countU = 0; // keep U

}//end reset() method
}//end class

2006-01-19 20:06
快速回复:[求助]谢谢大家的帮助,我已经完成啦
数据加载中...
 
   



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

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