Last active
May 7, 2016 21:53
-
-
Save tinkerstudent/4205b09f93ea1d2b1361aa9e45d06710 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.tinkeracademy.projects; | |
import java.awt.event.ActionEvent; | |
import java.awt.event.ActionListener; | |
import javax.swing.JButton; | |
import javax.swing.JTextArea; | |
public class FlipText implements ActionListener { | |
public JButton button; | |
public JTextArea input; | |
public JTextArea outputTextArea; | |
public static void main(String[] args) { | |
FlipText flipText = new FlipText(); | |
javax.swing.SwingUtilities.invokeLater(new Runnable() { | |
public void run() { | |
flipText.createAndShowGUI(); | |
} | |
}); | |
} | |
public void createAndShowGUI() { | |
Window.show(); | |
Window.addLabel("Flip Text Application Developed By: Tinker Academy v1.0"); | |
input = Window.addTextArea("<Type in text to flip>", 10, 10, true); | |
button = Window.addButton("Flip Text"); | |
button.addActionListener(this); | |
outputTextArea = Window.addTextArea("", 10, 10, false); | |
} | |
@Override | |
public void actionPerformed(ActionEvent e) { | |
String text = input.getText(); | |
System.out.println(text); | |
StringBuilder bldr = new StringBuilder(); | |
bldr.append(text); | |
bldr.reverse(); | |
for (int i = 0; i < bldr.length(); i++) { | |
char ch = bldr.charAt(i); | |
String flipChar = FlipTextLookupTable.getFlippedSymbol(String.valueOf(ch)); | |
bldr.replace(i, i+1, flipChar); | |
} | |
String output = bldr.toString(); | |
System.out.println(output); | |
outputTextArea.setText(output); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment