I'm having the hardest time finding out how to code how many words there are in the input for the JTextField, I have a set a clear input button, and once I figure out how to find out how many words there are, I'll be able to clear that as well. Thanks guys here's my code!
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class CopyTextPanel extends JPanel
{
private JTextField input;
private JLabel output, inlabel, outlabel;
private JButton compute, clear;
private JPanel panel;
public CopyTextPanel()
{
inlabel = new JLabel("Input Text: ");
outlabel = new JLabel("Text Statistics Results: ");
input = new JTextField (" ", 25);
output = new JLabel();
compute = new JButton("Compute Statistics");
compute.addActionListener (new ButtonListener());
clear = new JButton("Clear Text");
clear.addActionListener (new ButtonListener());
panel = new JPanel();
output.setPreferredSize (new Dimension(550, 30));
panel.setPreferredSize (new Dimension(620, 100));
panel.setBackground(Color.gray);
panel.add(inlabel);
panel.add(input);
//panel.add(outlabel);
//panel.add(output);
panel.add(compute);
panel.add(clear);
panel.add(outlabel);
panel.add(output);
setPreferredSize (new Dimension(700, 150));
setBackground(Color.cyan);
add(panel);
}
private class ButtonListener implements ActionListener
{
public void actionPerformed (ActionEvent event)
{
if (event.getSource()==compute)
{
{
output.setText (input.getText());
}
}
else
input.setText("");
}
}