Created
August 22, 2017 19:03
-
-
Save Fundibalus/964eaed1884730a3a3fe7d69137dc8e9 to your computer and use it in GitHub Desktop.
This file contains 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
/* | |
* To change this license header, choose License Headers in Project Properties. | |
* To change this template file, choose Tools | Templates | |
* and open the template in the editor. | |
*/ | |
package reverse_eingabe; | |
/** | |
* | |
* @author B201 | |
*/ | |
public interface Aendererer { | |
public String manipuliere(String eingabe); | |
} |
This file contains 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
/* | |
* To change this license header, choose License Headers in Project Properties. | |
* To change this template file, choose Tools | Templates | |
* and open the template in the editor. | |
*/ | |
package reverse_eingabe; | |
/** | |
* | |
* @author B201 | |
*/ | |
public class Marlon implements Aendererer{ | |
@Override | |
public String manipuliere(String eingabe) { | |
String newString = eingabe+"!"; | |
return newString; | |
} | |
} | |
/* | |
* To change this license header, choose License Headers in Project Properties. | |
* To change this template file, choose Tools | Templates | |
* and open the template in the editor. | |
*/ | |
package reverse_eingabe; | |
/** | |
* | |
* @author B201 | |
*/ | |
public class Reverse implements Aendererer{ | |
@Override | |
public String manipuliere(String eingabe) { | |
String newString = eingabe; | |
StringBuilder sb = new StringBuilder(newString); | |
String newnewString = sb.reverse().toString(); | |
return newnewString; | |
} | |
} | |
/* | |
* To change this license header, choose License Headers in Project Properties. | |
* To change this template file, choose Tools | Templates | |
* and open the template in the editor. | |
*/ | |
package reverse_eingabe; | |
/** | |
* | |
* @author B201 | |
*/ | |
public class Reverse_eingabe { | |
/** | |
* @param args the command line arguments | |
*/ | |
public static void main(String[] args) { | |
GUI gui = new GUI(); | |
gui.start(); | |
} | |
} | |
/* | |
* To change this license header, choose License Headers in Project Properties. | |
* To change this template file, choose Tools | Templates | |
* and open the template in the editor. | |
*/ | |
package reverse_eingabe; | |
/** | |
* | |
* @author B201 | |
*/ | |
public class UpperDowner implements Aendererer{ | |
@Override | |
public String manipuliere(String eingabe) { | |
String toggled = ""; | |
for(int i=0; i<eingabe.length(); i++) | |
{ | |
char letter = eingabe.charAt(i); | |
if(Character.isUpperCase(eingabe.charAt(i))) | |
{ | |
letter = Character.toLowerCase(letter); | |
toggled = toggled + letter; | |
} | |
else if(Character.isLowerCase(eingabe.charAt(i))) | |
{ | |
letter = Character.toUpperCase(letter); | |
toggled = toggled + letter; | |
} | |
} | |
return toggled; | |
} | |
} | |
/* | |
* To change this license header, choose License Headers in Project Properties. | |
* To change this template file, choose Tools | Templates | |
* and open the template in the editor. | |
*/ | |
package reverse_eingabe; | |
/** | |
* | |
* @author B201 | |
*/ | |
public interface Aendererer { | |
public String manipuliere(String eingabe); | |
} | |
/* | |
* To change this license header, choose License Headers in Project Properties. | |
* To change this template file, choose Tools | Templates | |
* and open the template in the editor. | |
*/ | |
package reverse_eingabe; | |
import java.awt.GridLayout; | |
import java.awt.event.ActionEvent; | |
import java.awt.event.ActionListener; | |
import java.awt.event.ItemEvent; | |
import javax.swing.AbstractAction; | |
import javax.swing.Action; | |
import javax.swing.JButton; | |
import javax.swing.JComboBox; | |
import javax.swing.JFrame; | |
import javax.swing.JLabel; | |
import javax.swing.JTextField; | |
/** | |
* | |
* @author B201 | |
*/ | |
class GUI { | |
JFrame frame; | |
JTextField eingabeFeld; | |
JButton knopf; | |
JComboBox box; | |
JLabel anzeige; | |
int conboindex = 0; | |
public void start() { | |
frame = new JFrame(); | |
frame.setLayout(new GridLayout(0,1)); | |
eingabeFeld = new JTextField(); | |
frame.add(eingabeFeld); | |
anzeige = new JLabel(); | |
frame.add(anzeige); | |
box = new JComboBox(); | |
box.addItem("Reverse"); | |
box.addItem("Marlon"); | |
box.addItem("UpperDowner"); | |
box.addItemListener(new ItemListener1()); | |
frame.add(box); | |
knopf = new JButton(); | |
knopf.setAction(new Pressing()); | |
knopf.setText("Umkehren"); | |
frame.add(knopf); | |
frame.setVisible(true); | |
frame.pack(); | |
} | |
public class ItemListener1 implements java.awt.event.ItemListener { | |
@Override | |
public void itemStateChanged(ItemEvent e) { | |
int index = box.getSelectedIndex(); | |
conboindex = index; | |
} | |
} | |
private class Pressing extends AbstractAction { | |
String newString; | |
@Override | |
public void actionPerformed(ActionEvent e) { | |
if(conboindex == 0) { //Reverse | |
Reverse re = new Reverse(); | |
newString = re.manipuliere(eingabeFeld.getText()); | |
anzeige.setText(newString); | |
} if(conboindex == 1) { //Marlon | |
Marlon mar = new Marlon(); | |
newString = mar.manipuliere(eingabeFeld.getText()); | |
anzeige.setText(newString); | |
}if(conboindex == 2) { //UpperDowner | |
UpperDowner ud = new UpperDowner(); | |
newString = ud.manipuliere(eingabeFeld.getText()); | |
anzeige.setText(newString); | |
} | |
} | |
} | |
} |
This file contains 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
/* | |
* To change this license header, choose License Headers in Project Properties. | |
* To change this template file, choose Tools | Templates | |
* and open the template in the editor. | |
*/ | |
package reverse_eingabe; | |
import java.awt.GridLayout; | |
import java.awt.event.ActionEvent; | |
import java.awt.event.ActionListener; | |
import java.awt.event.ItemEvent; | |
import javax.swing.AbstractAction; | |
import javax.swing.Action; | |
import javax.swing.JButton; | |
import javax.swing.JComboBox; | |
import javax.swing.JFrame; | |
import javax.swing.JLabel; | |
import javax.swing.JTextField; | |
/** | |
* | |
* @author B201 | |
*/ | |
class GUI { | |
JFrame frame; | |
JTextField eingabeFeld; | |
JButton knopf; | |
JComboBox box; | |
JLabel anzeige; | |
int conboindex = 0; | |
public void start() { | |
frame = new JFrame(); | |
frame.setLayout(new GridLayout(0,1)); | |
eingabeFeld = new JTextField(); | |
frame.add(eingabeFeld); | |
anzeige = new JLabel(); | |
frame.add(anzeige); | |
box = new JComboBox(); | |
box.addItem("Reverse"); | |
box.addItem("Marlon"); | |
box.addItem("UpperDowner"); | |
box.addItemListener(new ItemListener1()); | |
frame.add(box); | |
knopf = new JButton(); | |
knopf.setAction(new Pressing()); | |
knopf.setText("Umkehren"); | |
frame.add(knopf); | |
frame.setVisible(true); | |
frame.pack(); | |
} | |
public class ItemListener1 implements java.awt.event.ItemListener { | |
@Override | |
public void itemStateChanged(ItemEvent e) { | |
int index = box.getSelectedIndex(); | |
conboindex = index; | |
} | |
} | |
private class Pressing extends AbstractAction { | |
String newString; | |
@Override | |
public void actionPerformed(ActionEvent e) { | |
if(conboindex == 0) { //Reverse | |
Reverse re = new Reverse(); | |
newString = re.manipuliere(eingabeFeld.getText()); | |
anzeige.setText(newString); | |
} if(conboindex == 1) { //Marlon | |
Marlon mar = new Marlon(); | |
newString = mar.manipuliere(eingabeFeld.getText()); | |
anzeige.setText(newString); | |
}if(conboindex == 2) { //UpperDowner | |
UpperDowner ud = new UpperDowner(); | |
newString = ud.manipuliere(eingabeFeld.getText()); | |
anzeige.setText(newString); | |
} | |
} | |
} | |
} |
This file contains 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
/* | |
* To change this license header, choose License Headers in Project Properties. | |
* To change this template file, choose Tools | Templates | |
* and open the template in the editor. | |
*/ | |
package reverse_eingabe; | |
/** | |
* | |
* @author B201 | |
*/ | |
public class Marlon implements Aendererer{ | |
@Override | |
public String manipuliere(String eingabe) { | |
String newString = eingabe+"!"; | |
return newString; | |
} | |
} |
This file contains 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
/* | |
* To change this license header, choose License Headers in Project Properties. | |
* To change this template file, choose Tools | Templates | |
* and open the template in the editor. | |
*/ | |
package reverse_eingabe; | |
/** | |
* | |
* @author B201 | |
*/ | |
public class Reverse implements Aendererer{ | |
@Override | |
public String manipuliere(String eingabe) { | |
String newString = eingabe; | |
StringBuilder sb = new StringBuilder(newString); | |
String newnewString = sb.reverse().toString(); | |
return newnewString; | |
} | |
} |
This file contains 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
/* | |
* To change this license header, choose License Headers in Project Properties. | |
* To change this template file, choose Tools | Templates | |
* and open the template in the editor. | |
*/ | |
package reverse_eingabe; | |
/** | |
* | |
* @author B201 | |
*/ | |
public class Reverse_eingabe { | |
/** | |
* @param args the command line arguments | |
*/ | |
public static void main(String[] args) { | |
GUI gui = new GUI(); | |
gui.start(); | |
} | |
} |
This file contains 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
/* | |
* To change this license header, choose License Headers in Project Properties. | |
* To change this template file, choose Tools | Templates | |
* and open the template in the editor. | |
*/ | |
package reverse_eingabe; | |
/** | |
* | |
* @author B201 | |
*/ | |
public class UpperDowner implements Aendererer{ | |
@Override | |
public String manipuliere(String eingabe) { | |
String toggled = ""; | |
for(int i=0; i<eingabe.length(); i++) | |
{ | |
char letter = eingabe.charAt(i); | |
if(Character.isUpperCase(eingabe.charAt(i))) | |
{ | |
letter = Character.toLowerCase(letter); | |
toggled = toggled + letter; | |
} | |
else if(Character.isLowerCase(eingabe.charAt(i))) | |
{ | |
letter = Character.toUpperCase(letter); | |
toggled = toggled + letter; | |
} | |
} | |
return toggled; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment