PixelCompetition/Java
Zur Navigation springen
Zur Suche springen
Installation von BlueJ
Linux / Debian:
https://www.bluej.org/debian-ubuntu-oracle-java.html
Windows
--> StandAlone (zip) --> auspacken (z.B. nach c:\tools\bluej)
import java.net.*; import java.io.*; import javax.imageio.*; import java.awt.image.*; import java.awt.*; /** * Write a description of class App here. * * @author Jörn Schlingensiepen * @version 0.0.1 */ public class App { // instance variables - replace the example below with your own public static void main(String[] args) throws Exception{ // Ausgabe von "Hello World!" System.out.println("Hello World!"); String host = "box.pixel-competition.de"; int port = 2342; for (int i = 0; i<100; i++) { System.out.println(i); } // Mit dieser Schreibweise stellt Ihr sicher, dass die Socket in jedem Fall // immer richtig geschlossen wird. Sockets sind im Betriebsystem ja eine endliche // Ressource und wenn Ihr die nicht immer ordentlich schließt und aufräumt, ist // irgendwann Schicht. try (Socket socket = new Socket(host, port)) { OutputStream output = socket.getOutputStream(); PrintWriter writer = new PrintWriter(output, true); writer.println ("PX 100 100 5 5 200"); int r = 5; int g = 5; int b = 200; for (int x = 0; x < 100; x++) { for (int y = 0; y < 100; y++) { String command = String.format ("PX %d %d %d %d %d", x, y, r, g, b); System.out.println(command); writer.println(command); } } BufferedImage image = ImageIO.read(new File("Nut.jpg")); int width = image.getWidth(); int height = image.getHeight(); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { Color color = new Color(image.getRGB(x,y)); String command = String.format ("PX %d %d %d %d %d", x, y, color.getRed(), color.getGreen(), color.getBlue()); System.out.println(command); writer.println(command); } } } catch (UnknownHostException ex) { System.out.println("Server not found: " + ex.getMessage()); } catch (IOException ex) { System.out.println("I/O error: " + ex.getMessage()); } } }