first commit

This commit is contained in:
2020-06-12 23:49:11 +02:00
commit ea19e5ad2a
214 changed files with 43291 additions and 0 deletions

11
Paint/Paint.iml Normal file
View File

@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

45
Paint/src/Brush.java Normal file
View File

@@ -0,0 +1,45 @@
import basis.*;
import java.awt.*;
public class Brush {
Stift stift;
public Brush() {
stift = new Stift();
}
public void draw(){
stift.runter();
}
public void dontDraw(){
stift.hoch();
}
public int getBreite(){
return stift.linienBreite();
}
public void setBreite(int breite){
stift.setzeLinienBreite(breite);
}
public void setzePosition(int x, int y){
stift.bewegeAuf(x,y);
}
public void color(int r, int g, int b){
stift.setzeFarbe(Farbe.rgb(r,g,b));
}
public Color getColor(){
return stift.farbe();
}
public void write(String text,int grösse){
stift.setzeSchriftGroesse(grösse);
}
}

28
Paint/src/Canvas.java Normal file
View File

@@ -0,0 +1,28 @@
import basis.*;
public class Canvas
{
Fenster fenster;
public Canvas(int width, int height, String name) {
fenster = new Fenster(width, height);
fenster.setzeTitel(name);
}
public void setBackColor(int r, int g, int b){
fenster.setzeHintergrundFarbe(Farbe.rgb(r,g,b));
}
public java.awt.Color getColor(){
return fenster.hintergrundFarbe();
}
public double wigth(){
return fenster.breite();
}
public void savePicture(){
fenster.speichereZeichenflaeche();
}
}

View File

@@ -0,0 +1,53 @@
import javax.swing.JOptionPane;
public class ColorPicker {
private String input = null;
private String rgbValues(){
String[] choices = {"Rot", "Grün", "Blau", "Lila", "Cyan", "Gelb", "Schwarz", "Weiß", "Rosa", "Selber RGB-Werte eintragen"};
input = (String) JOptionPane.showInputDialog(null, "Choose now...",
"Choose a Color", JOptionPane.QUESTION_MESSAGE, null, // Use default icon
choices, // Initial choice
null);
switch (input){
case "Rot":
return "255,0,0";
case "Grün":
return "0,255,0";
case "Blau":
return "0,0,255";
case "Lila":
return "187,13,222";
case "Cyan":
return "18,224,204";
case "Gelb":
return "246,255,0";
case "Schwarz":
return "0,0,0";
case "Weiß":
return "255,255,255";
case "Rosa":
return "255,84,133";
case "Selber RGB-Werte eintragen":
String n = JOptionPane.showInputDialog("Set value between 0 to 255 for RED,GREEN,BLUE");
return n;
default:
throw new IllegalStateException("Unexpected value: " + input);
}
}
public int[] choseColor(){
String value = rgbValues();
value = value.replaceAll("\\s", "");
String[] parts = value.split(",");
int[] rgb = new int[parts.length];
for (int i = 0; i < parts.length; i++){
rgb[i]= Integer.parseInt(parts[i]);
}
return rgb;
}
}

View File

@@ -0,0 +1,3 @@
Manifest-Version: 1.0
Main-Class: PaintMain

57
Paint/src/Output.java Normal file
View File

@@ -0,0 +1,57 @@
import basis.*;
import java.awt.*;
public class Output {
TextFeld textFeldBreite;
TextFeld textFeldFarbe;
TextFeld textFeldSchrift;
public Output(double fensterbreite, int stiftbreite, Color stiftfarbe) {
textFeldBreite = new TextFeld();
textFeldBreite.setzeText("Stiftbreite: " + stiftbreite);
textFeldBreite.setzeSchriftGroesse(20);
textFeldBreite.setzeGroesse(textFeldBreite.text().length() * 11, 40);
textFeldBreite.setzePosition(fensterbreite - textFeldBreite.breite() - 20, textFeldBreite.hoehe() / 2);
textFeldBreite.entferneRand();
textFeldBreite.setzeHintergrundFarbe(Farbe.DURCHSICHTIG);
textFeldSchrift = new TextFeld();
textFeldSchrift.setzeText("Stiftfarbe: ");
textFeldSchrift.setzeSchriftGroesse(20);
textFeldSchrift.setzeGroesse(textFeldSchrift.text().length()*11, 40);
textFeldSchrift.setzePosition(fensterbreite - textFeldSchrift.breite() - 40, 45);
textFeldSchrift.setzeHintergrundFarbe(Farbe.DURCHSICHTIG);
textFeldSchrift.entferneRand();
textFeldFarbe = new TextFeld();
textFeldFarbe.setzeGroesse(20, 20);
textFeldFarbe.setzePosition(fensterbreite - 65, 55);
textFeldFarbe.setzeHintergrundFarbe(stiftfarbe);
textFeldFarbe.entferneRand();
}
public void updateBreite(int stiftbreite) {
textFeldBreite.setzeText("Stiftbreite: " + stiftbreite);
}
public void updateFarbe(Color stiftfarbe) {
textFeldFarbe.setzeHintergrundFarbe(stiftfarbe);
}
public void readable(Color hintergrundfarbe){
System.out.println(hintergrundfarbe);
if (hintergrundfarbe.equals(Color.black)){
textFeldSchrift.setzeSchriftFarbe(Farbe.WEISS);
textFeldBreite.setzeSchriftFarbe(Farbe.WEISS);
} else{
textFeldSchrift.setzeSchriftFarbe(Farbe.SCHWARZ);
textFeldBreite.setzeSchriftFarbe(Farbe.SCHWARZ);
}
}
}

100
Paint/src/PaintMain.java Normal file
View File

@@ -0,0 +1,100 @@
import basis.*;
import javax.swing.*;
public class PaintMain {
private Canvas c;
private Brush b;
private Picture p;
private ColorPicker color;
private Output o;
private Maus m;
private Tastatur t;
private String text;
private int number;
public PaintMain() {
c = new Canvas(Hilfe.monitorBreite(), Hilfe.monitorHoehe(), "Paint");
b = new Brush();
b.setBreite(4);
color = new ColorPicker();
o = new Output(c.wigth(), b.getBreite(), b.getColor());
m = new Maus();
t = new Tastatur();
text = null;
}
public void run() {
while (!t.istGedrueckt(Zeichen.ESC)) {
Hilfe.kurzePause();
b.setzePosition(m.hPosition(), m.vPosition());
if (m.istGedrueckt()) {
b.draw();
} else {
b.dontDraw();
}
if (t.istGedrueckt(Zeichen.PFEILOBEN) && b.getBreite() < 15) {
b.setBreite(b.getBreite() + 1);
Hilfe.pause(200);
System.out.println("Breite: " + b.getBreite());
o.updateBreite(b.getBreite());
}
if (t.istGedrueckt(Zeichen.PFEILUNTEN) && b.getBreite() > 1) {
b.setBreite(b.getBreite() - 1);
Hilfe.pause(200);
System.out.println("Breite: " + b.getBreite());
o.updateBreite(b.getBreite());
}
if (t.istGedrueckt('f')) {
try {
int[] rgb = color.choseColor();
b.color(rgb[0], rgb[1], rgb[2]);
o.updateFarbe(b.getColor());
} catch (Exception e) {
System.err.println("Failed to pass values");
}
}
if (t.istGedrueckt('s')) {
c.savePicture();
}
if (t.istGedrueckt('b')) {
int[] rgb = color.choseColor();
c.setBackColor(rgb[0], rgb[1], rgb[2]);
o.readable(c.getColor());
}
if (t.istGedrueckt('p')) {
p = new Picture();
p.ladeBild();
}
if (t.istGedrueckt('t')) {
b.write(text = JOptionPane.showInputDialog(null, "Type in the text you want to print on the screen") ,number = Integer.parseInt(JOptionPane.showInputDialog(null,"How big shall the text be?", 30)));
Hilfe.warte(500);
}
}
int n = JOptionPane.showConfirmDialog(null, "Möchten Sie das Projekt vor dem beenden speichern?", "Speichern?", 1, JOptionPane.WARNING_MESSAGE);
if (n == 0) {
c.savePicture();
System.exit(0);
} else if (n == 2) {
run();
} else {
System.exit(0);
}
}
public static void main(String[] args) {
PaintMain m;
m = new PaintMain();
m.run();
}
}

16
Paint/src/Picture.java Normal file
View File

@@ -0,0 +1,16 @@
import basis.*;
public class Picture
{
Bild bild;
public Picture(){
bild = new Bild();
bild.setzeSichtbar(false);
bild.setzeMitMausVerschiebbar(true);
}
public void ladeBild(){
bild.ladeBild();
bild.setzeSichtbar(true);
}
}