Hi all,
Im fairly (very) new to coding. now I have this school project I need to do for IT which is due tonight.
Basicly what I have to do is count the amount of words and letters in a string using what we know, which is not much...
What I was thinking of doing was the following:
enter string
count the length
substring it (using a while or for statement together with the lenght)
test those substrings against being a space or a letter
Count them up and print them.
I'm using visualcafe and the only thing I need to worry about is the actionperformed which is at the bottom of my code.
Here is the code of my mock-up that I have so far:
/*
A basic extension of the java.applet.Applet class
*/
import java.awt.*;
import java.applet.*;
public class Applet1 extends Applet
{
public void init()
{
// Take out this line if you don't use symantec.itools.net.RelativeURL or symantec.itools.awt.util.StatusScroller
symantec.itools.lang.Context.setApplet(this);
// This code is automatically generated by Visual Cafe when you add
// components to the visual environment. It instantiates and initializes
// the components. To modify the code, only use code syntax that matches
// what Visual Cafe can generate, or Visual Cafe may be unable to back
// parse your Java file into its visual environment.
//{{INIT_CONTROLS
setLayout(null);
setBackground(java.awt.Color.lightGray);
setSize(426,266);
add(InvoerVeld);
InvoerVeld.setBounds(36,24,100,40);
DoeKnop.setLabel("Bereken tekens");
add(DoeKnop);
DoeKnop.setBackground(java.awt.Color.lightGray);
DoeKnop.setBounds(12,84,120,40);
add(UitvoerTekens);
UitvoerTekens.setBounds(24,168,100,40);
add(UitvoerWoorden);
UitvoerWoorden.setBounds(144,168,100,40);
add(UitvoerLetters);
UitvoerLetters.setBounds(264,168,100,40);
//}}
//{{REGISTER_LISTENERS
SymAction lSymAction = new SymAction();
DoeKnop.addActionListener(lSymAction);
//}}
}
//{{DECLARE_CONTROLS
java.awt.TextField InvoerVeld = new java.awt.TextField();
java.awt.Button DoeKnop = new java.awt.Button();
java.awt.TextField UitvoerTekens = new java.awt.TextField();
java.awt.TextField UitvoerWoorden = new java.awt.TextField();
java.awt.TextField UitvoerLetters = new java.awt.TextField();
//}}
class SymAction implements java.awt.event.ActionListener
{
public void actionPerformed(java.awt.event.ActionEvent event)
{
Object object = event.getSource();
if (object == DoeKnop)
DoeKnop_ActionPerformed(event);
}
}
void DoeKnop_ActionPerformed(java.awt.event.ActionEvent event)
{
String entry;
entry = InvoerVeld.getText();
int characters;
characters = entry.length();
UitvoerTekens.setText(Integer.toString(characters));
int countLetters;
countLetters = 0;
int countWords;
countWords = 1;
for (int i = 1; i <= characters; i++)
{
entry.substring(a,b);
}
UitvoerWoorden.setText(Integer.toString(tellerWoorden));
UitvoerLetters.setText(Integer.toString(tellerLetters));
}
}