Results 1 to 3 of 3
  1. #1
    zaz_rin is offline Member
    Join Date
    Jul 2009
    Posts
    4
    Rep Power
    0

    Default Java String Tokenizer

    Hai...i have 2 textarea and 1 button which user is able to input text/string into the first textarea and the tokenization string is display into the second textarea right after the button is clicked. Can anyone help me?

  2. #2
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    765
    Rep Power
    6

    Default

    show ur code and tell exactly where you are getting problem
    Ramya:cool:

  3. #3
    zaz_rin is offline Member
    Join Date
    Jul 2009
    Posts
    4
    Rep Power
    0

    Default

    import java.awt.BorderLayout;
    import java.awt.Container;
    import java.awt.Dimension;
    import java.awt.Font;
    import java.awt.GridBagConstraints;
    import java.awt.GridBagLayout;
    import java.awt.GridLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.BorderFactory;
    import javax.swing.JButton;
    import javax.swing.JComponent;
    import javax.swing.JEditorPane;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTextArea;
    import javax.swing.text.Style;
    import javax.swing.text.StyleConstants;
    import javax.swing.text.StyleContext;
    import javax.swing.text.StyledDocument;

    public class TextAreaTest extends JPanel implements ActionListener {
    private String newline = "\n";

    public TextAreaTest() {
    setLayout(new BorderLayout());

    //Lay out the text controls and the labels.
    JPanel textControlsPane = new JPanel();
    GridBagLayout gridbag = new GridBagLayout();
    GridBagConstraints c = new GridBagConstraints();

    textControlsPane.setLayout(gridbag);

    addLabelTextRows(gridbag, textControlsPane);

    c.gridwidth = GridBagConstraints.REMAINDER; //last
    c.anchor = GridBagConstraints.WEST;
    c.weightx = 1.0;


    //Create the first text area.
    JTextArea textArea = new JTextArea();
    textArea.setFont(new Font("Serif", Font.PLAIN, 16));
    textArea.setLineWrap(true);
    textArea.setWrapStyleWord(true);
    JScrollPane areaScrollPane = new JScrollPane(textArea);
    areaScrollPane.setVerticalScrollBarPolicy(JScrollP ane.VERTICAL_SCROLLBAR_ALWAYS);
    areaScrollPane.setPreferredSize(new Dimension(250, 250));
    areaScrollPane.setBorder(BorderFactory.createCompo undBorder(
    BorderFactory.createCompoundBorder(BorderFactory
    .createTitledBorder("Tokenization String"), BorderFactory
    .createEmptyBorder(5, 5, 5, 5)), areaScrollPane
    .getBorder()));

    //Create the second text area.
    JTextArea textArea2 = new JTextArea();
    textArea2.setFont(new Font("Serif", Font.PLAIN, 16));
    textArea2.setLineWrap(true);
    textArea2.setWrapStyleWord(true);
    JScrollPane areaScrollPane2 = new JScrollPane(textArea2);
    areaScrollPane2.setVerticalScrollBarPolicy(JScroll Pane.VERTICAL_SCROLLBAR_ALWAYS);
    areaScrollPane2.setPreferredSize(new Dimension(250, 250));
    areaScrollPane2.setBorder(BorderFactory.createComp oundBorder(
    BorderFactory.createCompoundBorder(BorderFactory
    .createTitledBorder("Enter Text Here"), BorderFactory
    .createEmptyBorder(5, 5, 5, 5)), areaScrollPane2
    .getBorder()));


    //Create a button.
    JButton button = new JButton("Tokenize");
    JPanel middlePane = new JPanel(new GridLayout(1, 0));
    button.setSize(2,2);
    middlePane.add(button);
    middlePane.setBorder(BorderFactory.createCompoundB order(BorderFactory
    .createTitledBorder("Buttons"), BorderFactory
    .createEmptyBorder(5, 5, 5, 5)));


    //Put everything together.
    JPanel rightPane = new JPanel(new BorderLayout());
    rightPane.add(areaScrollPane, BorderLayout.CENTER);

    JPanel leftPane = new JPanel(new BorderLayout());
    leftPane.add(areaScrollPane2, BorderLayout.PAGE_START);

    add(leftPane, BorderLayout.LINE_START);
    add(middlePane, BorderLayout.CENTER);
    add(rightPane, BorderLayout.LINE_END);

    }

    private void addLabelTextRows(GridBagLayout gridbag, Container container) {
    GridBagConstraints c = new GridBagConstraints();
    c.anchor = GridBagConstraints.EAST;


    }

    public void actionPerformed(ActionEvent e)
    {

    }


    protected void addStylesToDocument(StyledDocument doc) {
    //Initialize some styles.
    Style def = StyleContext.getDefaultStyleContext().getStyle(
    StyleContext.DEFAULT_STYLE);

    Style regular = doc.addStyle("regular", def);
    StyleConstants.setFontFamily(def, "SansSerif");

    Style s = doc.addStyle("italic", regular);
    StyleConstants.setItalic(s, true);

    s = doc.addStyle("bold", regular);
    StyleConstants.setBold(s, true);

    s = doc.addStyle("small", regular);
    StyleConstants.setFontSize(s, 10);

    s = doc.addStyle("large", regular);
    StyleConstants.setFontSize(s, 16);

    }


    private static void createAndShowGUI() {
    //Make sure we have nice window decorations.
    JFrame.setDefaultLookAndFeelDecorated(true);

    //Create and set up the window.
    JFrame frame = new JFrame("TextAreaTest");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);

    //Create and set up the content pane.
    JComponent newContentPane = new TextAreaTest();
    newContentPane.setOpaque(true); //content panes must be opaque
    frame.setContentPane(newContentPane);

    //Display the window.
    frame.pack();
    frame.setVisible(true);
    frame.setSize(800,300);
    }

    public static void main(String[] args) {
    //Schedule a job for the event-dispatching thread:
    //creating and showing this application's GUI.
    javax.swing.SwingUtilities.invokeLater(new Runnable() {
    public void run() {
    createAndShowGUI();
    }
    });
    }
    }




    1- i dont know how to make the button to be small...:(
    2- when user type a words in the left text area and click the button, the right text area will display the tokenize words..

    Thank you so much for your help..

Similar Threads

  1. String Tokenizer
    By viperlasson in forum New To Java
    Replies: 1
    Last Post: 03-09-2010, 01:14 PM
  2. String Tokenizer
    By redasu in forum Advanced Java
    Replies: 4
    Last Post: 02-19-2010, 03:30 AM
  3. string tokenizer
    By twinytwo in forum New To Java
    Replies: 2
    Last Post: 03-26-2009, 02:10 PM
  4. Problem with string tokenizer
    By twinytwo in forum AWT / Swing
    Replies: 2
    Last Post: 03-26-2009, 11:27 AM
  5. String Tokenizer And Arraya
    By everlast88az in forum Advanced Java
    Replies: 2
    Last Post: 11-06-2008, 11:20 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •