![]() |
![]() |
|
|
|||||||
| Programmierung Rat & Tat für Programmierer |
|
|
Themen-Optionen | Ansicht |
|
|
#5 |
|
Inventar
![]() Registriert seit: 13.06.2001
Beiträge: 1.830
|
Kommt drauf an wo und wann die Farbe überprüft werden soll.
Ich würde mal folgendes probieren: Code:
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class testspiel extends java.applet.Applet implements Runnable {
public void init() {
}
public void start() {
}
public void stop() {
}
[...]
public void run() {
int x=1,y=1;
try{
Color c=getPixColor(x,y);
/*irgendetwas mit c machen*/
}
catch (IllegalArgumentException e){
/*Ein Fehler ist aufgetreten*/
}
[...]
}
public void paint(Graphics g) {
[...]
}
private Color getPixColor(int x, int y){
Color col;
GraphicsDevice screen;
try{screen=getDefaultScreenDevice();}
catch (HeadlessException e){throw new IllegalArgumentException ("No defaultScreenDevice");}
try{
Robot myRobbie=new Robot(screen);
col=myRobbie.getPixelColor(x,y)
}
catch(RuntimeException e){throw new IllegalArgumentException(e.getMessage());}
return col;
}
}
____________________________________
Join the DNRC | Godwin\'s Law (thx@stona) Documentation is like sex: If it\'s good, it\'s very, very good. If it\'s bad, it\'s better than nothing. \"In theory, theory and practice are the same. In practice, they are not\" (Lawrence Berra) |
|
|
|
| Aktive Benutzer in diesem Thema: 1 (Registrierte Benutzer: 0, Gäste: 1) | |
|
|