Java Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingJava Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old September 9th, 2003, 11:36 PM
Curwa Curwa is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 1 Curwa User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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

}

Reply With Quote
  #2  
Old September 10th, 2003, 07:17 AM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
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?

Reply With Quote
  #3  
Old September 11th, 2003, 06:36 PM
FrankieShakes FrankieShakes is offline
Frank The Tank!
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: Jun 2002
Location: Toronto, Canada
Posts: 1,246 FrankieShakes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
Send a message via ICQ to FrankieShakes Send a message via MSN to FrankieShakes
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

Reply With Quote
  #4  
Old April 28th, 2004, 02:42 PM
orozcom orozcom is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 3 orozcom User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.*;

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJava Development > Java code Help


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT