can anyone explain

publicclass ScrollingMessage

{

static String message ="this message scrolls with the aid " +

"of a timer from the javax.swing.Timer class . . . ";

staticint letterCount = 0;

publicstaticvoid main(String[] args)

{

final JTextField tf =new JTextField(30);

tf.setMargin(new Insets(0,10,0,10));

tf.setEditable(false);

tf.setFont(new Font("monospace", Font.PLAIN, 16));

tf.setText(message);

final String[] letters = message.split("(?<=[\\w\\d\\s])");

Timer timer =new Timer(250,new ActionListener()

{

publicvoid actionPerformed(ActionEvent e)

{

String text = tf.getText().substring(1) +

letters[letterCount++ % letters.length];

tf.setText(text);

}

});

timer.start();

JFrame f =new JFrame();

f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

f.getContentPane().add(tf,"South");

f.setSize(300,150);

f.setLocationRelativeTo(null);

f.setVisible(true);

}

From the code above can anyone explain what this line does?final String[] letters = message.split("(?<=[\\w\\d\\s])");

secondly how do i use 1 string instead of 2 strings for the scrolltext and how can i make the text scroll from left to right? Hope anyone could give a help explaining. thanks alot.

[2412 byte] By [sarah007a] at [2007-11-27 9:44:46]
# 1

> ...

> From the code above can anyone explain what

> this line does?

>

> final String[] letters = message.split("(?<=[\\w\\d\\s])");

It splits the String 'message' based upon a rather strange regex. I believe the author tried to replicate String's toCharArray() method.

You can see what it returns by printing the array the method returns.

It splits 'message' at every i-th index, where index i-1 is either a word-character (\\w), a decimal (\\d) or a space character (\\s).

(?<=X)Y matches Y, but only if it has X behind it (it's called positive lookbehind)

[XYZ] is called a character class and means either X, Y or Z.

Details: http://java.sun.com/j2se/1.4.2/docs/api/java/util/regex/Pattern.html

> secondly how

> do i use 1 string instead of 2 strings for the

> scrolltext and how can i make the text scroll from

> left to right? Hope anyone could give a help

> explaining. thanks alot.

Ask the author of that code to do it?

prometheuzza at 2007-7-12 23:52:10 > top of Java-index,Java Essentials,Java Programming...