Results 1 to 3 of 3
Thread: Java String Tokenizer
- 03-15-2010, 09:42 AM #1
Member
- Join Date
- Jul 2009
- Posts
- 4
- Rep Power
- 0
- 03-15-2010, 10:03 AM #2
show ur code and tell exactly where you are getting problem
Ramya:cool:
- 03-17-2010, 04:17 AM #3
Member
- Join Date
- Jul 2009
- Posts
- 4
- Rep Power
- 0
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
-
String Tokenizer
By viperlasson in forum New To JavaReplies: 1Last Post: 03-09-2010, 01:14 PM -
String Tokenizer
By redasu in forum Advanced JavaReplies: 4Last Post: 02-19-2010, 03:30 AM -
string tokenizer
By twinytwo in forum New To JavaReplies: 2Last Post: 03-26-2009, 02:10 PM -
Problem with string tokenizer
By twinytwo in forum AWT / SwingReplies: 2Last Post: 03-26-2009, 11:27 AM -
String Tokenizer And Arraya
By everlast88az in forum Advanced JavaReplies: 2Last Post: 11-06-2008, 11:20 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks