Compare commits

...

13 Commits

22 changed files with 1036 additions and 6 deletions

View File

@@ -9,7 +9,7 @@ public class Aufgabe04 {
public static void main(String[] args) {
final int laufzeit = 4;
final double startwert = 100.0;
final double[] zinssaetze = { 2.0, 2.5, 3.0 };
final double[] zinssaetze = new double[] { 2.0, 2.5, 3.0 };
double entwicklung[][] = new double[laufzeit][zinssaetze.length];
for (int i = 0; i < laufzeit; i++) {

View File

@@ -11,7 +11,7 @@ public class Aufgabe05 {
final int DIR_RIGHT = 1;
final int NUM_FROGS = 100;
int[] numbersrow = new int[1000];
int[] bucket = { 0, 0 };
int[] bucket = new int[] { 0, 0 };
int position = 1;
int position_max = position;

View File

@@ -27,7 +27,7 @@ public class Aufgabe01 {
* @return The fibonacci number.
*/
private static int iterativeFibonacci(int nth) {
int[] fib = { 1, 1 };
int[] fib = new int[] { 1, 1 };
for (int i = 0; i <= nth; i++) {
if (i < fib.length)

View File

@@ -0,0 +1,38 @@
package VL08.Aufgabe03;
/**
* Vorlesung 8 / Aufgabe 3
*
* @author Sebastian Brosch
*/
public class Aufgabe03 {
public static void main(String[] args) {
Matrix matrixA = new Matrix(2, 3);
matrixA.setValue(0, 0, 3);
matrixA.setValue(0, 1, 2);
matrixA.setValue(0, 2, 1);
matrixA.setValue(1, 0, 1);
matrixA.setValue(1, 1, 0);
matrixA.setValue(1, 2, 2);
Matrix matrixB = new Matrix(3, 2);
matrixB.setValue(0, 0, 1);
matrixB.setValue(0, 1, 2);
matrixB.setValue(1, 0, 0);
matrixB.setValue(1, 1, 1);
matrixB.setValue(2, 0, 4);
matrixB.setValue(2, 1, 0);
System.out.println("------------------");
matrixA.print();
System.out.println("------------------");
matrixB.print();
System.out.println("------------------");
matrixA.multiply(matrixB);
matrixA.print();
System.out.println("------------------");
}
}

154
VL08/Aufgabe03/Matrix.java Normal file
View File

@@ -0,0 +1,154 @@
package VL08.Aufgabe03;
/**
* A class to represent a Matrix.
*/
public class Matrix {
private int rows = 0;
private int columns = 0;
private int[][] matrix;
Matrix(int rows, int columns) {
this.rows = rows;
this.columns = columns;
this.matrix = new int[this.rows][this.columns];
for (int rowIndex = 0; rowIndex < this.rows; rowIndex++) {
for (int columnIndex = 0; columnIndex < this.columns; columnIndex++) {
this.matrix[rowIndex][columnIndex] = 0;
}
}
}
/**
* Method to get the number of columns.
*
* @return The number of columns.
*/
int getColumns() {
return this.columns;
}
/**
* Method to get the number of rows.
*
* @return The number of rows.
*/
int getRows() {
return this.rows;
}
/**
* Method to get the value of a specific field.
*
* @param row The row of the value.
* @param column The column of the value.
* @return The value of the given row and column.
*/
int getValue(int row, int column) {
return this.matrix[row][column];
}
/**
* Method to set the value of a specific field.
*
* @param row The row to set the value.
* @param column The column to set the value.
* @param value The value to be set in the field.
*/
void setValue(int row, int column, int value) {
this.matrix[row][column] = value;
}
/**
* Methode to get the state whether the given Matrix is same size.
*
* @param matrix The Matrix to check for same size.
* @return The state whether the given Matrix is same size.
*/
boolean isSameSize(Matrix matrix) {
return (this.rows == matrix.getRows()) && (this.columns == matrix.getColumns());
}
/**
* Method to add a Matrix to the current Matrix.
*
* @param matrix The Matrix to add to the current Matrix.
*/
void add(Matrix matrix) {
if (!this.isSameSize(matrix)) {
return;
}
for (int rowIndex = 0; rowIndex < this.rows; rowIndex++) {
for (int columnIndex = 0; columnIndex < this.columns; columnIndex++) {
this.matrix[rowIndex][columnIndex] += matrix.getValue(rowIndex, columnIndex);
}
}
}
/**
* Method to multiply a scalar value to the Matrix.
*
* @param scalar The scalar value to multiply the Matrix.
*/
void multiply(int scalar) {
for (int rowIndex = 0; rowIndex < this.rows; rowIndex++) {
for (int columnIndex = 0; columnIndex < this.columns; columnIndex++) {
this.matrix[rowIndex][columnIndex] *= scalar;
}
}
}
/**
* Method to multiply a Matrix to the Matrix.
*
* @param matrix The Matrix to multiply with this Matrix.
* @return State whether the multiplication of the Matrix was successful.
*/
boolean multiply(Matrix matrix) {
// multiplication is not possible if there are no rows or no columns.
if (this.getColumns() == 0 || this.getRows() == 0) {
return false;
}
// multiplication is only possible if the number of rows of Matrix A
// is equals to the number of columns of Matrix B.
if (this.getColumns() != matrix.getRows()) {
return false;
}
int[][] tempMatrix = new int[this.matrix.length][this.matrix.length];
for (int rowIndex = 0; rowIndex < this.getRows(); rowIndex++) {
for (int columnIndex = 0; columnIndex < matrix.getColumns(); columnIndex++) {
tempMatrix[rowIndex][columnIndex] = 0;
for (int fieldIndex = 0; fieldIndex < matrix.getRows(); fieldIndex++) {
tempMatrix[rowIndex][columnIndex] += this.getValue(rowIndex, fieldIndex)
* matrix.getValue(fieldIndex, columnIndex);
}
}
}
this.matrix = tempMatrix;
this.columns = tempMatrix.length;
this.rows = tempMatrix.length;
return true;
}
/**
* Method to print the Matrix.
*/
void print() {
for (int rowIndex = 0; rowIndex < this.rows; rowIndex++) {
for (int columnIndex = 0; columnIndex < this.columns; columnIndex++) {
System.out.printf("%5d", this.getValue(rowIndex, columnIndex));
}
System.out.print("\n");
}
}
}

View File

@@ -0,0 +1,30 @@
package VL08.Aufgabe04;
import VL08.Aufgabe04.PersonenDH.Person;
import VL08.Aufgabe04.PersonenDH.Student;
import VL08.Aufgabe04.PersonenDH.Studiengangsleiter;
import VL08.Aufgabe04.PersonenDH.Dozent;
import VL08.Aufgabe04.PersonenDH.Mitarbeiter;
import java.util.ArrayList;
/**
* Vorlesung 8 / Aufgabe 4
*
* @author Sebastian Brosch
*/
public class Aufgabe04 {
public static void main(String[] args) {
ArrayList<Person> personen = new ArrayList<Person>();
personen.add(new Person("Petra Mustermann", 37));
personen.add(new Student("Max Mustermann", 30, "1234567"));
personen.add(new Dozent("Eva Mustermann", 50, "Informatik"));
personen.add(new Mitarbeiter("Tim Mustermann", 35, "Programmieren"));
personen.add(new Studiengangsleiter("Kevin Mustermann", 40, "BWL", "BWL 1"));
for (Person person : personen) {
person.print();
System.out.println("-------------------------");
}
}
}

View File

@@ -0,0 +1,15 @@
package VL08.Aufgabe04.PersonenDH;
public class Dozent extends Person {
private String specialization;
public Dozent(String name, int age, String specialization) {
super(name, age);
this.specialization = specialization;
}
public void print() {
super.print();
System.out.printf("Fachrichtung: %s\n", specialization);
}
}

View File

@@ -0,0 +1,15 @@
package VL08.Aufgabe04.PersonenDH;
public class Mitarbeiter extends Person {
private String activity;
public Mitarbeiter(String name, int age, String activity) {
super(name, age);
this.activity = activity;
}
public void print() {
super.print();
System.out.printf("Tätigkeit: %s\n", this.activity);
}
}

View File

@@ -0,0 +1,16 @@
package VL08.Aufgabe04.PersonenDH;
public class Person {
String name;
int age;
public Person(String name, int age) {
this.name = name;
this.age = age;
}
public void print() {
System.out.printf("Name: %s\n", this.name);
System.out.printf("Alter: %d\n", this.age);
}
}

View File

@@ -0,0 +1,15 @@
package VL08.Aufgabe04.PersonenDH;
public class Student extends Person {
private String studentNumber;
public Student(String name, int age, String studentNumber) {
super(name, age);
this.studentNumber = studentNumber;
}
public void print() {
super.print();
System.out.printf("Matrikel-Nummer: %s\n", this.studentNumber);
}
}

View File

@@ -0,0 +1,15 @@
package VL08.Aufgabe04.PersonenDH;
final public class Studiengangsleiter extends Dozent {
private String course;
public Studiengangsleiter(String name, int age, String specialization, String course) {
super(name, age, specialization);
this.course = course;
}
public void print() {
super.print();
System.out.printf("Kurs: %s\n", this.course);
}
}

View File

@@ -12,15 +12,15 @@ import java.util.Random;
public class Aufgabe03 {
public static void main(String[] args) {
final int MAX_RUNS = 10;
int[] sizes = { 10000, 20000, 50000, 100000, 200000, 500000, 1000000, 2000000, 5000000, 10000000, 20000000,
50000000 };
int[] sizes = new int[] { 10000, 20000, 50000, 100000, 200000, 500000, 1000000, 2000000, 5000000, 10000000,
20000000, 50000000 };
for (int size : sizes) {
long sumArrayList = 0;
long sumLinkedList = 0;
ArrayList<String> values = getValues(size);
for (int i = 0; i < MAX_RUNS; i++) {
ArrayList<String> values = getValues(size);
sumArrayList += runTestArrayList(values);
sumLinkedList += runTestLinkedList(values);
}

View File

@@ -0,0 +1,18 @@
package VL14.Aufgabe01;
/**
* Vorlesung 14 / Aufgabe 1
*
* @author Sebastian Brosch
*/
class Aufgabe01 {
public static void main(String[] args) {
Counter counterUp = new Counter(1, 100);
Counter counterDown = new Counter(-10);
Thread threadCounterUp = new Thread(counterUp);
Thread threadCounterDown = new Thread(counterDown);
threadCounterUp.start();
threadCounterDown.start();
}
}

View File

@@ -0,0 +1,52 @@
package VL14.Aufgabe01;
/**
* Class representing a counter.
*
* @author Sebastian Brosch
*/
public class Counter implements Runnable {
static int counter;
// some information of the counter.
private int number;
/**
* Create a new counter with initializing the start value.
*
* @param number The number to increment or decrement the counter.
* @param start The start value of the counter.
*/
public Counter(int number, int start) {
this(number);
counter = start;
}
/**
* Create a new counter without initializing the start value.
*
* @param number The number to increment or decrement the counter.
*/
public Counter(int number) {
this.number = number;
}
/**
* Method to run some code in a Thread.
*/
public void run() {
while (counter > 0 && counter < 1000) {
this.count();
}
}
/**
* Method to increment or decrement the counter.
*/
private void count() {
synchronized (getClass()) {
counter += this.number;
System.out.printf("%3d [%s: %3d]\n", counter, Thread.currentThread().getName(), this.number);
}
}
}

View File

@@ -0,0 +1,38 @@
package VL14.Aufgabe02;
import java.util.Random;
/**
* Vorlesung 14 / Aufgabe 2
*
* @author Sebastian Brosch
*/
public class Aufgabe02 {
public static void main(String[] args) throws Exception {
final int NUMBER_OF_USERS = 2;
final int NUMBER_OF_PRINTERS = 2;
// create some printers.
for (int p = 0; p < NUMBER_OF_PRINTERS; p++) {
Thread threadPrinter = new Thread(new Printer());
threadPrinter.start();
}
// create some users.
for (int u = 0; u < NUMBER_OF_USERS; u++) {
Thread threadUser = new Thread(new User(getRandomNumber(1, 10) * 1000));
threadUser.start();
}
}
/**
* Method to determine a random number from a certain range.
*
* @param start The first number of the range.
* @param end The last number of the range.
* @return A random number from a certain range.
*/
private static int getRandomNumber(int start, int end) {
return (new Random()).nextInt((end - start + 1)) + start;
}
}

View File

@@ -0,0 +1,19 @@
package VL14.Aufgabe02;
/**
* Class which represents a printer.
*
* @author Sebastian Brosch
*/
public class Printer implements Runnable {
public void run() {
while (true) {
synchronized (PrinterQueue.queue) {
if (PrinterQueue.queue.size() > 0) {
System.out.println("Printer " + Thread.currentThread().threadId() + " prints: " + PrinterQueue.queue.getFirst());
PrinterQueue.queue.removeFirst();
}
}
}
}
}

View File

@@ -0,0 +1,14 @@
package VL14.Aufgabe02;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
* Class which represents a printer queue.
*
* @author Sebastian Brosch
*/
public class PrinterQueue {
static List<Object> queue = Collections.synchronizedList(new ArrayList<>());
}

36
VL14/Aufgabe02/User.java Normal file
View File

@@ -0,0 +1,36 @@
package VL14.Aufgabe02;
/**
* Class which represents a user.
*
* @author Sebastian Brosch
*/
public class User implements Runnable {
private int number = 0;
private long wait = 0;
/**
* Constructor to initialize a User.
*/
public User() {
this.wait = 1000;
}
/**
* Constructor to initialize a User.
*
* @param wait The time the user is waiting for creating new print jobs.
*/
public User(int wait) {
this.wait = wait;
}
public void run() {
while (this.wait > 0) {
int data = this.number++;
PrinterQueue.queue.add(data);
System.out.println("User " + Thread.currentThread().threadId() + " added " + data);
this.wait--;
}
}
}

View File

@@ -0,0 +1,18 @@
package VL15.Aufgabe01;
import javax.swing.JFrame;
/**
* Vorlesung 15 / Aufgabe 1
*
* @author Sebastian Brosch
*/
public class Aufgabe01 {
public static void main(String[] args) {
Screenshot screenshot = new Screenshot("Screenshot");
screenshot.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
screenshot.setSize(690, 390);
screenshot.setResizable(false);
screenshot.setVisible(true);
}
}

View File

@@ -0,0 +1,238 @@
package VL15.Aufgabe01;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSeparator;
import javax.swing.JTabbedPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.UIManager;
import java.awt.event.WindowListener;
import java.awt.Color;
import java.awt.Font;
import java.awt.Image;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
public class Screenshot extends JFrame {
Screenshot(String title) {
super(title);
JTabbedPane tcMain = new JTabbedPane();
JPanel pnlVerbindungssuche = new JPanel();
pnlVerbindungssuche.setLayout(null);
JPanel pnlErweiterteSuche = new JPanel();
tcMain.addTab("Verbindungssuche", pnlVerbindungssuche);
tcMain.addTab("Erweiterte Suche", pnlErweiterteSuche);
JTextArea txtLanguageMenu = new JTextArea();
txtLanguageMenu.setText("deutsch | english | francais | italiano");
txtLanguageMenu.setBounds(480, 0, 200, 20);
this.getContentPane().add(txtLanguageMenu);
insertHeading("Start & Ziel", pnlVerbindungssuche, 0);
JLabel lblStartZielVon = new JLabel();
lblStartZielVon.setText("Von:");
lblStartZielVon.setBounds(0, 25, 100, 25);
pnlVerbindungssuche.add(lblStartZielVon);
JLabel lblStartZielNach = new JLabel();
lblStartZielNach.setText("Nach:");
lblStartZielNach.setBounds(0, 50, 100, 25);
pnlVerbindungssuche.add(lblStartZielNach);
JLabel lblStartZielBahnhofHaltestelleVon = new JLabel();
lblStartZielBahnhofHaltestelleVon.setText("Bahnhof/Haltestelle");
lblStartZielBahnhofHaltestelleVon.setBounds(100, 25, 150, 25);
lblStartZielBahnhofHaltestelleVon.setFont(lblStartZielBahnhofHaltestelleVon.getFont().deriveFont(Font.PLAIN));
pnlVerbindungssuche.add(lblStartZielBahnhofHaltestelleVon);
JLabel lblStartZielBahnhofHaltestelleNach = new JLabel();
lblStartZielBahnhofHaltestelleNach.setText("Bahnhof/Haltestelle");
lblStartZielBahnhofHaltestelleNach.setBounds(100, 50, 150, 25);
lblStartZielBahnhofHaltestelleNach.setFont(lblStartZielBahnhofHaltestelleNach.getFont().deriveFont(Font.PLAIN));
pnlVerbindungssuche.add(lblStartZielBahnhofHaltestelleNach);
JTextField txtStartZielVon = new JTextField();
txtStartZielVon.setBounds(250, 27, 300, 20);
txtStartZielVon.setBorder(BorderFactory.createLineBorder(Color.black));
pnlVerbindungssuche.add(txtStartZielVon);
JTextField txtStartZielNach = new JTextField();
txtStartZielNach.setBounds(250, 52, 300, 20);
txtStartZielNach.setBorder(BorderFactory.createLineBorder(Color.BLACK));
pnlVerbindungssuche.add(txtStartZielNach);
pnlVerbindungssuche.add(getInfoIcon(555, 27));
JButton btnStartZielUeber = new JButton();
btnStartZielUeber.setText("Über");
btnStartZielUeber.setBounds(555, 52, 65, 20);
pnlVerbindungssuche.add(btnStartZielUeber);
insertHeading("Reisedatum und -zeit", pnlVerbindungssuche, 75);
JLabel lblReisedatumHinfahrt = new JLabel();
lblReisedatumHinfahrt.setText("Hinfahrt:");
lblReisedatumHinfahrt.setBounds(0, 100, 100, 25);
pnlVerbindungssuche.add(lblReisedatumHinfahrt);
JLabel lblReisedatumHinfahrtDatum = new JLabel();
lblReisedatumHinfahrtDatum.setText("Datum:");
lblReisedatumHinfahrtDatum.setBounds(100, 100, 75, 25);
lblReisedatumHinfahrtDatum.setFont(lblReisedatumHinfahrtDatum.getFont().deriveFont(Font.PLAIN));
pnlVerbindungssuche.add(lblReisedatumHinfahrtDatum);
JLabel lblReisedatumHinfahrtUhrzeit = new JLabel();
lblReisedatumHinfahrtUhrzeit.setText("Uhrzeit:");
lblReisedatumHinfahrtUhrzeit.setBounds(100, 125, 50, 25);
lblReisedatumHinfahrtUhrzeit.setFont(lblReisedatumHinfahrtUhrzeit.getFont().deriveFont(Font.PLAIN));
pnlVerbindungssuche.add(lblReisedatumHinfahrtUhrzeit);
JTextField txtReisedatumHinfahrtDatum = new JTextField();
txtReisedatumHinfahrtDatum.setBounds(150, 102, 100, 20);
txtReisedatumHinfahrtDatum.setBorder(BorderFactory.createLineBorder(Color.black));
pnlVerbindungssuche.add(txtReisedatumHinfahrtDatum);
JTextField txtReisedatumHinfahrtUhrzeit = new JTextField();
txtReisedatumHinfahrtUhrzeit.setBounds(150, 127, 50, 20);
txtReisedatumHinfahrtUhrzeit.setBorder(BorderFactory.createLineBorder(Color.black));
pnlVerbindungssuche.add(txtReisedatumHinfahrtUhrzeit);
String uhrzeitTypes[] = { "Ankunft", "Abfahrt" };
JComboBox<String> cmbReisedatumHinfahrtUhrzeitType = new JComboBox<String>(uhrzeitTypes);
cmbReisedatumHinfahrtUhrzeitType.setBounds(205, 127, 100, 20);
pnlVerbindungssuche.add(cmbReisedatumHinfahrtUhrzeitType);
JSeparator sepReisedatum = new JSeparator(SwingConstants.VERTICAL);
sepReisedatum.setBounds(315, 100, 1, 50);
sepReisedatum.setBackground(Color.LIGHT_GRAY);
pnlVerbindungssuche.add(sepReisedatum);
JLabel lblReisedatumRueckfahrt = new JLabel();
lblReisedatumRueckfahrt.setText("Rückfahrt:");
lblReisedatumRueckfahrt.setBounds(325, 100, 100, 25);
pnlVerbindungssuche.add(lblReisedatumRueckfahrt);
JLabel lblReisedatumRueckfahrtDatum = new JLabel();
lblReisedatumRueckfahrtDatum.setText("Datum:");
lblReisedatumRueckfahrtDatum.setBounds(425, 100, 75, 25);
lblReisedatumRueckfahrtDatum.setFont(lblReisedatumRueckfahrtDatum.getFont().deriveFont(Font.PLAIN));
pnlVerbindungssuche.add(lblReisedatumRueckfahrtDatum);
JLabel lblReisedatumRueckfahrtUhrzeit = new JLabel();
lblReisedatumRueckfahrtUhrzeit.setText("Uhrzeit:");
lblReisedatumRueckfahrtUhrzeit.setBounds(425, 125, 50, 25);
lblReisedatumRueckfahrtUhrzeit.setFont(lblReisedatumRueckfahrtUhrzeit.getFont().deriveFont(Font.PLAIN));
pnlVerbindungssuche.add(lblReisedatumRueckfahrtUhrzeit);
JTextField txtReisedatumRueckfahrtDatum = new JTextField();
txtReisedatumRueckfahrtDatum.setBounds(475, 102, 100, 20);
txtReisedatumRueckfahrtDatum.setBorder(BorderFactory.createLineBorder(Color.black));
pnlVerbindungssuche.add(txtReisedatumRueckfahrtDatum);
JTextField txtReisedatumRueckfahrtUhrzeit = new JTextField();
txtReisedatumRueckfahrtUhrzeit.setBounds(475, 127, 50, 20);
txtReisedatumRueckfahrtUhrzeit.setBorder(BorderFactory.createLineBorder(Color.black));
pnlVerbindungssuche.add(txtReisedatumRueckfahrtUhrzeit);
JComboBox<String> cmbReisedatumRueckfahrtUhrzeitType = new JComboBox<String>(uhrzeitTypes);
cmbReisedatumRueckfahrtUhrzeitType.setBounds(530, 127, 100, 20);
pnlVerbindungssuche.add(cmbReisedatumRueckfahrtUhrzeitType);
insertHeading("Angaben zur Preisberechnung", pnlVerbindungssuche, 150);
JLabel lblPreisberechnungReisende = new JLabel();
lblPreisberechnungReisende.setText("Reisende:");
lblPreisberechnungReisende.setBounds(0, 175, 100, 25);
pnlVerbindungssuche.add(lblPreisberechnungReisende);
String personType[] = { "1 Erwachsener", "2 Erwachsene" };
JComboBox<String> cmbPreisberechnungPersonType = new JComboBox<String>(personType);
cmbPreisberechnungPersonType.setBounds(100, 177, 205, 20);
pnlVerbindungssuche.add(cmbPreisberechnungPersonType);
JButton btnPreisberechnungAdd = new JButton();
btnPreisberechnungAdd.setText("Personen hinzufügen");
btnPreisberechnungAdd.setBounds(100, 202, 160, 20);
pnlVerbindungssuche.add(btnPreisberechnungAdd);
pnlVerbindungssuche.add(getInfoIcon(265, 202));
String rabattType[] = { "Keine Ermäßigung", "Bahn-Card 25", "Bahn-Card 50" };
JComboBox<String> cmbPreisberechnungRabattType = new JComboBox<String>(rabattType);
cmbPreisberechnungRabattType.setBounds(315, 177, 210, 20);
pnlVerbindungssuche.add(cmbPreisberechnungRabattType);
JButton btnPreisberechnungAuslandspreise = new JButton();
btnPreisberechnungAuslandspreise.setText("Auslandspreise");
btnPreisberechnungAuslandspreise.setBounds(315, 202, 125, 20);
pnlVerbindungssuche.add(btnPreisberechnungAuslandspreise);
pnlVerbindungssuche.add(getInfoIcon(445, 202));
String klasseType[] = { "1. Klasse", "2. Klasse" };
JComboBox<String> cmbPreisberechnungKlasse = new JComboBox<String>(klasseType);
cmbPreisberechnungKlasse.setBounds(530, 177, 100, 20);
pnlVerbindungssuche.add(cmbPreisberechnungKlasse);
insertHeading("Angaben zur Verbindung", pnlVerbindungssuche, 225);
JLabel lblVerbindungVerkehrsmittel = new JLabel();
lblVerbindungVerkehrsmittel.setText("Verkehrsmittel:");
lblVerbindungVerkehrsmittel.setBounds(0, 250, 100, 25);
pnlVerbindungssuche.add(lblVerbindungVerkehrsmittel);
String searchType[] = { "Standardsuche", "Erweiterte Suche" };
JComboBox<String> cmbVerbindungSucheType = new JComboBox<String>(searchType);
cmbVerbindungSucheType.setBounds(100, 252, 205, 20);
pnlVerbindungssuche.add(cmbVerbindungSucheType);
JButton btnVerbindungAdvanced = new JButton();
btnVerbindungAdvanced.setText("Erweitert");
btnVerbindungAdvanced.setBounds(315, 252, 100, 20);
pnlVerbindungssuche.add(btnVerbindungAdvanced);
pnlVerbindungssuche.add(getInfoIcon(420, 252));
JCheckBox chkVerbindungSchnelleVerbindung = new JCheckBox();
chkVerbindungSchnelleVerbindung.setText("schnelle Verbindungen bevorzugen");
chkVerbindungSchnelleVerbindung.setBounds(100, 277, 235, 20);
pnlVerbindungssuche.add(chkVerbindungSchnelleVerbindung);
pnlVerbindungssuche.add(getInfoIcon(335, 277));
JCheckBox chkVerbindungFahrrad = new JCheckBox();
chkVerbindungFahrrad.setText("Fahrradmitnahme");
chkVerbindungFahrrad.setBounds(370, 277, 150, 20);
pnlVerbindungssuche.add(chkVerbindungFahrrad);
JSeparator sepControls = new JSeparator(SwingConstants.HORIZONTAL);
sepControls.setBounds(0, 300, 670, 1);
sepControls.setBackground(Color.LIGHT_GRAY);
pnlVerbindungssuche.add(sepControls);
JButton btnVerbindungSuchen = new JButton();
btnVerbindungSuchen.setText("Verbindung suchen");
btnVerbindungSuchen.setBounds(0, 305, 150, 20);
pnlVerbindungssuche.add(btnVerbindungSuchen);
JButton btnVerbindungNeueAnfrage = new JButton();
btnVerbindungNeueAnfrage.setText("Neue Anfrage");
btnVerbindungNeueAnfrage.setBounds(155, 305, 125, 20);
pnlVerbindungssuche.add(btnVerbindungNeueAnfrage);
JButton btnMeinAnfrageprofil = new JButton();
btnMeinAnfrageprofil.setText("Mein Anfrageprofil");
btnMeinAnfrageprofil.setBounds(520, 305, 150, 20);
pnlVerbindungssuche.add(btnMeinAnfrageprofil);
this.getContentPane().add(tcMain);
WindowListener closeListener = new WindowAdapter() {
public void windowClosing(WindowEvent event) {
System.exit(0);
}
};
this.addWindowListener(closeListener);
}
private void insertHeading(String title, JPanel panel, int top) {
JLabel lblStartZiel = new JLabel();
lblStartZiel.setText(title);
lblStartZiel.setOpaque(true);
lblStartZiel.setBackground(Color.decode("#ceccfe"));
lblStartZiel.setForeground(Color.decode("#1b0897"));
lblStartZiel.setBounds(0, top, 670, 25);
panel.add(lblStartZiel);
}
/**
* Get a JLabel with displaying the info icon.
*
* @param left The position on the x-axis.
* @param top The position on the y-axis.
* @return The label with info icon.
*/
private JLabel getInfoIcon(int left, int top) {
ImageIcon icon = (ImageIcon) UIManager.get("OptionPane.informationIcon");
Image imgFit = icon.getImage().getScaledInstance(20, 20, java.awt.Image.SCALE_SMOOTH);
JLabel lblInfoIcon = new JLabel(new ImageIcon(imgFit));
lblInfoIcon.setBounds(left, top, 20, 20);
return lblInfoIcon;
}
}

View File

@@ -0,0 +1,18 @@
package VL16.Aufgabe01;
import javax.swing.JFrame;
/**
* Vorlesung 16 / Aufgabe 1
*
* @author Sebastian Brosch
*/
public class Aufgabe01 {
public static void main(String[] args) {
Screenshot screenshot = new Screenshot("Screenshot mit Zusammenfassung");
screenshot.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
screenshot.setSize(690, 390);
screenshot.setResizable(false);
screenshot.setVisible(true);
}
}

View File

@@ -0,0 +1,281 @@
package VL16.Aufgabe01;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JSeparator;
import javax.swing.JTabbedPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.UIManager;
import java.awt.event.WindowListener;
import java.awt.Color;
import java.awt.Font;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
public class Screenshot extends JFrame implements ActionListener {
// Controls (used in events).
JButton btnVerbindungSuchen = new JButton("Verbindung suchen");
JTextField txtStartZielVon = new JTextField();
JTextField txtStartZielNach = new JTextField();
JTextField txtReisedatumHinfahrtDatum = new JTextField();
JTextField txtReisedatumHinfahrtUhrzeit = new JTextField();
String uhrzeitTypes[] = { "Ankunft", "Abfahrt" };
JComboBox<String> cmbReisedatumHinfahrtUhrzeitType = new JComboBox<String>(uhrzeitTypes);
JTextField txtReisedatumRueckfahrtDatum = new JTextField();
JTextField txtReisedatumRueckfahrtUhrzeit = new JTextField();
JComboBox<String> cmbReisedatumRueckfahrtUhrzeitType = new JComboBox<String>(uhrzeitTypes);
String personType[] = { "1 Erwachsener", "2 Erwachsene" };
JComboBox<String> cmbPreisberechnungPersonType = new JComboBox<String>(personType);
String rabattType[] = { "Keine Ermäßigung", "Bahn-Card 25", "Bahn-Card 50" };
JComboBox<String> cmbPreisberechnungRabattType = new JComboBox<String>(rabattType);
String klasseType[] = { "1. Klasse", "2. Klasse" };
JComboBox<String> cmbPreisberechnungKlasse = new JComboBox<String>(klasseType);
String searchType[] = { "Standardsuche", "Erweiterte Suche" };
JComboBox<String> cmbVerbindungSucheType = new JComboBox<String>(searchType);
JCheckBox chkVerbindungSchnelleVerbindung = new JCheckBox();
JCheckBox chkVerbindungFahrrad = new JCheckBox();
Screenshot(String title) {
super(title);
JTabbedPane tcMain = new JTabbedPane();
JPanel pnlVerbindungssuche = new JPanel();
pnlVerbindungssuche.setLayout(null);
JPanel pnlErweiterteSuche = new JPanel();
tcMain.addTab("Verbindungssuche", pnlVerbindungssuche);
tcMain.addTab("Erweiterte Suche", pnlErweiterteSuche);
JTextArea txtLanguageMenu = new JTextArea();
txtLanguageMenu.setText("deutsch | english | francais | italiano");
txtLanguageMenu.setBounds(480, 0, 200, 20);
this.getContentPane().add(txtLanguageMenu);
insertHeading("Start & Ziel", pnlVerbindungssuche, 0);
JLabel lblStartZielVon = new JLabel();
lblStartZielVon.setText("Von:");
lblStartZielVon.setBounds(0, 25, 100, 25);
pnlVerbindungssuche.add(lblStartZielVon);
JLabel lblStartZielNach = new JLabel();
lblStartZielNach.setText("Nach:");
lblStartZielNach.setBounds(0, 50, 100, 25);
pnlVerbindungssuche.add(lblStartZielNach);
JLabel lblStartZielBahnhofHaltestelleVon = new JLabel();
lblStartZielBahnhofHaltestelleVon.setText("Bahnhof/Haltestelle");
lblStartZielBahnhofHaltestelleVon.setBounds(100, 25, 150, 25);
lblStartZielBahnhofHaltestelleVon.setFont(lblStartZielBahnhofHaltestelleVon.getFont().deriveFont(Font.PLAIN));
pnlVerbindungssuche.add(lblStartZielBahnhofHaltestelleVon);
JLabel lblStartZielBahnhofHaltestelleNach = new JLabel();
lblStartZielBahnhofHaltestelleNach.setText("Bahnhof/Haltestelle");
lblStartZielBahnhofHaltestelleNach.setBounds(100, 50, 150, 25);
lblStartZielBahnhofHaltestelleNach.setFont(lblStartZielBahnhofHaltestelleNach.getFont().deriveFont(Font.PLAIN));
pnlVerbindungssuche.add(lblStartZielBahnhofHaltestelleNach);
txtStartZielVon.setBounds(250, 27, 300, 20);
txtStartZielVon.setBorder(BorderFactory.createLineBorder(Color.black));
pnlVerbindungssuche.add(txtStartZielVon);
txtStartZielNach.setBounds(250, 52, 300, 20);
txtStartZielNach.setBorder(BorderFactory.createLineBorder(Color.BLACK));
pnlVerbindungssuche.add(txtStartZielNach);
pnlVerbindungssuche.add(getInfoIcon(555, 27));
JButton btnStartZielUeber = new JButton();
btnStartZielUeber.setText("Über");
btnStartZielUeber.setBounds(555, 52, 65, 20);
pnlVerbindungssuche.add(btnStartZielUeber);
insertHeading("Reisedatum und -zeit", pnlVerbindungssuche, 75);
JLabel lblReisedatumHinfahrt = new JLabel();
lblReisedatumHinfahrt.setText("Hinfahrt:");
lblReisedatumHinfahrt.setBounds(0, 100, 100, 25);
pnlVerbindungssuche.add(lblReisedatumHinfahrt);
JLabel lblReisedatumHinfahrtDatum = new JLabel();
lblReisedatumHinfahrtDatum.setText("Datum:");
lblReisedatumHinfahrtDatum.setBounds(100, 100, 75, 25);
lblReisedatumHinfahrtDatum.setFont(lblReisedatumHinfahrtDatum.getFont().deriveFont(Font.PLAIN));
pnlVerbindungssuche.add(lblReisedatumHinfahrtDatum);
JLabel lblReisedatumHinfahrtUhrzeit = new JLabel();
lblReisedatumHinfahrtUhrzeit.setText("Uhrzeit:");
lblReisedatumHinfahrtUhrzeit.setBounds(100, 125, 50, 25);
lblReisedatumHinfahrtUhrzeit.setFont(lblReisedatumHinfahrtUhrzeit.getFont().deriveFont(Font.PLAIN));
pnlVerbindungssuche.add(lblReisedatumHinfahrtUhrzeit);
txtReisedatumHinfahrtDatum.setBounds(150, 102, 100, 20);
txtReisedatumHinfahrtDatum.setBorder(BorderFactory.createLineBorder(Color.black));
pnlVerbindungssuche.add(txtReisedatumHinfahrtDatum);
txtReisedatumHinfahrtUhrzeit.setBounds(150, 127, 50, 20);
txtReisedatumHinfahrtUhrzeit.setBorder(BorderFactory.createLineBorder(Color.black));
pnlVerbindungssuche.add(txtReisedatumHinfahrtUhrzeit);
cmbReisedatumHinfahrtUhrzeitType.setBounds(205, 127, 100, 20);
pnlVerbindungssuche.add(cmbReisedatumHinfahrtUhrzeitType);
JSeparator sepReisedatum = new JSeparator(SwingConstants.VERTICAL);
sepReisedatum.setBounds(315, 100, 1, 50);
sepReisedatum.setBackground(Color.LIGHT_GRAY);
pnlVerbindungssuche.add(sepReisedatum);
JLabel lblReisedatumRueckfahrt = new JLabel();
lblReisedatumRueckfahrt.setText("Rückfahrt:");
lblReisedatumRueckfahrt.setBounds(325, 100, 100, 25);
pnlVerbindungssuche.add(lblReisedatumRueckfahrt);
JLabel lblReisedatumRueckfahrtDatum = new JLabel();
lblReisedatumRueckfahrtDatum.setText("Datum:");
lblReisedatumRueckfahrtDatum.setBounds(425, 100, 75, 25);
lblReisedatumRueckfahrtDatum.setFont(lblReisedatumRueckfahrtDatum.getFont().deriveFont(Font.PLAIN));
pnlVerbindungssuche.add(lblReisedatumRueckfahrtDatum);
JLabel lblReisedatumRueckfahrtUhrzeit = new JLabel();
lblReisedatumRueckfahrtUhrzeit.setText("Uhrzeit:");
lblReisedatumRueckfahrtUhrzeit.setBounds(425, 125, 50, 25);
lblReisedatumRueckfahrtUhrzeit.setFont(lblReisedatumRueckfahrtUhrzeit.getFont().deriveFont(Font.PLAIN));
pnlVerbindungssuche.add(lblReisedatumRueckfahrtUhrzeit);
txtReisedatumRueckfahrtDatum.setBounds(475, 102, 100, 20);
txtReisedatumRueckfahrtDatum.setBorder(BorderFactory.createLineBorder(Color.black));
pnlVerbindungssuche.add(txtReisedatumRueckfahrtDatum);
txtReisedatumRueckfahrtUhrzeit.setBounds(475, 127, 50, 20);
txtReisedatumRueckfahrtUhrzeit.setBorder(BorderFactory.createLineBorder(Color.black));
pnlVerbindungssuche.add(txtReisedatumRueckfahrtUhrzeit);
cmbReisedatumRueckfahrtUhrzeitType.setBounds(530, 127, 100, 20);
pnlVerbindungssuche.add(cmbReisedatumRueckfahrtUhrzeitType);
insertHeading("Angaben zur Preisberechnung", pnlVerbindungssuche, 150);
JLabel lblPreisberechnungReisende = new JLabel();
lblPreisberechnungReisende.setText("Reisende:");
lblPreisberechnungReisende.setBounds(0, 175, 100, 25);
pnlVerbindungssuche.add(lblPreisberechnungReisende);
cmbPreisberechnungPersonType.setBounds(100, 177, 205, 20);
pnlVerbindungssuche.add(cmbPreisberechnungPersonType);
JButton btnPreisberechnungAdd = new JButton();
btnPreisberechnungAdd.setText("Personen hinzufügen");
btnPreisberechnungAdd.setBounds(100, 202, 160, 20);
pnlVerbindungssuche.add(btnPreisberechnungAdd);
pnlVerbindungssuche.add(getInfoIcon(265, 202));
cmbPreisberechnungRabattType.setBounds(315, 177, 210, 20);
pnlVerbindungssuche.add(cmbPreisberechnungRabattType);
JButton btnPreisberechnungAuslandspreise = new JButton();
btnPreisberechnungAuslandspreise.setText("Auslandspreise");
btnPreisberechnungAuslandspreise.setBounds(315, 202, 125, 20);
pnlVerbindungssuche.add(btnPreisberechnungAuslandspreise);
pnlVerbindungssuche.add(getInfoIcon(445, 202));
cmbPreisberechnungKlasse.setBounds(530, 177, 100, 20);
pnlVerbindungssuche.add(cmbPreisberechnungKlasse);
insertHeading("Angaben zur Verbindung", pnlVerbindungssuche, 225);
JLabel lblVerbindungVerkehrsmittel = new JLabel();
lblVerbindungVerkehrsmittel.setText("Verkehrsmittel:");
lblVerbindungVerkehrsmittel.setBounds(0, 250, 100, 25);
pnlVerbindungssuche.add(lblVerbindungVerkehrsmittel);
cmbVerbindungSucheType.setBounds(100, 252, 205, 20);
pnlVerbindungssuche.add(cmbVerbindungSucheType);
JButton btnVerbindungAdvanced = new JButton();
btnVerbindungAdvanced.setText("Erweitert");
btnVerbindungAdvanced.setBounds(315, 252, 100, 20);
pnlVerbindungssuche.add(btnVerbindungAdvanced);
pnlVerbindungssuche.add(getInfoIcon(420, 252));
chkVerbindungSchnelleVerbindung.setText("schnelle Verbindungen bevorzugen");
chkVerbindungSchnelleVerbindung.setBounds(100, 277, 235, 20);
pnlVerbindungssuche.add(chkVerbindungSchnelleVerbindung);
pnlVerbindungssuche.add(getInfoIcon(335, 277));
chkVerbindungFahrrad.setText("Fahrradmitnahme");
chkVerbindungFahrrad.setBounds(370, 277, 150, 20);
pnlVerbindungssuche.add(chkVerbindungFahrrad);
JSeparator sepControls = new JSeparator(SwingConstants.HORIZONTAL);
sepControls.setBounds(0, 300, 670, 1);
sepControls.setBackground(Color.LIGHT_GRAY);
pnlVerbindungssuche.add(sepControls);
btnVerbindungSuchen.addActionListener(this);
btnVerbindungSuchen.setBounds(0, 305, 150, 20);
pnlVerbindungssuche.add(btnVerbindungSuchen);
JButton btnVerbindungNeueAnfrage = new JButton();
btnVerbindungNeueAnfrage.setText("Neue Anfrage");
btnVerbindungNeueAnfrage.setBounds(155, 305, 125, 20);
pnlVerbindungssuche.add(btnVerbindungNeueAnfrage);
JButton btnMeinAnfrageprofil = new JButton();
btnMeinAnfrageprofil.setText("Mein Anfrageprofil");
btnMeinAnfrageprofil.setBounds(520, 305, 150, 20);
pnlVerbindungssuche.add(btnMeinAnfrageprofil);
this.getContentPane().add(tcMain);
WindowListener closeListener = new WindowAdapter() {
public void windowClosing(WindowEvent event) {
System.exit(0);
}
};
this.addWindowListener(closeListener);
}
/**
* Method to insert a heading to the JFrame.
*
* @param title Title of the heading.
* @param panel The parent panel of the heading.
* @param top The absolute top position of the heading.
*/
private void insertHeading(String title, JPanel panel, int top) {
JLabel lblStartZiel = new JLabel();
lblStartZiel.setText(title);
lblStartZiel.setOpaque(true);
lblStartZiel.setBackground(Color.decode("#ceccfe"));
lblStartZiel.setForeground(Color.decode("#1b0897"));
lblStartZiel.setBounds(0, top, 670, 25);
panel.add(lblStartZiel);
}
/**
* Get a JLabel with displaying the info icon.
*
* @param left The position on the x-axis.
* @param top The position on the y-axis.
* @return The label with info icon.
*/
private JLabel getInfoIcon(int left, int top) {
ImageIcon icon = (ImageIcon) UIManager.get("OptionPane.informationIcon");
Image imgFit = icon.getImage().getScaledInstance(20, 20, java.awt.Image.SCALE_SMOOTH);
JLabel lblInfoIcon = new JLabel(new ImageIcon(imgFit));
lblInfoIcon.setBounds(left, top, 20, 20);
return lblInfoIcon;
}
/**
* Method to react to events of the JFrame.
*
* @param event The event to react.
*/
public void actionPerformed(ActionEvent event) {
Object source = event.getSource();
if (source == btnVerbindungSuchen) {
String infoVerbindung = "";
infoVerbindung += String.format("Verbindung von %s nach %s.\n", txtStartZielVon.getText(), txtStartZielNach.getText());
infoVerbindung += String.format("Hinfahrt: %s am %s um %s Uhr.\n", cmbReisedatumHinfahrtUhrzeitType.getSelectedItem(), txtReisedatumHinfahrtDatum.getText(), txtReisedatumHinfahrtUhrzeit.getText());
infoVerbindung += String.format("Rückfahrt: %s am %s um %s Uhr.\n", cmbReisedatumRueckfahrtUhrzeitType.getSelectedItem(), txtReisedatumRueckfahrtDatum.getText(), txtReisedatumRueckfahrtUhrzeit.getText());
infoVerbindung += String.format("Reisende: %s (%s)\n", cmbPreisberechnungPersonType.getSelectedItem(), cmbPreisberechnungKlasse.getSelectedItem());
infoVerbindung += String.format("Ermäßigung: %s\n", cmbPreisberechnungRabattType.getSelectedItem());
if (chkVerbindungSchnelleVerbindung.isSelected()) {
if (chkVerbindungFahrrad.isSelected()) {
infoVerbindung += "Es soll die schnellste Verbindung mit Fahrradmitnahme gesucht werden.\n";
} else {
infoVerbindung += "Es soll die schnellste Verbindung gesucht werden.\n";
}
} else if (chkVerbindungFahrrad.isSelected()) {
infoVerbindung += "Es sollen nur Verbindungen mit Fahrradmitnahme angezeigt werden.\n";
}
JOptionPane.showMessageDialog(this, infoVerbindung, cmbVerbindungSucheType.getSelectedItem().toString(), JOptionPane.INFORMATION_MESSAGE);
}
}
}