WCM - Das österreichische Computer Magazin Forenübersicht
 

Zurück   WCM Forum > Rat & Tat > Programmierung

Programmierung Rat & Tat für Programmierer

Microsoft KARRIERECAMPUS

Antwort
 
Themen-Optionen Ansicht
Alt 10.01.2004, 18:58   #1
heli2sky
Master
 
Registriert seit: 02.10.2001
Alter: 38
Beiträge: 523


heli2sky eine Nachricht über ICQ schicken
Standard java: farbe eines applet-pixels auslesen??

hallo!

wie die überschrift schon sagt, will ich die farbe eines pixels vom applet per koordinaten (x,y) auslesen!!!

wie mach ich das?

ich bitte um eure hilfe!!!!!!!!!!!!
____________________________________
Lang ist der Weg durch Lehren, kurz und wirksam durch Beispiele.
Lucius Annaeus Seneca


...:::www.modellbaulexikon.org:::...

www.acrobat-se.org | www.ams-8c.de.vu
heli2sky ist offline   Mit Zitat antworten
Alt 11.01.2004, 14:04   #2
jak
Inventar
 
Registriert seit: 13.06.2001
Beiträge: 1.830


Standard

In der Robot Klasse gibt es ein getPixelColor():
getPixelColor(int x, int y)

Code:
import java.awt.*;

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)
jak ist offline   Mit Zitat antworten
Alt 11.01.2004, 14:08   #3
jak
Inventar
 
Registriert seit: 13.06.2001
Beiträge: 1.830


Standard

Aufgerufen wird das ganze dann so:
public static void main(String[] args){
int x=1,y=1;
try{Color c=getPixColor(x,y);/*irgendetwas mit c machen*/}
catch (IllegalArgumentException e){/*Ein Fehler ist aufgetreten*/}
}

Jak
____________________________________
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)
jak ist offline   Mit Zitat antworten
Alt 11.01.2004, 17:07   #4
heli2sky
Master
 
Registriert seit: 02.10.2001
Alter: 38
Beiträge: 523


heli2sky eine Nachricht über ICQ schicken
Standard

hallo!

danke für die antwort!!! leider schaff ich es nicht, das einzubauen...

könntest du mir vielleicht helfen, das in dieses applet einzubauen:

PHP-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() {

        [...]
    }
    
    public 
void paint(Graphics g) {
        
        [...]
    }

____________________________________
Lang ist der Weg durch Lehren, kurz und wirksam durch Beispiele.
Lucius Annaeus Seneca


...:::www.modellbaulexikon.org:::...

www.acrobat-se.org | www.ams-8c.de.vu
heli2sky ist offline   Mit Zitat antworten
Alt 12.01.2004, 17:41   #5
jak
Inventar
 
Registriert seit: 13.06.2001
Beiträge: 1.830


Standard

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;
    }

}
Jak
____________________________________
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)
jak ist offline   Mit Zitat antworten
Antwort


Aktive Benutzer in diesem Thema: 1 (Registrierte Benutzer: 0, Gäste: 1)
 

Forumregeln
Es ist Ihnen nicht erlaubt, neue Themen zu verfassen.
Es ist Ihnen nicht erlaubt, auf Beiträge zu antworten.
Es ist Ihnen nicht erlaubt, Anhänge hochzuladen.
Es ist Ihnen nicht erlaubt, Ihre Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.

Gehe zu


Alle Zeitangaben in WEZ +2. Es ist jetzt 15:18 Uhr.


Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Forum SEO by Zoints
© 2009 FSL Verlag