|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Java code Help
I tried many ways to make this code work. It needs an html applet to run. Half of it works, the other half im having trouble with. Any help would be great. Thanks.
Code:
public class test extends JApplet implements ActionListener {
private JLabel sentLabel;
private JTextField sentence;
private JTextArea outputArea;
int array[ ];
int len,len2,pick;
char letter;
public void init( )
{
//set up window
Container container = getContentPane( );
container.setLayout( new FlowLayout ( ) ); //change layout
//set up textLabel and textField
sentLabel = new JLabel("Enter a sentence: ");
container.add(sentLabel);
sentence = new JTextField(60);
container.add(sentence);
//add listener
sentence.addActionListener(this);
} //end of init method
public void actionPerformed (ActionEvent event)
{
//create array and populate
array = new int[25];
for (int b=0; b<array.length; b++)
{ array[ b ] = 0; }
//take sentence, put it on status line, and clear textbox
String message = sentence.getText();
showStatus(message);
sentence.setText(" ");
//---------------------------- Everything Works above -------
len = message.length(); //get length of string
//search string with array
for(int j=0; j < len; j++) {
letter = message.charAt(j); //get character from string
char chlet = Character.toUpperCase(letter); //change character to Upper case
pick = ((int)(chlet)); //casting letter to ASCII
//increment array with character count
if (pick >= 65 || pick <= 90)
{
array[pick-65]++;
}
}
len2 = array.length;
for(int p=0; p < len2;p++)
{outputArea.setText(" "+array[p]);}
}//end of actionPerformed
}
|
|
#2
|
||||
|
||||
|
You might want to post something about the nature of the error you're getting. If all you post is that half of it works, all I can post is that it must be broken. Not very helpful, huh?
|
|
#3
|
|||
|
|||
|
Curwa,
DHouston's right... It's tough to determine the problem without knowing the error you're receiving...
__________________
____________________________________________ Developer Shed Weekly Writer | DevArticles Forum Moderator Build Your Own KlipFolio Klip With PHP FrankManno.com - Under Construction Design Interactive Group - Under Construction |
|
#4
|
|||
|
|||
|
to Curwa
I did not see any imports, do you have these in your code?
import javax.swing.*; import javax.swing.text.*; import java.awt.*; import java.awt.event.*; import java.applet.*; |
![]() |
| Viewing: Dev Articles Community Forums > Programming > Java Development > Java code Help |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|