Re: top-post...

From: nos (nos_at_nospam.com)
Date: 01/20/04


Date: Tue, 20 Jan 2004 18:40:21 GMT

what does it do?

"Andrew Thompson" <andrew64@bigNOSPAMpond.com> wrote in message
news:zhePb.20610$Wa.8711@news-server.bigpond.net.au...
> <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
>
>



Relevant Pages

  • im still here ...
    ... public void paintComponent{ ... public static String setAlarm(String theAlarm,String theTime){ ...
    (comp.lang.java.help)
  • Re: JTable help
    ... interActiveJatable and the resultObject: ... public void setClassCode{ ... public static final int CLASS_INDEX = 1; ...
    (comp.lang.java.help)
  • RE: Object Name
    ... An unhandled exception of type 'System.NullReferenceException' occurred in System.Windows.Forms.dll ... public static string GetControlName ... >> It seam there is no name properties. ... >> public void SetDataInputField ...
    (microsoft.public.pocketpc.developer)
  • Re: Array of Objects
    ... > public static String y; ... public void pusht ... they have class scope rather than instance scope. ...
    (comp.lang.java.programmer)