summaryrefslogtreecommitdiffstats
path: root/qtjava/javalib/examples/rot13/Rot13.java
blob: 67c2ee7fb6f9229df91d1349904dfa3579ef0e3b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/***************************************************************************
* $Id$
**
* Definition of something or other
**
* Created : 979899
**
* Copyright (C) 1997 by Trolltech AS.  All rights reserved.
**
* This file is part of an example program for Qt.  This example
* program may be used, distributed and modified without limitation.
**
****************************************************************************/

import org.kde.qt.*;


class Rot13 extends TQWidget {
private    TQMultiLineEdit  left,  right;



Rot13()
{
    left = new TQMultiLineEdit( this, "left" );
    right = new TQMultiLineEdit( this, "right" );
    connect( left, SIGNAL("textChanged()"), this, SLOT("changeRight()") );
    connect( right, SIGNAL("textChanged()"), this, SLOT("changeLeft()") );

    TQPushButton  quit = new TQPushButton( "&Quit", this );
    quit.setFocusPolicy( NoFocus );
    connect( quit, SIGNAL("clicked()"), qApp(), SLOT("quit()") );

    TQGridLayout  l = new TQGridLayout( this, 2, 2, 5 );
    l.addWidget( left, 0, 0 );
    l.addWidget( right, 0, 1 );
    l.addWidget( quit, 1, 1, AlignRight );

    left.setFocus();
}


void changeLeft()
{
    left.blockSignals( true );
    left.setText( rot13( right.text() ) );
    left.blockSignals( false );
}


void changeRight()
{
    right.blockSignals( true );
    right.setText( rot13( left.text() ) );
    right.blockSignals( false );
}


String rot13( String  input )
{
    char[] r = input.toCharArray();
    int i = r.length;
    while( i-- != 0 ) {
	if ( r[i] >= (int) 'A' && r[i] <= (int) 'M' ||
	     r[i] >= (int) 'a' && r[i] <= (int) 'm' )
	    r[i] = (char) (r[i] + 13);
	else if  ( r[i] >= (int) 'N' && r[i] <= (int) 'Z' ||
		   r[i] >= (int) 'n' && r[i] <= (int) 'z' )
	    r[i] = (char) (r[i] - 13);
    }
    return new String(r);
}


public static void main(String[] args)
{
    TQApplication a = new TQApplication( args );
    Rot13 r = new Rot13();
    r.resize( 400, 400 );
    a.setMainWidget( r );
    r.setCaption("Qt Example - ROT13");
    r.show();
    a.exec();
    return;
}

	static {
		qtjava.initialize();
	}
}