top-post...

A

Andrew Thompson

<asbestos suit>
I have encountered so many threads
tonight that were disjointed by
top-posting that I writ this..
___________________
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.BevelBorder;
import java.util.StringTokenizer;

/** GUI for the ReverseText class. */
public class ReverseFrame
extends JFrame implements KeyListener
{
int rows = 10, cols = 20;
JTextArea taIn = new JTextArea(rows, cols),
taOut = new JTextArea(rows, cols);
JCheckBox cbLine = new JCheckBox("Lines", true),
cbLetter = new JCheckBox("Characters", false);

/** Creates a ReverseText GUI. */
public ReverseFrame()
{
super("Reverse Text");

JPanel pMain = new JPanel( new BorderLayout() ),
pIO = new JPanel( new GridLayout(0,1) ),
pControl = new JPanel();

taIn.setBorder( new BevelBorder(BevelBorder.LOWERED) );
taIn.addKeyListener( this );
pIO.add( taIn );
taOut.setBorder( new BevelBorder(BevelBorder.LOWERED) );
pIO.add( taOut );
pMain.add( pIO, BorderLayout.CENTER );

pControl.add( new JLabel("Reverse:") );
pControl.add( cbLine );
pControl.add( cbLetter );
pMain.add( pControl, BorderLayout.NORTH );

setDefaultCloseOperation(
WindowConstants.DISPOSE_ON_CLOSE );

setContentPane( pMain );
pack();
validate();

setSize( getPreferredSize() );
setLocation(500,25);
taIn.requestFocus();
}


public void keyTyped(KeyEvent ke) {}
public void keyPressed(KeyEvent ke) {}
public void keyReleased(KeyEvent ke)
{
taOut.setText( ReverseText.reverse( taIn.getText(),
cbLine.isSelected(), cbLetter.isSelected() ) );
}

public static void main(String[] args)
{
ReverseFrame rf = new ReverseFrame();
rf.setVisible(true);
}
}

/** A class that demonstrates the
disadvantages of top-posting. */
class ReverseText
{
//private static final boolean TEST = false;

/** Reverses lines and/or letters according to the
two booleans. */
public static String reverse( String s,
boolean lines, boolean letters )
{
return reverseLine(s, lines, letters);
}

/** Swaps the order of the lines. */
public static String reverseLine(
String s, boolean lines, boolean letters )
{
StringTokenizer st = new StringTokenizer(s, "\n");
int ii = st.countTokens();

String[] sAll = new String[ ii ];

// put the lines in the array in reverse order
while( st.hasMoreTokens() )
{
sAll[--ii] = st.nextToken();
}

// now read them into the StringBuffer in that order
StringBuffer sb = new StringBuffer();
for (ii=0; ii<sAll.length; ii++)
{
sb.append( reverseLetter(sAll[ii], letters) + "\n" );
}

return sb.toString();
}

/** Swaps the order of the letters. */
public static String reverseLetter(String s, boolean letters)
{
if (!letters) return s;
else
{
StringBuffer sb = new StringBuffer();
for (int ii=s.length()-1; ii>-1; ii--)
{
sb.append( s.substring( ii, ii+1) );
}
return sb.toString();
}
}
}
___________________
I must be _really_ bored..
</asbestos suit>

Now, I must get on with things that
are (hopefully) _not_ going to attract
abuse and derision.. ;-)
 
N

nos

what does it do?


Andrew Thompson said:
<asbestos suit>
I have encountered so many threads
tonight that were disjointed by
top-posting that I writ this..
___________________
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.BevelBorder;
import java.util.StringTokenizer;

/** GUI for the ReverseText class. */
public class ReverseFrame
extends JFrame implements KeyListener
{
int rows = 10, cols = 20;
JTextArea taIn = new JTextArea(rows, cols),
taOut = new JTextArea(rows, cols);
JCheckBox cbLine = new JCheckBox("Lines", true),
cbLetter = new JCheckBox("Characters", false);

/** Creates a ReverseText GUI. */
public ReverseFrame()
{
super("Reverse Text");

JPanel pMain = new JPanel( new BorderLayout() ),
pIO = new JPanel( new GridLayout(0,1) ),
pControl = new JPanel();

taIn.setBorder( new BevelBorder(BevelBorder.LOWERED) );
taIn.addKeyListener( this );
pIO.add( taIn );
taOut.setBorder( new BevelBorder(BevelBorder.LOWERED) );
pIO.add( taOut );
pMain.add( pIO, BorderLayout.CENTER );

pControl.add( new JLabel("Reverse:") );
pControl.add( cbLine );
pControl.add( cbLetter );
pMain.add( pControl, BorderLayout.NORTH );

setDefaultCloseOperation(
WindowConstants.DISPOSE_ON_CLOSE );

setContentPane( pMain );
pack();
validate();

setSize( getPreferredSize() );
setLocation(500,25);
taIn.requestFocus();
}


public void keyTyped(KeyEvent ke) {}
public void keyPressed(KeyEvent ke) {}
public void keyReleased(KeyEvent ke)
{
taOut.setText( ReverseText.reverse( taIn.getText(),
cbLine.isSelected(), cbLetter.isSelected() ) );
}

public static void main(String[] args)
{
ReverseFrame rf = new ReverseFrame();
rf.setVisible(true);
}
}

/** A class that demonstrates the
disadvantages of top-posting. */
class ReverseText
{
//private static final boolean TEST = false;

/** Reverses lines and/or letters according to the
two booleans. */
public static String reverse( String s,
boolean lines, boolean letters )
{
return reverseLine(s, lines, letters);
}

/** Swaps the order of the lines. */
public static String reverseLine(
String s, boolean lines, boolean letters )
{
StringTokenizer st = new StringTokenizer(s, "\n");
int ii = st.countTokens();

String[] sAll = new String[ ii ];

// put the lines in the array in reverse order
while( st.hasMoreTokens() )
{
sAll[--ii] = st.nextToken();
}

// now read them into the StringBuffer in that order
StringBuffer sb = new StringBuffer();
for (ii=0; ii<sAll.length; ii++)
{
sb.append( reverseLetter(sAll[ii], letters) + "\n" );
}

return sb.toString();
}

/** Swaps the order of the letters. */
public static String reverseLetter(String s, boolean letters)
{
if (!letters) return s;
else
{
StringBuffer sb = new StringBuffer();
for (int ii=s.length()-1; ii>-1; ii--)
{
sb.append( s.substring( ii, ii+1) );
}
return sb.toString();
}
}
}
___________________
I must be _really_ bored..
</asbestos suit>

Now, I must get on with things that
are (hopefully) _not_ going to attract
abuse and derision.. ;-)

--
Andrew Thompson
* http://www.PhySci.org/ PhySci software suite
* http://www.1point1C.org/ 1.1C - Superluminal!
* http://www.AThompson.info/andrew/ personal site
 
T

Tris Orendorff

| what does it do?

What does what do?

It's supposed to make you pop your cork. Notice that "nos" top-posted
"what does it do?"

--
-----BEGIN GEEK CODE BLOCK-----
Version: 3.12
GCS d++ s+:- a+ C+ UL++++ P+ L+ E- W+ N++ o- K++ w+ O+ M !V PS+ PE Y+ PGP
t+ !5 X- R- tv--- b++ DI++ D+ G++ e++ h---- r+++ y+++
------END GEEK CODE BLOCK------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top