[英]importing a package on mac
嘿家伙有這個非常簡單的問題,但似乎無法弄清楚必須導入這個包稱為it
但我不知道在Mac上放置實際文件夾的位置,繼續給出錯誤package does not exist
,這是一個非常愚蠢的問題,但真的不知道該怎么做
這是代碼(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();
}
}
}
該項目的下一部分是將循環放入一個方法,任何幫助將不勝感激。
您必須在java命令中包含該包的類路徑:
java -cp .;<path to the it classes> pyramidColour
.
之前;
代表當前目錄,其中存儲了pyramidColour類。
編輯:在Mac上,分隔符不是;
但是:
謝謝Jesper)
如果您使用的是IDE(Eclipse,Netbeans),則只需在項目屬性中添加庫即可。
這是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);
}
}
}
包類似於文件夾,因此您必須將這些包放在與導入它的代碼相同的父文件夾中。 所以應該是這樣的
<it> folder
programs
<another package> folder
pyramidColor
這篇文章應該可以幫到你。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.