Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > General Coding
You last visited: Today at 04:37

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



Java interface als library

Discussion on Java interface als library within the General Coding forum part of the Coders Den category.

Reply
 
Old   #1
 
epiTR's Avatar
 
elite*gold: 185
Join Date: May 2008
Posts: 3,646
Received Thanks: 603
Java interface als library

Huhu,
ich programmiere gerade ein Tic Tac Toe Spiel. Da ich bestimmte Sachen, wie Spielername, current player etc. speichern möchte, wollte ich ein interface als library benutzen. Leider bekomme ich einen recht seltsamen Fehler und zwar bei:

Library:
Code:
package main;

import java.awt.Color;

public interface Library {
//::::::::::::::::::::::::
	//own data for players
	public enum Player{A, B, NONE}

	//set first player
	public Player firstPlayer = Player.A;
	
	//set current player
	public Player curPlayer = firstPlayer;
	
	//colors for each player
	public final Color COLOR_NONE = Color.white;
	public final Color COLOR_PLAYER_A = Color.blue;
	public final Color COLOR_PLAYER_B = Color.red;
//::::::::::::::::::::::::	
}//end Library (interface)
andere Klasse:
Code:
package main;

import java.awt.Button;
import main.Library;

public class GameControl implements Library {
	//temporary button:
	Button button;
	
	public GameControl(Button hB){
		button = hB;
	}//end Constructor
	
	
	public void calculation(){
                 [COLOR="Red"]curPlayer[/COLOR] = Player.B;
}//end calculation
	
}//end GameControl (class)
curPlayer: The final field Library.curPlayer cannot be assigned

Ich bin noch eher ein Programmieranfänger und kenne mich natürlich nicht 100%ig aus. Ich stehe gerade auf dem Schlauch und kann auch nichts im Internet finden. Ich bedanke mich für Hilfe
epiTR is offline  
Old 05/11/2011, 19:57   #2

 
Obilee's Avatar
 
elite*gold: 144
Join Date: May 2007
Posts: 62,459
Received Thanks: 29,541
In Interfaces kann man keine Variablen definieren , nur Konstanten. Felder in Interfaces sind immer "public static final".

Darum kannst du der Konstanten "curplayer" auch nicht den Wert player.b zuschreiben
Obilee is offline  
Thanks
1 User
Old 05/11/2011, 20:09   #3
 
epiTR's Avatar
 
elite*gold: 185
Join Date: May 2008
Posts: 3,646
Received Thanks: 603
Ok danke dir, werde ich dann anderst lösen müssen.
epiTR is offline  
Old 05/11/2011, 20:11   #4

 
Obilee's Avatar
 
elite*gold: 144
Join Date: May 2007
Posts: 62,459
Received Thanks: 29,541
Du verstehst glaub ich auch den Sinn vom Interface falsch wenn du dies so verwenden willst.
Obilee is offline  
Old 05/11/2011, 20:58   #5
 
epiTR's Avatar
 
elite*gold: 185
Join Date: May 2008
Posts: 3,646
Received Thanks: 603
Ich weiß schon wofür interfaces sind, wusste aber nicht, dass alles final sein muss.
epiTR is offline  
Reply


Similar Threads Similar Threads
FtH User Interface (Complete Interface)
09/05/2006 - World of Warcraft - 10 Replies
Hallo , ich will euch das wohl beste Interface nicht vorenthalten. For the Horde hat mit seiner ersten Version seines eigenen Interfaces schon gute arbeit geleistet. Aber das naja nich mehr ganz aktuele ist noch besser. http://web4.h60972.serverkompetenz.net/for...p?th readid=3465 <- DL Link. Dort gibt es aber auch den kompletten Guide zu dem Interface. Achja FTH benutzt X-Raid , nicht jedem seine Sache. Das Interface ist aber auch mit CT_RAID kompatibel.
Geniales neues Wow-Interface - new WoW-Interface
11/04/2005 - World of Warcraft - 20 Replies
Schaut dann so aus - looks like : http://www.musterplan.de/preview1.jpg http://www.musterplan.de/preview2.jpg Download UI FAQ zum Installieren / Install FAQ:



All times are GMT +1. The time now is 04:38.


Powered by vBulletin®
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2025 elitepvpers All Rights Reserved.