![]() |
|
Good for nothing String Crypter :D - Printable Version +- Sinisterly (https://sinister.li) +-- Forum: Coding (https://sinister.li/Forum-Coding) +--- Forum: Java, JVM, & JRE (https://sinister.li/Forum-Java-JVM-JRE) +--- Thread: Good for nothing String Crypter :D (/Thread-Good-for-nothing-String-Crypter-D) |
Good for nothing String Crypter :D - Gintoki Ameto - 12-30-2013 This is a silly String Crypter, made by my hobby and study of swing. https://drive.google.com/file/d/0B8Cwc8LhrJS6UTQ4a3NpVVIxemM/edit?usp=sharing What it does: I don't know, it modify the string and recover the string. Sometimes the string get shorter, sometimes it become longer =)), and it will not work right with the number, already told ya, it is a good-for-nothing program =)) Source: Spoiler:import javax.swing.*; Code: import java.awt.event.*;
public class Main {
public static String s;
private static void createAndShowGUI() {
JFrame frame = new JFrame("String Crypto");
JButton inputText = new JButton("Input Text");
JButton textEncrypt = new JButton("Text Encrypt");
JButton textDecrypt = new JButton("Text Decrypt");
JButton showText = new JButton("Show Text");
inputText.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
s = JOptionPane.showInputDialog(null, "Enter input text : ", null, 1);
}});
textEncrypt.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
String s2 = new String();
int cnt = 1;
for(int i = 1;i<s.length();i++){
if (s.charAt(i) == s.charAt(i-1)){
cnt++;
}
else{
s2 += cnt+""+s.charAt(i-1);
cnt = 1;
};
if (i==s.length()-1){
s2 += cnt+""+s.charAt(i);
};
}
s = s2;
JOptionPane.showMessageDialog(null, "New String: "+s, "StringCrypto",1);
}});
textDecrypt.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
String s2 = new String();
for(int i = 0;i<s.length();i++){
if (Character.isDigit(s.charAt(i))){
for(int j = Integer.parseInt(s.charAt(i)+"");j>0;j--){
s2 += s.charAt(i+1)+"";
}
};
}
s = s2;
JOptionPane.showMessageDialog(null, "New String: "+s, "StringCrypto",1);
}});
showText.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
JOptionPane.showMessageDialog(null, "Current String: "+s, "Show String",1);
}});
JPanel panel = new JPanel();
panel.add(inputText);
panel.add(textEncrypt);
panel.add(textDecrypt);
panel.add(showText);
frame.add(panel);
frame.setSize(400, 400);
frame.pack();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
public static void main(String[] args) {
//Schedule a job for the event-dispatching thread:
//creating and showing this application's GUI.
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
} |