master
3009594 2024-12-15 23:32:50 +01:00
parent d7836fd17c
commit 7aa59568dc
25 changed files with 1060 additions and 1122 deletions

View File

@ -1,15 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="Programmierung2/src"/>
<classpathentry exported="true" kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/5">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="bin"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="Programmierung2/src"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/5">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="bin"/>
</classpath>

View File

@ -1,55 +1,54 @@
package BankSystemGUI;
import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.Before;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
class JTest {
User obai;
Konto obai_konto, obai_konto2;
User omar;
Konto omar_konto;
Bank bank;
@BeforeEach
void erstelle_Objekt() {
obai = new User("Obai","albek");
obai_konto = new Konto(0,obai);
obai_konto2 = new Konto(0,obai);
omar = new User("Omar","Albek");
omar_konto = new Konto(0,omar);
bank = new Bank("SparKasse");
bank.kunde_Hinzufuegen(obai);
bank.kunde_Hinzufuegen(omar);
}
@Test
public void sucheKunden() throws Exception {
assertEquals(omar.toString(),bank.getKunde(1003));
}
@Test
void testeinzahlen() throws Exception {
obai_konto.einzahlen(50);
assertEquals(50,obai_konto.getKontostand());
obai_konto2.einzahlen(100);
assertEquals(100,obai_konto2.getKontostand());
omar_konto.einzahlen(100);
assertEquals(100,omar_konto.getKontostand());
}
}
package BankSystemGUI;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.BeforeEach;
class JTest {
User obai;
Konto obai_konto, obai_konto2;
User omar;
Konto omar_konto;
Bank bank;
@BeforeEach
void erstelle_Objekt() {
obai = new User("Obai","albek");
obai_konto = new Konto(0,obai);
obai_konto2 = new Konto(0,obai);
omar = new User("Omar","Albek");
omar_konto = new Konto(0,omar);
bank = new Bank("SparKasse");
bank.kunde_Hinzufuegen(obai);
bank.kunde_Hinzufuegen(omar);
}
@Test
public void sucheKunden() throws Exception {
assertEquals(omar.toString(),bank.getKunde(1003));
}
@Test
void testeinzahlen() throws Exception {
obai_konto.einzahlen(50);
assertEquals(50,obai_konto.getKontostand());
obai_konto2.einzahlen(100);
assertEquals(100,obai_konto2.getKontostand());
omar_konto.einzahlen(100);
assertEquals(100,omar_konto.getKontostand());
}
}

View File

@ -1,13 +1,10 @@
package BinaryTree;
import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
class JuintTeste {
@Test
void test() {
BinaryBaumList b1 = new BinaryBaumList();
b1.addElement(15);

View File

@ -3,32 +3,34 @@ package BinaryTree;
public class Test {
public static void main(String[] args) {
BinaryBaumList b1 = new BinaryBaumList();
b1.addElement(50);
b1.addElement(30);
b1.addElement(70);
b1.addElement(20);
b1.addElement(40);
b1.addElement(60);
b1.addElement(80);
b1.addElement(15);
b1.addElement(22);
b1.addElement(35);
b1.addElement(45);
b1.addElement(21);
b1.addElement(25);
// BinaryBaumList b1 = new BinaryBaumList();
// b1.addElement(50);
// b1.addElement(30);
// b1.addElement(70);
// b1.addElement(20);
// b1.addElement(40);
// b1.addElement(60);
// b1.addElement(80);
// b1.addElement(15);
// b1.addElement(22);
// b1.addElement(35);
// b1.addElement(45);
// b1.addElement(21);
// b1.addElement(25);
//
//
//
//
// System.out.print("[");
// b1.printDepth();
// System.out.print("]");
// System.out.println();
// b1.removNode(30);
// System.out.print("[");
// b1.printDepth();
// System.out.print("]");
System.out.print("[");
b1.printDepth();
System.out.print("]");
System.out.println();
b1.removNode(30);
System.out.print("[");
b1.printDepth();
System.out.print("]");
System.out.println('G' > 'F');
}

View File

@ -2,14 +2,12 @@ package GUIAnwendungen;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JComboBox;
import javax.swing.JButton;
import java.awt.Font;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
@ -30,7 +28,6 @@ public class Jpanel {
// و وضعنا له حدود و عنوان Layout Manager لا يستخدم أي Panel هنا قمنا بتعريف
JPanel panel = new JPanel(null);
panel.setBorder(BorderFactory.createTitledBorder("Add User"));
panel.setBounds(50, 30, 290, 300);
// Frame في الـ Panel هنا وضعنا الـ

View File

@ -9,7 +9,6 @@ import java.awt.Font;
import java.text.SimpleDateFormat;
import java.awt.Font;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
@ -28,7 +27,6 @@ public class Labels {
JLabel label = new JLabel();
// Erstelle einen Border für das Fenster
Border b1 = BorderFactory.createLineBorder(Color.GREEN,5);
// füge den Text auf dem Fenster hinzu
label.setText("Hall Welt");
@ -60,7 +58,6 @@ public class Labels {
label.setOpaque(true);
//zeige den Border auf dem Fenster
label.setBorder(b1);
//füge ein Bild hinzu

View File

@ -2,7 +2,6 @@ package GUIAnwendungen;
import java.awt.Color;
import java.awt.Font;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;

View File

@ -1,47 +1,45 @@
package Hashmap;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import Hashmap.MyGenericHashMap.Entry;
class JunitTest {
private MyGenericHashMap<Integer,String> h1;
@BeforeEach
void list() {
h1 = new MyGenericHashMap<>();
h1.put(3009594, "obai");
h1.put(3129594, "omar");
h1.put(3129592, "abd");
h1.put(3129392, "basel");
}
@Test
void testPut() {
h1.put(3009594, "omar");
String value = h1.getValue(3009594);
assertEquals("omar",value);
}
@Test
void testcontainsKey() {
assertTrue(h1.containsKey(3129592));
assertFalse(h1.containsKey(3213213));
}
@Test
void testSize() {
assertEquals(4,h1.size());
}
@Test
void testisEmpty() {
assertTrue(h1.isEmpty());
}
}
package Hashmap;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.BeforeEach;
class JunitTest {
private MyGenericHashMap<Integer,String> h1;
@BeforeEach
void list() {
h1 = new MyGenericHashMap<>();
h1.put(3009594, "obai");
h1.put(3129594, "omar");
h1.put(3129592, "abd");
h1.put(3129392, "basel");
}
@Test
void testPut() {
h1.put(3009594, "omar");
String value = h1.getValue(3009594);
assertEquals("omar",value);
}
@Test
void testcontainsKey() {
assertTrue(h1.containsKey(3129592));
assertFalse(h1.containsKey(3213213));
}
@Test
void testSize() {
assertEquals(4,h1.size());
}
@Test
void testisEmpty() {
assertTrue(h1.isEmpty());
}
}

View File

@ -1,22 +1,22 @@
package Timer;
import java.util.Timer;
import java.util.TimerTask;
public class TimerKlasse extends TimerTask {
public static void main(String[] args) {
Timer timer = new Timer();
TimerTask task = new TimerKlasse();
timer.schedule(task,1000);
}
@Override
public void run() {
System.out.println("Hallo Welt!");
}
}
package Timer;
import java.util.Timer;
import java.util.TimerTask;
public class TimerKlasse extends TimerTask {
public static void main(String[] args) {
Timer timer = new Timer();
TimerTask task = new TimerKlasse();
timer.schedule(task,5000);
}
@Override
public void run() {
System.out.println("Hallo Welt!");
}
}

View File

@ -1,156 +1,174 @@
package TodoListApp.GUI_UserInterface;
import java.awt.*;
import javax.swing.*;
import javax.swing.border.EmptyBorder;
import javax.swing.border.LineBorder;
import TodoListApp.Domain.*;
public class GUI_addTask extends JFrame {
private JPanel contentPane;
private JTextField tasktitle;
private JTextField taskBeschreibung;
private ButtonGroup priorityGroup;
private JButton submitTask;
private JRadioButton hoch, mittel,niedrig ;
public GUI_addTask() {
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE );
setBounds(100, 100, 515, 618);
contentPane = new JPanel();
contentPane.setBackground(new Color(255, 255, 255));
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JPanel panel = new JPanel();
panel.setBorder(new LineBorder(new Color(255, 255, 255), 3));
panel.setBackground(new Color(0, 128, 255));
panel.setForeground(new Color(255, 255, 255));
panel.setBounds(31, 26, 441, 517);
contentPane.add(panel);
panel.setLayout(null);
JLabel lblNewLabel = new JLabel("Füge Task hinzu");
lblNewLabel.setFont(new Font("Tahoma", Font.BOLD, 18));
lblNewLabel.setForeground(new Color(255, 255, 255));
lblNewLabel.setHorizontalAlignment(SwingConstants.CENTER);
lblNewLabel.setBounds(76, 11, 289, 58);
panel.add(lblNewLabel);
JLabel lblNewLabel_1 = new JLabel("Title:");
lblNewLabel_1.setForeground(new Color(255, 255, 255));
lblNewLabel_1.setHorizontalAlignment(SwingConstants.LEFT);
lblNewLabel_1.setFont(new Font("Tahoma", Font.BOLD, 14));
lblNewLabel_1.setBounds(24, 79, 103, 14);
panel.add(lblNewLabel_1);
JLabel lblNewLabel_1_1 = new JLabel("Beschreibung: ");
lblNewLabel_1_1.setHorizontalAlignment(SwingConstants.LEFT);
lblNewLabel_1_1.setForeground(Color.WHITE);
lblNewLabel_1_1.setFont(new Font("Tahoma", Font.BOLD, 14));
lblNewLabel_1_1.setBounds(24, 121, 103, 14);
panel.add(lblNewLabel_1_1);
JLabel lblNewLabel_1_3 = new JLabel("Priorität:");
lblNewLabel_1_3.setHorizontalAlignment(SwingConstants.LEFT);
lblNewLabel_1_3.setForeground(Color.WHITE);
lblNewLabel_1_3.setFont(new Font("Tahoma", Font.BOLD, 14));
lblNewLabel_1_3.setBounds(24, 203, 103, 14);
panel.add(lblNewLabel_1_3);
tasktitle = new JTextField();
tasktitle.setBounds(142, 77, 133, 20);
panel.add(tasktitle);
tasktitle.setColumns(10);
taskBeschreibung = new JTextField();
taskBeschreibung.setColumns(10);
taskBeschreibung.setBounds(142, 119, 133, 20);
panel.add(taskBeschreibung);
// RadioButtons erstellen
hoch = new JRadioButton("Hoch");
hoch.setSelected(true);
hoch.setBounds(142, 165, 89, 23);
panel.add(hoch);
mittel = new JRadioButton("Mittel");
mittel.setBounds(142, 201, 89, 23);
panel.add(mittel);
niedrig = new JRadioButton("Niedrig");
niedrig.setBounds(142, 240, 89, 23);
panel.add(niedrig);
// ButtonGroup erstellen, um die RadioButtons zu gruppieren
priorityGroup = new ButtonGroup();
priorityGroup.add(hoch);
priorityGroup.add(mittel);
priorityGroup.add(niedrig);
submitTask = new JButton("Submit");
submitTask.setBounds(24, 323, 123, 23);
panel.add(submitTask);
setLocationRelativeTo(null);
}
public void zeigeFensterAddTask() {
this.setVisible(true);
}
public void closeFensterAddTask() {
this.setVisible(false);
}
public JTextField getTasktitle() {
return tasktitle;
}
public void setTasktitle(JTextField tasktitle) {
this.tasktitle = tasktitle;
}
public JTextField getTaskBeschreibung() {
return taskBeschreibung;
}
public void setTaskBeschreibung(JTextField taskBeschreibung) {
this.taskBeschreibung = taskBeschreibung;
}
public ButtonGroup getPriorityGroup() {
return priorityGroup;
}
public JButton getSubmitTask() {
return submitTask;
}
public JRadioButton getHoch() {
return hoch;
}
public JRadioButton getMittel() {
return mittel;
}
public JRadioButton getNiedrig() {
return niedrig;
}
public void resetButtons() {
tasktitle.setText("");
taskBeschreibung.setText("");
hoch.setSelected(true);
}
public void showInfo(String message) {
JOptionPane.showMessageDialog(null, message, "Studen angemeldet", JOptionPane.INFORMATION_MESSAGE);
}
}
package TodoListApp.GUI_UserInterface;
import java.awt.*;
import javax.swing.*;
import javax.swing.border.EmptyBorder;
import javax.swing.border.LineBorder;
import TodoListApp.Domain.*;
public class GUI_addTask extends JFrame {
private JPanel contentPane;
private JTextField tasktitle;
private JTextField taskBeschreibung;
private ButtonGroup priorityGroup;
private JButton submitTask;
private JRadioButton hoch, mittel,niedrig ;
public GUI_addTask() {
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE );
setBounds(100, 100, 515, 618);
contentPane = new JPanel();
contentPane.setBackground(new Color(255, 255, 255));
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JPanel panel = new JPanel();
panel.setBorder(new LineBorder(new Color(255, 255, 255), 3));
panel.setBackground(new Color(0, 128, 255));
panel.setForeground(new Color(255, 255, 255));
panel.setBounds(31, 26, 441, 517);
contentPane.add(panel);
panel.setLayout(null);
JLabel lblNewLabel = new JLabel("Füge Task hinzu");
lblNewLabel.setFont(new Font("Tahoma", Font.BOLD, 18));
lblNewLabel.setForeground(new Color(255, 255, 255));
lblNewLabel.setHorizontalAlignment(SwingConstants.CENTER);
lblNewLabel.setBounds(76, 11, 289, 58);
panel.add(lblNewLabel);
JLabel lblNewLabel_1 = new JLabel("Title:");
lblNewLabel_1.setForeground(new Color(255, 255, 255));
lblNewLabel_1.setHorizontalAlignment(SwingConstants.LEFT);
lblNewLabel_1.setFont(new Font("Tahoma", Font.BOLD, 14));
lblNewLabel_1.setBounds(24, 79, 103, 14);
panel.add(lblNewLabel_1);
JLabel lblNewLabel_1_1 = new JLabel("Beschreibung: ");
lblNewLabel_1_1.setHorizontalAlignment(SwingConstants.LEFT);
lblNewLabel_1_1.setForeground(Color.WHITE);
lblNewLabel_1_1.setFont(new Font("Tahoma", Font.BOLD, 14));
lblNewLabel_1_1.setBounds(24, 121, 103, 14);
panel.add(lblNewLabel_1_1);
JLabel lblNewLabel_1_3 = new JLabel("Priorität:");
lblNewLabel_1_3.setHorizontalAlignment(SwingConstants.LEFT);
lblNewLabel_1_3.setForeground(Color.WHITE);
lblNewLabel_1_3.setFont(new Font("Tahoma", Font.BOLD, 14));
lblNewLabel_1_3.setBounds(24, 203, 103, 14);
panel.add(lblNewLabel_1_3);
tasktitle = new JTextField();
tasktitle.setBounds(142, 77, 133, 20);
panel.add(tasktitle);
tasktitle.setColumns(10);
taskBeschreibung = new JTextField();
taskBeschreibung.setColumns(10);
taskBeschreibung.setBounds(142, 119, 133, 20);
panel.add(taskBeschreibung);
// RadioButtons erstellen
hoch = new JRadioButton("Hoch");
hoch.setSelected(true);
hoch.setBounds(142, 165, 89, 23);
panel.add(hoch);
mittel = new JRadioButton("Mittel");
mittel.setBounds(142, 201, 89, 23);
panel.add(mittel);
niedrig = new JRadioButton("Niedrig");
niedrig.setBounds(142, 240, 89, 23);
panel.add(niedrig);
// ButtonGroup erstellen, um die RadioButtons zu gruppieren
priorityGroup = new ButtonGroup();
priorityGroup.add(hoch);
priorityGroup.add(mittel);
priorityGroup.add(niedrig);
submitTask = new JButton("Submit");
submitTask.setBounds(24, 323, 123, 23);
panel.add(submitTask);
JScrollPane scrollPane = new JScrollPane();
scrollPane.setBounds(229, 333, 2, 2);
panel.add(scrollPane);
JCheckBox chckbxNewCheckBox = new JCheckBox("New check box");
chckbxNewCheckBox.setBounds(148, 383, 97, 23);
panel.add(chckbxNewCheckBox);
JButton resest = new JButton("Reset");
resest.setForeground(new Color(64, 0, 128));
resest.setFont(new Font("Microsoft Tai Le", Font.BOLD, 14));
resest.setBounds(221, 317, 144, 34);
panel.add(resest);
JCheckBox chckbxNewCheckBox_1 = new JCheckBox("New check box");
chckbxNewCheckBox_1.setBounds(268, 240, 112, 23);
panel.add(chckbxNewCheckBox_1);
setLocationRelativeTo(null);
}
public void zeigeFensterAddTask() {
this.setVisible(true);
}
public void closeFensterAddTask() {
this.setVisible(false);
}
public JTextField getTasktitle() {
return tasktitle;
}
public void setTasktitle(JTextField tasktitle) {
this.tasktitle = tasktitle;
}
public JTextField getTaskBeschreibung() {
return taskBeschreibung;
}
public void setTaskBeschreibung(JTextField taskBeschreibung) {
this.taskBeschreibung = taskBeschreibung;
}
public ButtonGroup getPriorityGroup() {
return priorityGroup;
}
public JButton getSubmitTask() {
return submitTask;
}
public JRadioButton getHoch() {
return hoch;
}
public JRadioButton getMittel() {
return mittel;
}
public JRadioButton getNiedrig() {
return niedrig;
}
public void resetButtons() {
tasktitle.setText("");
taskBeschreibung.setText("");
hoch.setSelected(true);
}
public void showInfo(String message) {
JOptionPane.showMessageDialog(null, message, "Studen angemeldet", JOptionPane.INFORMATION_MESSAGE);
}
}

View File

@ -1,27 +1,23 @@
package VorlesungsFolien.Verebung;
public class A {
void f() {
System.out.println("A");
}
public static void main(String[] args) {
A a1 = new A();
A a2 = new B();
B b = new B();
a1.f();
// Ausgabe B:
// Das passiert aufgrund des Konzepts des Polymorphismus
// Dies liegt am Prinzip der dynamischen Bindung
a2.f();
}
}
class B extends A {
void f() {
System.out.println("B");
}
package VorlesungsFolien.Verebung;
public class A {
public void f() {
System.out.println("A");
}
public static void main(String[] args) {
A a1 = new A();
A a2 = new B();
B b = new B();
a2.f();
}
}
class B extends A {
public void f() {
System.out.println("B");
}
}

View File

@ -1,173 +1,173 @@
package VorlesungsFolien.Verebung;
import java.util.ArrayList;
public class Firma {
private ArrayList<Mitarbeiter> mas = new ArrayList<>();
public static void main(String[] args) {
Mitarbeiter mi = new Manager("Stromberg", "01.02.1970", "Finanzen");
Manager ma = new Geschaeftsfuehrer();
Mitarbeiter m = new Geschaeftsfuehrer();
// Ja weil Manager ein Mitarbeiter ist
if (mi instanceof Mitarbeiter )
System.out.println("Ja ");
// Ja weil Manager ein Manager ist
if (mi instanceof Manager )
System.out.println("Ja stimmt");
// nein, weil nicht jeder manager ein Geschaeftsfuehrer ist, aber jeder Geschaeftsfuehrer ist ein manager
if (mi instanceof Geschaeftsfuehrer)
System.out.println("Ja");
if (null instanceof Geschaeftsfuehrer )
System.out.println("null");
if (null instanceof Mitarbeiter )
System.out.println("null");
if (null instanceof Manager )
System.out.println("null");
if (ma instanceof Geschaeftsfuehrer)
System.out.println("Ja");
mi = ma;
//ma = mi; nein, weil nicht jeder mitarbeiter ein manager ist!
Firma firma = new Firma();
Mitarbeiter mitarbeiter2 = new Mitarbeiter("Mayer", "12.12.1999");
Mitarbeiter mitarbeiter = new Mitarbeiter("Müller", "27.10.1972");
Manager manager = new Manager("Stromberg", "01.02.1970", "Finanzen");
firma.mitarbeiterEinstellen(mitarbeiter);
firma.mitarbeiterEinstellen(manager);
firma.mitarbeiterEinstellen(mitarbeiter2);
/* geht nicht! Warum?
* weil nicht jeder mitarbeiter ein manager ist!
*/
// manager = mitarbeiter; //geht nicht!
//weil jeder manager ist ein mitarbeiter
// mitarbeiter = manager;// Ja geht:
System.out.println("Polymorphismus");
System.out.println(mitarbeiter.getGehalt());
System.out.println(manager.getAbteilung());
// System.out.println(mitarbeiter.getAbteilung()); // geht nicht, wg. statischem Typ Mitarbeiter
System.out.println("Geht ");
Manager me = ((Manager)mitarbeiter);
// mitarbeiter2 = manager;// Ja geht:
Manager md =((Manager)mitarbeiter2);
// ClassCastException zur laufzeit, weil ich if (mitarbeiter instanceof Manager) verwenden soll
// WICHTIG:
//instanceof prüft, ob die klasse manager die klasse mitarbeiter erbt
}
private void mitarbeiterEinstellen(Mitarbeiter m) {
mas.add(m);
}
private void gehaltsErhöhung() {
for (Mitarbeiter m : mas) {
double erhöhung = 0.02;
// System.out.println(m instanceof String); // das geht NICHT, muss zur Vererbungshierachie passen
if (m instanceof Manager)
erhöhung = 0.12;
// else if (m instanceof Geschäftsführer)
// erhöhung = 0.2;
m.setGehalt(m.getGehalt() * (1 + erhöhung));
}
}
}
class Mitarbeiter extends Object {
private String name;
private double gehalt;
private String geburtsdatum;
public Mitarbeiter(String name, String geburtsdatum) {
this(name, 35000, geburtsdatum);
}
public Mitarbeiter(String name, double gehalt, String geburtsdatum) {
this.name = name;
this.gehalt = gehalt;
this.geburtsdatum = geburtsdatum;
}
public Mitarbeiter() {
}
public String getDetails() {
return name;
}
public double getGehalt() {
return gehalt;
}
public void setGehalt(double gehalt) {
this.gehalt = gehalt;
}
}
class Manager extends Mitarbeiter {
private String abteilung;
public Manager(String name, String geburtsdatum, String abteilung) {
super(name, 65000, geburtsdatum); // das MUSS zuerst gemacht werden!
this.abteilung = abteilung;
}
public Manager() {
}
public String getDetails() {
return super.getDetails() + " " + abteilung;
}
public String getAbteilung() {
return abteilung;
}
}
class Geschaeftsfuehrer extends Manager{
public Geschaeftsfuehrer(String name, String geburtsdatum, String abteilung) {
super(name, geburtsdatum, abteilung);
}
public Geschaeftsfuehrer(){
}
public void printGeschaeftsfuehrer() {
System.out.println("Hi");
}
}
package VorlesungsFolien.Verebung;
import java.util.ArrayList;
public class Firma {
private ArrayList<Mitarbeiter> mas = new ArrayList<>();
public static void main(String[] args) {
Mitarbeiter mi = new Manager("Stromberg", "01.02.1970", "Finanzen");
Manager ma = new Geschaeftsfuehrer();
Mitarbeiter m = new Geschaeftsfuehrer();
// Ja weil Manager ein Mitarbeiter ist
if (mi instanceof Mitarbeiter )
System.out.println("Ja ");
// Ja weil Manager ein Manager ist
if (mi instanceof Manager )
System.out.println("Ja stimmt");
// nein, weil nicht jeder manager ein Geschaeftsfuehrer ist, aber jeder Geschaeftsfuehrer ist ein manager
if (mi instanceof Geschaeftsfuehrer)
System.out.println("Jalll");
if (null instanceof Geschaeftsfuehrer )
System.out.println("null");
if (null instanceof Mitarbeiter )
System.out.println("null");
if (null instanceof Manager )
System.out.println("null");
if (ma instanceof Geschaeftsfuehrer)
System.out.println("Ja");
mi = ma;
//ma = mi; nein, weil nicht jeder mitarbeiter ein manager ist!
Firma firma = new Firma();
Mitarbeiter mitarbeiter2 = new Mitarbeiter("Mayer", "12.12.1999");
Mitarbeiter mitarbeiter = new Mitarbeiter("Müller", "27.10.1972");
Manager manager = new Manager("Stromberg", "01.02.1970", "Finanzen");
firma.mitarbeiterEinstellen(mitarbeiter);
firma.mitarbeiterEinstellen(manager);
firma.mitarbeiterEinstellen(mitarbeiter2);
/* geht nicht! Warum?
* weil nicht jeder mitarbeiter ein manager ist!
*/
// manager = mitarbeiter; //geht nicht!
//weil jeder manager ist ein mitarbeiter
// mitarbeiter = manager;// Ja geht:
System.out.println("Polymorphismus");
System.out.println(mitarbeiter.getGehalt());
System.out.println(manager.getAbteilung());
// System.out.println(mitarbeiter.getAbteilung()); // geht nicht, wg. statischem Typ Mitarbeiter
System.out.println("Geht ");
Manager me = ((Manager)mitarbeiter);
// mitarbeiter2 = manager;// Ja geht:
Manager md =((Manager)mitarbeiter2);
// ClassCastException zur laufzeit, weil ich if (mitarbeiter instanceof Manager) verwenden soll
// WICHTIG:
//instanceof prüft, ob die klasse manager die klasse mitarbeiter erbt
}
private void mitarbeiterEinstellen(Mitarbeiter m) {
mas.add(m);
}
private void gehaltsErhöhung() {
for (Mitarbeiter m : mas) {
double erhöhung = 0.02;
// System.out.println(m instanceof String); // das geht NICHT, muss zur Vererbungshierachie passen
if (m instanceof Manager)
erhöhung = 0.12;
// else if (m instanceof Geschäftsführer)
// erhöhung = 0.2;
m.setGehalt(m.getGehalt() * (1 + erhöhung));
}
}
}
class Mitarbeiter extends Object {
private String name;
private double gehalt;
private String geburtsdatum;
public Mitarbeiter(String name, String geburtsdatum) {
this(name, 35000, geburtsdatum);
}
public Mitarbeiter(String name, double gehalt, String geburtsdatum) {
this.name = name;
this.gehalt = gehalt;
this.geburtsdatum = geburtsdatum;
}
public Mitarbeiter() {
}
public String getDetails() {
return name;
}
public double getGehalt() {
return gehalt;
}
public void setGehalt(double gehalt) {
this.gehalt = gehalt;
}
}
class Manager extends Mitarbeiter {
private String abteilung;
public Manager(String name, String geburtsdatum, String abteilung) {
super(name, 65000, geburtsdatum); // das MUSS zuerst gemacht werden!
this.abteilung = abteilung;
}
public Manager() {
}
public String getDetails() {
return super.getDetails() + " " + abteilung;
}
public String getAbteilung() {
return abteilung;
}
}
class Geschaeftsfuehrer extends Manager{
public Geschaeftsfuehrer(String name, String geburtsdatum, String abteilung) {
super(name, geburtsdatum, abteilung);
}
public Geschaeftsfuehrer(){
}
public void printGeschaeftsfuehrer() {
System.out.println("Hi");
}
}

View File

@ -7,8 +7,6 @@
module Programmierung2 {
requires java.desktop;
requires org.junit.jupiter.api;
requires junit;
requires java.sql;
requires java.logging;
exports Übungen.TaschenrechnerGUI to junit; // Exportiere das Paket für das JUnit-Modul
}

Binary file not shown.

View File

@ -1,39 +1,39 @@
package oop.Generics;
public class Pocket<T> {
private T value;
public Pocket() {}
public Pocket(T value) {
this.value = value;
}
public T getValue() {
return value;
}
public void setValue(T value) {
this.value = value;
}
@Override
public String toString() {
return "Pocket [value=" + value + "]";
}
public static void main(String[] args) {
Pocket<Pocket<String>> pocketOfPockets = new Pocket<>();
pocketOfPockets.setValue(new Pocket<String>());
pocketOfPockets.getValue().setValue("Innere Pocket");
System.out.println(pocketOfPockets.getValue().getValue());
//-----------------------------------------------------------------
Pocket<String>[] pocket = new Pocket[10]; // mit 10 Plätzen
}
}
package oop.Generics;
import java.util.*;
public class Pocket<T> {
private T value;
public Pocket() {}
public Pocket(T value) {
this.value = value;
}
public static <G> G getT(G g) {
return g;
}
public T getValue() {
return value;
}
public void setValue(T value) {
this.value = value;
}
@Override
public String toString() {
return "Pocket [value=" + value + "]";
}
public static void main(String[] args) {
List<Object> stringList = new ArrayList<>();
}
}

View File

@ -0,0 +1,19 @@
package oop.Generics;
import java.util.*;
public class RawType{
public static void main(String[] args) {
ArrayList<Integer> t = new ArrayList<>();
t.add(22);
t.add(12);
}
public static void printList(ArrayList<Object> list) {
for (Object elem : list)
System.out.println(elem + " ");
}
}

View File

@ -1,45 +1,17 @@
package streams;
import java.util.Arrays;
import java.util.stream.*;
public class Beispiele {
public static void main(String[] args) {
Integer[] myArray = new Integer[] { 10, 20, 22, 30, 50 };
Stream<Integer> myStream = Arrays.stream(myArray);
/*
* Hier macht der Stream nichts, weil die Intermediate-Operation filter keine
* Aktion auslöst, solange keine Terminal-Operation aufgerufen wird.
*/
// myStream.filter(i -> (i % 2 == 0));//Keine Wirkung, da keine Terminal-Operation folgt
/*
* Hier wird eine Intermediate-Operation (filter) auf dem Stream aufgerufen, die
* die geraden Zahlen aus dem Stream herausfiltert. Danach wird die
* Terminal-Operation count() aufgerufen, die die Anzahl der gefilterten
* Elemente zählt und als long zurückgibt.
*/
long x = myStream.filter(i -> (i % 2 == 0)).count(); // count gibt Long zurück
System.out.println(x);
// Wiederverwendung von myStream liefert einen Compiler-Fehler, da der Stream
// bereits abgeschlossen ist.
// Ein Stream kann nur einmal verwendet werden, und nach einer
// Terminal-Operation wie count()
// ist der Stream geschlossen und nicht wiederverwendbar.
x = myStream.filter(i -> (i % 2 == 1)).count(); // Compiler-Fehler
System.out.println(x);
// Compiler-Fehler: Stream has already been operated upon or closed
// Dieser Fehler tritt auf, weil myStream nach der ersten count()-Operation
// nicht erneut verwendet werden kann.
long y = myStream.filter(i -> (i % 2 == 1)).count(); // Compiler-Fehler
System.out.println(y);
int[] array = { 1, 2, 3, 45, 6 };
}
}
package streams;
import java.util.Arrays;
import java.util.stream.*;
public class Beispiele {
public static void main(String[] args) {
int[] array = { 1, 2, 3, 45, 6 };
IntStream.of(array).forEach(System.out::print);
}
}

View File

@ -1,7 +1,6 @@
package Übungen.BlackJack;
import org.junit.jupiter.api.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.*;
import java.util.ArrayList;

View File

@ -1,56 +1,56 @@
package Übungen.MyBankSystem;
import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.*;
import java.util.ArrayList;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
//class JTest {
// private Konto obaiKonto1;
// private Konto obaiKonto2;
// private User obai;
//
// @BeforeEach
// void erstelleObjekt() {
// obai = new User("Obai" , "123");
// obaiKonto1 = new Konto(1234,0,obai);
// obaiKonto2 = new Konto (1235,0 ,obai);
// obai.addKonto(obaiKonto1);
// obai.addKonto(obaiKonto2);
//
// }
//
//
// @Disabled
// void testEinzahlen() throws Exception {
// obai.einzahlen(123, obaiKonto1);
// obai.einzahlen(124, obaiKonto2);
// assertEquals(123,obaiKonto1.getKontostand());
// assertEquals(124,obaiKonto2.getKontostand());
//
// }
//
// @Test
// void testauszahlen() throws Exception {
// obai.einzahlen(123, obaiKonto1);
// obai.auszahlen(123, obaiKonto1);
// assertEquals(0,obaiKonto1.getKontostand());
//
// }
//
// @Test
// void testueberweisen() throws Exception {
// obai.einzahlen(123, obaiKonto1);
// obai.ueberweisen(100, obaiKonto1, obaiKonto2);
//
// assertEquals(23,obaiKonto1.getKontostand());
// assertEquals(100,obaiKonto2.getKontostand());
//
// }
//
//
//}
package Übungen.MyBankSystem;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
import java.util.ArrayList;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
//class JTest {
// private Konto obaiKonto1;
// private Konto obaiKonto2;
// private User obai;
//
// @BeforeEach
// void erstelleObjekt() {
// obai = new User("Obai" , "123");
// obaiKonto1 = new Konto(1234,0,obai);
// obaiKonto2 = new Konto (1235,0 ,obai);
// obai.addKonto(obaiKonto1);
// obai.addKonto(obaiKonto2);
//
// }
//
//
// @Disabled
// void testEinzahlen() throws Exception {
// obai.einzahlen(123, obaiKonto1);
// obai.einzahlen(124, obaiKonto2);
// assertEquals(123,obaiKonto1.getKontostand());
// assertEquals(124,obaiKonto2.getKontostand());
//
// }
//
// @Test
// void testauszahlen() throws Exception {
// obai.einzahlen(123, obaiKonto1);
// obai.auszahlen(123, obaiKonto1);
// assertEquals(0,obaiKonto1.getKontostand());
//
// }
//
// @Test
// void testueberweisen() throws Exception {
// obai.einzahlen(123, obaiKonto1);
// obai.ueberweisen(100, obaiKonto1, obaiKonto2);
//
// assertEquals(23,obaiKonto1.getKontostand());
// assertEquals(100,obaiKonto2.getKontostand());
//
// }
//
//
//}

View File

@ -1,115 +1,61 @@
package Übungen;
import java.awt.EventQueue;
import javax.swing.*;
import javax.swing.border.EmptyBorder;
import java.awt.*;
import java.util.ArrayList;
public class Stopuhr extends JFrame {
JPanel contentPane;
JLabel zeige_zeit;
JButton start_zeit, stop_zeit_1;
JTextArea zeige_alleZeiten;
Timer timer, print_alleZeiten;
boolean aktiv;
long startzeit;
int speichere_alle_zeiten_index = 0;
ArrayList<String> speichere_alle_zeiten = new ArrayList<>();
public Stopuhr() {
this.setTitle("Stopuhr");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 498, 630);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
zeite_elemente();
start_programm();
this.setVisible(true);
}
public void start_programm() {
aktiv = false;
timer = new Timer(100, e -> update_zeit());
print_alleZeiten = new Timer(100, e -> print_next_time());
start_zeit.addActionListener(e -> start_stopuhr());
stop_zeit_1.addActionListener(e -> stop_stopuhr());
}
public void start_stopuhr() {
if (!aktiv) {
timer.start();
startzeit = System.currentTimeMillis(); // Milisekunden
aktiv = true;
speichere_alle_zeiten_index = 0;
}else
print_alleZeiten.start();
}
public void stop_stopuhr() {
if (aktiv) {
timer.stop();
print_alleZeiten.stop();
start_zeit.setEnabled(false);
aktiv = false;
} else {
zeige_alleZeiten.setText("");
zeige_zeit.setText("Zeit: 0.0 s");
start_zeit.setEnabled(true);
speichere_alle_zeiten.clear();
}
}
public void update_zeit() {
double rest = (System.currentTimeMillis() - startzeit) / 1000.0;
String formatiere_zahl = String.format("Zeit: %.1f s", rest);
speichere_alle_zeiten.add(formatiere_zahl);
zeige_zeit.setText(formatiere_zahl);
}
public void print_next_time() {
zeige_alleZeiten.append(speichere_alle_zeiten_index + 1 + ".: " + speichere_alle_zeiten.get(speichere_alle_zeiten_index) + "\n");
speichere_alle_zeiten_index++;
}
public static void main(String[] args) {
new Stopuhr();
}
public ArrayList<String> getalleZeiten() {
return speichere_alle_zeiten;
}
public void zeite_elemente() {
zeige_zeit = new JLabel("Zeit: 0.0 s");
zeige_zeit.setFont(new Font("Tahoma", Font.BOLD, 16));
zeige_zeit.setBounds(10, 11, 450, 42);
contentPane.add(zeige_zeit);
start_zeit = new JButton("Start/Lap");
start_zeit.setBounds(10, 484, 190, 54);
contentPane.add(start_zeit);
stop_zeit_1 = new JButton("Stop/Löschen");
stop_zeit_1.setBounds(252, 484, 190, 54);
contentPane.add(stop_zeit_1);
zeige_alleZeiten = new JTextArea();
zeige_alleZeiten.setFont(new Font("Arial", Font.BOLD, 15));
zeige_alleZeiten.setBounds(10, 53, 417, 376);
contentPane.add(zeige_alleZeiten);
}
package Übungen;
import javax.swing.*;
import javax.swing.border.EmptyBorder;
import java.awt.*;
import java.util.ArrayList;
public class Stopuhr extends JFrame {
JPanel contentPane;
JLabel zeige_zeit;
JButton start_zeit;
Timer timer;
long startzeit;
public Stopuhr() {
this.setTitle("Stopuhr");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 498, 630);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
zeite_elemente();
start_programm();
this.setVisible(true);
}
public void start_programm() {
timer = new Timer(1000, e -> update_zeit());
start_zeit.addActionListener(e -> start_stopuhr());
}
public void start_stopuhr() {
timer.start();
startzeit = System.currentTimeMillis(); // Milisekunden
}
public void update_zeit() {
double rest = (System.currentTimeMillis() - startzeit) / 1000.0;
String formatiere_zahl = String.format("Zeit: %.1f s", rest);
zeige_zeit.setText(formatiere_zahl);
System.out.println(formatiere_zahl);
}
public static void main(String[] args) {
new Stopuhr();
}
public void zeite_elemente() {
zeige_zeit = new JLabel("Zeit: 0.0 s");
zeige_zeit.setFont(new Font("Tahoma", Font.BOLD, 16));
zeige_zeit.setBounds(10, 11, 450, 42);
contentPane.add(zeige_zeit);
start_zeit = new JButton("Start/Lap");
start_zeit.setBounds(10, 484, 190, 54);
contentPane.add(start_zeit);
}
}

View File

@ -1,46 +1,45 @@
package Übungen.TaschenrechnerGUI;
import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
public class JunitTest {
// Modell<?, ?> m1;
//
// @BeforeEach
// public void initi() {
// m1 = new Modell<>();
// }
@Test
public void testAdd() {
Modell<Integer, Integer> m1 = new Modell<>();
assertEquals(15 ,m1.add(10, 5).intValue());
}
@Disabled
public void testSub() {
Modell<Integer, Integer> m1 = new Modell<>();
}
@Disabled
public void testmulti() {
Modell<Double, Double> m1 = new Modell<>();
assertEquals(1.44 ,m1.multi(1.2, 1.2).doubleValue());
}
@Disabled
public void testdivid() {
Modell<Integer, Integer> m1 = new Modell<>();
assertEquals(1 ,m1.divid(5, 5).intValue());
}
}
package Übungen.TaschenrechnerGUI;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
public class JunitTest {
// Modell<?, ?> m1;
//
// @BeforeEach
// public void initi() {
// m1 = new Modell<>();
// }
@Test
public void testAdd() {
Modell<Integer, Integer> m1 = new Modell<>();
assertEquals(15 ,m1.add(10, 5).intValue());
}
@Disabled
public void testSub() {
Modell<Integer, Integer> m1 = new Modell<>();
}
@Disabled
public void testmulti() {
Modell<Double, Double> m1 = new Modell<>();
assertEquals(1.44 ,m1.multi(1.2, 1.2).doubleValue());
}
@Disabled
public void testdivid() {
Modell<Integer, Integer> m1 = new Modell<>();
assertEquals(1 ,m1.divid(5, 5).intValue());
}
}

View File

@ -1,156 +1,158 @@
package Übungen.TaschenrechnerGUI;
import java.awt.Color;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class View extends JFrame {
// Fenster Eigenschaften:
final int WIDTH = 500;
final int HEIGHT = 500;
// Fenster Elemente:
JTextField eingabe = new JTextField();
JLabel ergebnisse = new JLabel();
JLabel error = new JLabel();
JButton button1 = new JButton("1");
JButton button2 = new JButton("2");
JButton button3 = new JButton("3");
JButton button4 = new JButton("4");
JButton button5 = new JButton("5");
JButton button6 = new JButton("6");
JButton button7 = new JButton("7");
JButton button8 = new JButton("8");
JButton button9 = new JButton("9");
JButton button0 = new JButton("0");
JButton plus = new JButton("+");
JButton minus = new JButton("-");
JButton multi = new JButton("x");
JButton divid = new JButton("÷");
JButton punkt = new JButton(".");
JButton berechnen = new JButton("=");
JButton clear = new JButton("C");
JButton back = new JButton("←");
int buttonWidth = 60;
int buttonheight = 30;
public View() {
this.setTitle("Taschenrechner");
this.setSize(WIDTH, HEIGHT);
this.setResizable(false);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLocationRelativeTo(null);
this.setVisible(true);
this.setLayout(null);
ergebnisse.setBounds(40, 60, 300, 40);
error.setBounds(40, 60, 100, 30);
eingabe.setBounds(40, 100, buttonWidth * 6 + 20, 40);
button1.setBounds(40,150,buttonWidth,buttonheight);
button2.setBounds(120,150,buttonWidth,buttonheight);
button3.setBounds(200,150,buttonWidth,buttonheight);
button4.setBounds(40,190,buttonWidth,buttonheight);
button5.setBounds(120,190,buttonWidth,buttonheight);
button6.setBounds(200,190,buttonWidth,buttonheight);
button7.setBounds(40,230,buttonWidth,buttonheight);
button8.setBounds(120,230,buttonWidth,buttonheight);
button9.setBounds(200,230,buttonWidth,buttonheight);
button0.setBounds(40,270,buttonWidth*2 + 20,buttonheight);
punkt.setBounds(200, 270, buttonWidth, buttonheight);
plus.setBounds(280, 150, buttonWidth, buttonheight);
plus.setBackground(Color.GRAY);
plus.setForeground(Color.WHITE);
minus.setBounds(280, 190, buttonWidth, buttonheight);
minus.setBackground(Color.GRAY);
minus.setForeground(Color.WHITE);
multi.setBounds(280, 230, buttonWidth, buttonheight);
multi.setBackground(Color.GRAY);
multi.setForeground(Color.WHITE);
divid.setBounds(280, 270, buttonWidth, buttonheight);
divid.setBackground(Color.GRAY);
divid.setForeground(Color.WHITE);
clear.setBackground(Color.RED);
clear.setForeground(Color.white);
clear.setBounds(360,150 , buttonWidth, buttonheight);
back.setBackground(Color.ORANGE);
back.setForeground(Color.white);
back.setBounds(360,190, buttonWidth, buttonheight);
berechnen.setBackground(Color.GRAY);
berechnen.setForeground(Color.WHITE);
berechnen.setBounds(360, 230, buttonWidth, buttonheight* 2 + 10);
this.add(clear);
this.add(error);
this.add(ergebnisse);
this.add(eingabe);
this.add(button1);
this.add(button2);
this.add(button3);
this.add(button4);
this.add(button5);
this.add(button6);
this.add(button7);
this.add(button8);
this.add(button9);
this.add(button0);
this.add(punkt);
this.add(plus);
this.add(minus);
this.add(multi);
this.add(divid);
this.add(berechnen);
this.add(back);
}
public void updateErgebnisse(String erg) {
ergebnisse.setText(erg);
}
public void showError(String err) {
ergebnisse.setText(err);
}
public void setEingabe(String auswahl) {
eingabe.setText(auswahl);
}
public void setAction(ActionListener actionListener) {
button1.addActionListener(actionListener);
button2.addActionListener(actionListener);
button3.addActionListener(actionListener);
button4.addActionListener(actionListener);
button5.addActionListener(actionListener);
button6.addActionListener(actionListener);
button7.addActionListener(actionListener);
button8.addActionListener(actionListener);
button9.addActionListener(actionListener);
button0.addActionListener(actionListener);
punkt.addActionListener(actionListener);
plus.addActionListener(actionListener);
minus.addActionListener(actionListener);
divid.addActionListener(actionListener);
multi.addActionListener(actionListener);
eingabe.addActionListener(actionListener);
berechnen.addActionListener(actionListener);
clear.addActionListener(actionListener);
back.addActionListener(actionListener);
}
}
package Übungen.TaschenrechnerGUI;
import java.awt.Color;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class View extends JFrame {
// Fenster Eigenschaften:
final int WIDTH = 500;
final int HEIGHT = 500;
// Fenster Elemente:
JTextField eingabe = new JTextField();
JLabel ergebnisse = new JLabel();
JLabel error = new JLabel();
JButton button1 = new JButton("1");
JButton button2 = new JButton("2");
JButton button3 = new JButton("3");
JButton button4 = new JButton("4");
JButton button5 = new JButton("5");
JButton button6 = new JButton("6");
JButton button7 = new JButton("7");
JButton button8 = new JButton("8");
JButton button9 = new JButton("9");
JButton button0 = new JButton("0");
JButton plus = new JButton("+");
JButton minus = new JButton("-");
JButton multi = new JButton("x");
JButton divid = new JButton("÷");
JButton punkt = new JButton(".");
JButton berechnen = new JButton("=");
JButton clear = new JButton("C");
JButton back = new JButton("←");
int buttonWidth = 60;
int buttonheight = 30;
public View() {
this.setTitle("Taschenrechner");
this.setSize(WIDTH, HEIGHT);
this.setResizable(false);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLocationRelativeTo(null);
this.setVisible(true);
getContentPane().setLayout(null);
ergebnisse.setBounds(40, 60, 300, 40);
error.setBounds(40, 60, 100, 30);
eingabe.setBounds(40, 100, buttonWidth * 6 + 20, 40);
button1.setBounds(40,150,buttonWidth,buttonheight);
button2.setBounds(120,150,buttonWidth,buttonheight);
button3.setBounds(200,150,buttonWidth,buttonheight);
button4.setBounds(40,190,buttonWidth,buttonheight);
button5.setBounds(120,190,buttonWidth,buttonheight);
button6.setBounds(200,190,buttonWidth,buttonheight);
button7.setBounds(40,230,buttonWidth,buttonheight);
button8.setBackground(new Color(0, 64, 0));
button8.setForeground(new Color(0, 64, 0));
button8.setBounds(120,230,buttonWidth,buttonheight);
button9.setBounds(200,230,buttonWidth,buttonheight);
button0.setBounds(40,270,buttonWidth*2 + 20,buttonheight);
punkt.setBounds(200, 270, buttonWidth, buttonheight);
plus.setBounds(280, 150, buttonWidth, buttonheight);
plus.setBackground(Color.GRAY);
plus.setForeground(Color.WHITE);
minus.setBounds(280, 190, buttonWidth, buttonheight);
minus.setBackground(Color.GRAY);
minus.setForeground(Color.WHITE);
multi.setBounds(280, 230, buttonWidth, buttonheight);
multi.setBackground(Color.GRAY);
multi.setForeground(Color.WHITE);
divid.setBounds(280, 270, buttonWidth, buttonheight);
divid.setBackground(Color.GRAY);
divid.setForeground(Color.WHITE);
clear.setBackground(Color.RED);
clear.setForeground(Color.white);
clear.setBounds(360,150 , buttonWidth, buttonheight);
back.setBackground(Color.ORANGE);
back.setForeground(Color.white);
back.setBounds(360,190, buttonWidth, buttonheight);
berechnen.setBackground(Color.GRAY);
berechnen.setForeground(Color.WHITE);
berechnen.setBounds(360, 230, buttonWidth, buttonheight* 2 + 10);
getContentPane().add(clear);
getContentPane().add(error);
getContentPane().add(ergebnisse);
getContentPane().add(eingabe);
getContentPane().add(button1);
getContentPane().add(button2);
getContentPane().add(button3);
getContentPane().add(button4);
getContentPane().add(button5);
getContentPane().add(button6);
getContentPane().add(button7);
getContentPane().add(button8);
getContentPane().add(button9);
getContentPane().add(button0);
getContentPane().add(punkt);
getContentPane().add(plus);
getContentPane().add(minus);
getContentPane().add(multi);
getContentPane().add(divid);
getContentPane().add(berechnen);
getContentPane().add(back);
}
public void updateErgebnisse(String erg) {
ergebnisse.setText(erg);
}
public void showError(String err) {
ergebnisse.setText(err);
}
public void setEingabe(String auswahl) {
eingabe.setText(auswahl);
}
public void setAction(ActionListener actionListener) {
button1.addActionListener(actionListener);
button2.addActionListener(actionListener);
button3.addActionListener(actionListener);
button4.addActionListener(actionListener);
button5.addActionListener(actionListener);
button6.addActionListener(actionListener);
button7.addActionListener(actionListener);
button8.addActionListener(actionListener);
button9.addActionListener(actionListener);
button0.addActionListener(actionListener);
punkt.addActionListener(actionListener);
plus.addActionListener(actionListener);
minus.addActionListener(actionListener);
divid.addActionListener(actionListener);
multi.addActionListener(actionListener);
eingabe.addActionListener(actionListener);
berechnen.addActionListener(actionListener);
clear.addActionListener(actionListener);
back.addActionListener(actionListener);
}
}

View File

@ -1,47 +1,47 @@
package Übungen.TicTac;
import javax.swing.*;
import java.awt.*;
public class SpielfeldGUI {
private JFrame frame;
private JButton[][] buttons;
public SpielfeldGUI() {
frame = new JFrame("Spielfeld");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(300, 300);
// Erstelle ein 3x3 GridLayout
JPanel panel = new JPanel();
panel.setLayout(new GridLayout(3, 3));
// Erstelle das Spielfeld mit 3x3 Buttons
buttons = new JButton[3][3];
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
buttons[i][j] = new JButton("-");
buttons[i][j].addActionListener(e -> {
JButton clickedButton = (JButton) e.getSource();
clickedButton.setText("X"); // Ändert den Text zu "X" beim Klick
});
panel.add(buttons[i][j]);
}
}
// Füge das Panel zum Frame hinzu
frame.add(panel);
frame.setVisible(true); // Zeige das Fenster an
}
public static void main(String[] args) {
// Starte die GUI
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new SpielfeldGUI();
}
});
}
}
package Übungen.TicTac;
import javax.swing.*;
import java.awt.*;
public class SpielfeldGUI {
private JFrame frame;
private JButton[][] buttons;
public SpielfeldGUI() {
frame = new JFrame("Spielfeld");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(300, 300);
// Erstelle ein 3x3 GridLayout
JPanel panel = new JPanel();
panel.setLayout(new GridLayout(3, 3));
// Erstelle das Spielfeld mit 3x3 Buttons
buttons = new JButton[4][4];
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
buttons[i][j] = new JButton("-");
buttons[i][j].addActionListener(e -> {
JButton clickedButton = (JButton) e.getSource();
clickedButton.setText("X"); // Ändert den Text zu "X" beim Klick
});
panel.add(buttons[i][j]);
}
}
// Füge das Panel zum Frame hinzu
frame.add(panel);
frame.setVisible(true); // Zeige das Fenster an
}
public static void main(String[] args) {
// Starte die GUI
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new SpielfeldGUI();
}
});
}
}

View File

@ -1,85 +1,85 @@
package Übungen.TicTac;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import java.awt.Color;
import javax.swing.border.LineBorder;
import javax.swing.JLabel;
import javax.swing.JButton;
import javax.swing.JTextField;
import java.awt.GridLayout;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class View extends JFrame {
private static final long serialVersionUID = 1L;
private JPanel contentPane;
JLabel nameSpieler1;
JLabel nameSpieler2;
JLabel anzahlgewinn1;
JLabel anzahlgewinn2;
JLabel XoderO;
JButton[][] x_o;
public View() {
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setBounds(100, 100, 626, 709);
this.contentPane = new JPanel();
this.contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JPanel panel = new JPanel();
panel.setBorder(new LineBorder(new Color(128, 255, 128), 2));
panel.setBackground(new Color(192, 192, 192));
panel.setBounds(38, 36, 529, 585);
contentPane.add(panel);
panel.setLayout(null);
nameSpieler1 = new JLabel();
nameSpieler1.setBounds(46, 27, 100, 14);
panel.add(nameSpieler1);
anzahlgewinn1 = new JLabel();
anzahlgewinn1.setBounds(46, 52, 100, 14);
panel.add(anzahlgewinn1);
nameSpieler2 = new JLabel();
nameSpieler2.setBounds(391, 27, 100, 14);
panel.add(nameSpieler2);
anzahlgewinn2 = new JLabel();
anzahlgewinn2.setBounds(391, 52, 100, 14);
panel.add(anzahlgewinn2);
XoderO = new JLabel("New label");
XoderO.setBounds(222, 41, 100, 14);
panel.add(XoderO);
JButton btnNewButton = new JButton("New Game");
btnNewButton.setBounds(196, 447, 129, 23);
panel.add(btnNewButton);
JPanel panel_1 = new JPanel();
panel_1.setBounds(101, 125, 312, 291);
panel.add(panel_1);
panel_1.setLayout(new GridLayout(3, 3, 0, 0));
x_o = new JButton[3][3];
for (int i = 0; i < 3; i++)
for (int j = 0; j < 3; j++) {
x_o[i][j] = new JButton("-");
panel_1.add(x_o[i][j]);
}
panel.add(panel_1);
this.setVisible(true);
}
}
package Übungen.TicTac;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import java.awt.Color;
import javax.swing.border.LineBorder;
import javax.swing.JLabel;
import javax.swing.JButton;
import javax.swing.JTextField;
import java.awt.GridLayout;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class View extends JFrame {
private static final long serialVersionUID = 1L;
private JPanel contentPane;
JLabel nameSpieler1;
JLabel nameSpieler2;
JLabel anzahlgewinn1;
JLabel anzahlgewinn2;
JLabel XoderO;
JButton[][] x_o;
public View() {
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setBounds(100, 100, 626, 709);
this.contentPane = new JPanel();
this.contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JPanel panel = new JPanel();
panel.setBorder(new LineBorder(new Color(128, 255, 128), 2));
panel.setBackground(new Color(192, 192, 192));
panel.setBounds(38, 36, 529, 585);
contentPane.add(panel);
panel.setLayout(null);
nameSpieler1 = new JLabel();
nameSpieler1.setBounds(46, 27, 100, 14);
panel.add(nameSpieler1);
anzahlgewinn1 = new JLabel();
anzahlgewinn1.setBounds(46, 52, 100, 14);
panel.add(anzahlgewinn1);
nameSpieler2 = new JLabel();
nameSpieler2.setBounds(391, 27, 100, 14);
panel.add(nameSpieler2);
anzahlgewinn2 = new JLabel();
anzahlgewinn2.setBounds(391, 52, 100, 14);
panel.add(anzahlgewinn2);
XoderO = new JLabel("New label");
XoderO.setBounds(222, 41, 100, 14);
panel.add(XoderO);
JButton btnNewButton = new JButton("New Game");
btnNewButton.setBounds(196, 447, 129, 23);
panel.add(btnNewButton);
JPanel panel_1 = new JPanel();
panel_1.setBounds(101, 125, 312, 291);
panel.add(panel_1);
panel_1.setLayout(new GridLayout(3, 3, 0, 0));
x_o = new JButton[3][3];
for (int i = 0; i < 3; i++)
for (int j = 0; j < 3; j++) {
x_o[i][j] = new JButton("-");
panel_1.add(x_o[i][j]);
}
panel.add(panel_1);
this.setVisible(true);
}
}