2012-06-13 96 views
0

嘿傢伙有這個非常簡單的問題,但似乎無法弄清楚必須導入這個軟件包叫做it,但我不知道把mac上的實際文件夾放在哪裏,不斷給出一個錯誤package does not exist,這是一個非常愚蠢的問題,但真的不知道該怎麼辦在mac上導入一個軟件包

這裏是代碼(JAVA):

import it.*; 
import java.awt.*; 

public class pyramidColour 
{   
    public static void main (String[] args) 
    { 
    int col1 = (int)(Math.random()*255+1); 
    int col2 = (int)(Math.random()*255+1); 
    int col3 = (int)(Math.random()*255+1); 

    Color newCol = new Color (col1, col2, col3); 

    Gogga bug= new Gogga();//creating the gogga 
    Gogga(1,8); 

    for (int i = 1; i <= 4; i ++)//loop for going up 
    { 
     bug.move(); 
     bug.turnRight(); 
     bug.move(); 
     bug.turnLeft(); 
    } 

    bug.setDirection(bug.DOWN); 

    for (int i = 1; i <= 3; i ++)//loop for going down 
    {   
     bug.move(); 
     bug.turnLeft(); 
     bug.move(); 
     bug.turnRight();   
    } 

    bug.move(); 
    bug.turnRight(); 

    for (int i = 1; i <= 7; i ++)//loop for base of pyramid 
    { 
     bug.move(); 
    }   
    } 
} 

該項目的下一部分是放環插入的方法,任何幫助將不勝感激。

+0

你能UND顯示您的文件夾結構,你如何試圖編譯/運行的代碼? Maby你的'CLASS_PATH'必須改變嗎? – tbraun89

+0

你正在使用哪個IDE? –

回答

1

你必須包括在包中的java命令的類路徑:

java -cp .;<path to the it classes> pyramidColour 

.之前;立場當前目錄中,其中pyramidColour類存儲。

編輯:Mac上的分隔符不是;:(感謝加斯帕)

如果您使用的是IDE(Eclipse中,Netbeans的),你可以簡單地添加庫在項目屬性。

+2

在Mac上它應該是':'而不是';'。 – Jesper

+0

「it」文件夾在我的桌面上(對不起,你們新來的java) – FluX

+0

@Jesper謝謝我編輯過。 –

0

包類似於文件夾,因此您必須將這些包放入與導入它的代碼相同的父文件夾中。所以它應該像

article應該會幫助你。

+0

java -cp。:Desktop/it pyramidColour – FluX

1

這裏是jGrasp

工作的例子
import java.awt.*; 
import it.*; 
public class DiscoSquares 
{ 
    public static void main(String[] args) 
    { 
     int red, green, blue; 
     Color col = new Color(255, 0, 0); 
     Gogga.setGridSize(17, 17); 
     Gogga bug = new Gogga(); 
     bug.setTrailWidth(150); 
     for (int dir = 1; dir <=4; dir++) 
     { 
      bug.setDirection (dir); 
      for(int sides=1;sides<=4;sides++) 
      { 
       for(int length=1;length<=5;length++) 
       { 
        bug.move(); 
       } 
       bug.turnLeft(); 
      } 
      if(dir==4) 
       dir = 0; 
     red = (int)(Math.random()*255+1); 
      green = (int)(Math.random()*255+1); 
      blue = (int)(Math.random()*255+1); 
      col = new Color(red, green, blue); 
      bug.setColor(col); 
     } 
    } 
} 
相關問題