Created
August 28, 2017 11:00
-
-
Save Fundibalus/47026859e1f4fdcdad7f0ad049b5e03a 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 uebungtr; | |
/** | |
* | |
* @author B201 | |
*/ | |
public class Plus implements Rechenoperation { | |
@Override | |
public int rechne(int a, int b) { | |
int erg = a+b; | |
return erg; | |
} | |
} | |
/* | |
* 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 uebungtr; | |
/** | |
* | |
* @author B201 | |
*/ | |
public interface Rechenoperation { | |
int rechne(int a, int b); | |
} | |
/* | |
* 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 uebungtr; | |
/** | |
* | |
* @author B201 | |
*/ | |
public class TR { | |
int start(String zahl1, String zahl2, String rechenzeichen) { | |
int ergebnis = 0; | |
int nummer1 = Integer.parseInt(zahl1); | |
int nummer2 = Integer.parseInt(zahl2); | |
if("-".equals(rechenzeichen)) { | |
Minus minus = new Minus(); | |
ergebnis = minus.rechne(nummer1, nummer2); | |
} else if("+".equals(rechenzeichen)){ | |
Plus plus = new Plus(); | |
ergebnis = plus.rechne(nummer1,nummer2); | |
} | |
return ergebnis; | |
} | |
} | |
/* | |
* 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 uebungtr; | |
/** | |
* | |
* @author B201 | |
*/ | |
public class UebungTR { | |
/** | |
* @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 uebungtr; | |
import java.awt.event.ActionEvent; | |
import java.awt.event.ActionListener; | |
import javax.swing.AbstractAction; | |
import javax.swing.BoxLayout; | |
import javax.swing.JButton; | |
import javax.swing.JFrame; | |
import javax.swing.JLabel; | |
import javax.swing.JPanel; | |
import javax.swing.JTextField; | |
/** | |
* | |
* @author B201 | |
*/ | |
public class GUI { | |
JFrame frame; | |
JTextField zahl1; | |
JTextField zahl2; | |
JTextField rechenzeichen; | |
JButton rechne; | |
JPanel panelrechnung; | |
JPanel grundpanel; | |
void start() { | |
zahl1 = new JTextField(); | |
grundpanel = new JPanel(); | |
zahl2 = new JTextField(); | |
rechenzeichen = new JTextField(); | |
rechne = new JButton(); | |
frame = new JFrame(); | |
frame.setLayout(new BoxLayout(frame.getContentPane(), 1)); | |
panelrechnung = new JPanel(); | |
panelrechnung.setLayout(new BoxLayout(panelrechnung, BoxLayout.X_AXIS)); | |
frame.add(panelrechnung); | |
panelrechnung.add(zahl1); | |
panelrechnung.add(rechenzeichen); | |
panelrechnung.add(zahl2); | |
panelrechnung.add(rechne); | |
rechne.setText("Rechne"); | |
rechne.addActionListener(new ButtonPower()); | |
frame.setVisible(true); | |
frame.pack(); | |
} | |
private class ButtonPower extends AbstractAction { | |
@Override | |
public void actionPerformed(ActionEvent e) { | |
TR taschenTr = new TR(); | |
int ergebnis = taschenTr.start(zahl1.getText(), zahl2.getText(), rechenzeichen.getText()); | |
JPanel panelneu = new JPanel(); | |
panelneu.setLayout(new BoxLayout(panelneu, 0)); | |
JLabel label = new JLabel(); | |
label.setText(ergebnis+""); | |
panelneu.add(label); | |
JButton button = new JButton(); | |
button.setText("Delete"); | |
panelneu.add(button); | |
frame.add(panelneu); | |
} | |
} | |
} | |
/* | |
* 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 uebungtr; | |
/** | |
* | |
* @author B201 | |
*/ | |
public class Minus implements Rechenoperation{ | |
@Override | |
public int rechne(int a, int b) { | |
int erg = a-b; | |
return erg; | |
} | |
} |
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 uebungtr; | |
import java.awt.event.ActionEvent; | |
import java.awt.event.ActionListener; | |
import javax.swing.AbstractAction; | |
import javax.swing.BoxLayout; | |
import javax.swing.JButton; | |
import javax.swing.JFrame; | |
import javax.swing.JLabel; | |
import javax.swing.JPanel; | |
import javax.swing.JTextField; | |
/** | |
* | |
* @author B201 | |
*/ | |
public class GUI { | |
JFrame frame; | |
JTextField zahl1; | |
JTextField zahl2; | |
JTextField rechenzeichen; | |
JButton rechne; | |
JPanel panelrechnung; | |
JPanel grundpanel; | |
void start() { | |
zahl1 = new JTextField(); | |
grundpanel = new JPanel(); | |
zahl2 = new JTextField(); | |
rechenzeichen = new JTextField(); | |
rechne = new JButton(); | |
frame = new JFrame(); | |
frame.setLayout(new BoxLayout(frame.getContentPane(), 1)); | |
panelrechnung = new JPanel(); | |
panelrechnung.setLayout(new BoxLayout(panelrechnung, BoxLayout.X_AXIS)); | |
frame.add(panelrechnung); | |
panelrechnung.add(zahl1); | |
panelrechnung.add(rechenzeichen); | |
panelrechnung.add(zahl2); | |
panelrechnung.add(rechne); | |
rechne.setText("Rechne"); | |
rechne.addActionListener(new ButtonPower()); | |
frame.setVisible(true); | |
frame.pack(); | |
} | |
private class ButtonPower extends AbstractAction { | |
@Override | |
public void actionPerformed(ActionEvent e) { | |
TR taschenTr = new TR(); | |
int ergebnis = taschenTr.start(zahl1.getText(), zahl2.getText(), rechenzeichen.getText()); | |
JPanel panelneu = new JPanel(); | |
panelneu.setLayout(new BoxLayout(panelneu, 0)); | |
JLabel label = new JLabel(); | |
label.setText(ergebnis+""); | |
panelneu.add(label); | |
JButton button = new JButton(); | |
button.setText("Delete"); | |
panelneu.add(button); | |
frame.add(panelneu); | |
} | |
} | |
} |
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 uebungtr; | |
/** | |
* | |
* @author B201 | |
*/ | |
public class Minus implements Rechenoperation{ | |
@Override | |
public int rechne(int a, int b) { | |
int erg = a-b; | |
return erg; | |
} | |
} |
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 uebungtr; | |
/** | |
* | |
* @author B201 | |
*/ | |
public class Plus implements Rechenoperation { | |
@Override | |
public int rechne(int a, int b) { | |
int erg = a+b; | |
return erg; | |
} | |
} |
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 uebungtr; | |
/** | |
* | |
* @author B201 | |
*/ | |
public interface Rechenoperation { | |
int rechne(int a, int b); | |
} |
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 uebungtr; | |
/** | |
* | |
* @author B201 | |
*/ | |
public class TR { | |
int start(String zahl1, String zahl2, String rechenzeichen) { | |
int ergebnis = 0; | |
int nummer1 = Integer.parseInt(zahl1); | |
int nummer2 = Integer.parseInt(zahl2); | |
if("-".equals(rechenzeichen)) { | |
Minus minus = new Minus(); | |
ergebnis = minus.rechne(nummer1, nummer2); | |
} else if("+".equals(rechenzeichen)){ | |
Plus plus = new Plus(); | |
ergebnis = plus.rechne(nummer1,nummer2); | |
} | |
return ergebnis; | |
} | |
} |
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 uebungtr; | |
/** | |
* | |
* @author B201 | |
*/ | |
public class UebungTR { | |
/** | |
* @param args the command line arguments | |
*/ | |
public static void main(String[] args) { | |
GUI gui = new GUI(); | |
gui.start(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment