From 84e220b332bfffb0f2dcc39b9697a6fd6691d265 Mon Sep 17 00:00:00 2001 From: Leonard Kugis Date: Mon, 25 Apr 2022 18:36:30 +0200 Subject: Initial commit --- src/aufgaben/b20160425/Aufgabe3.java | 121 +++++++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100755 src/aufgaben/b20160425/Aufgabe3.java (limited to 'src/aufgaben/b20160425/Aufgabe3.java') diff --git a/src/aufgaben/b20160425/Aufgabe3.java b/src/aufgaben/b20160425/Aufgabe3.java new file mode 100755 index 0000000..2a2b242 --- /dev/null +++ b/src/aufgaben/b20160425/Aufgabe3.java @@ -0,0 +1,121 @@ +package aufgaben.b20160425; + +import java.awt.Color; +import java.awt.Graphics; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.IOException; + +import javax.imageio.ImageIO; +import javax.swing.JPanel; +import javax.swing.JSpinner; +import javax.swing.SpinnerNumberModel; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; + +import aufgaben.Aufgabe; +import misc.Utils; + +public class Aufgabe3 extends Aufgabe { + + private final int width = 500, height = 500; + private boolean done = false; + private String name; + private BufferedImage image, todraw; + private JPanel panel; + private JSpinner spinner; + + public Aufgabe3() { + name = "Interpolation"; + this.setSize(width, height); + this.setTitle(name); + this.addWindowListener( + new WindowAdapter() { + @Override + public void windowClosing(WindowEvent e) { + System.out.println("close"); + done = true; + } + } + ); + this.setLayout(null); + } + + @Override + public boolean done() { + return done; + } + + @Override + public String getName() { + return name; + } + + @Override + public void init() { + panel = new JPanel(){ + public void paint(Graphics g) { + if(todraw != null) + g.drawImage(todraw, 0, 0, this.getWidth(), this.getHeight(), this); + } + }; + panel.setBounds(0, 100, width, height-100); + spinner = new JSpinner(new SpinnerNumberModel(0, 0, 100, 1)); + spinner.setBounds(100, 50, 100, 20); + spinner.addChangeListener(new ChangeListener() { + public void stateChanged(ChangeEvent e) { + for(int x = 0; x= 0 && absoluteX < image.getWidth() && absoluteY >= 0 && absoluteY < image.getHeight()) { + color = new Color(image.getRGB(absoluteX, absoluteY)); + colori[0] += color.getRed(); + colori[1] += color.getGreen(); + colori[2] += color.getBlue(); + c++; + } + } + } + return new Color(colori[0]/c, colori[1]/c, colori[2]/c); + } + +} -- cgit v1.2.1