0
我一直在爲此苦苦掙扎了一段時間,但沒有找到解決方法。當用戶將鼠標懸停在顯示在PGraphics對象旁邊的特定標記上時,我試圖顯示工具提示(包含一些文本的不同顏色的矩形框)。它在java中編程並使用PApplet類作爲Java applet運行。PGraphics文字(工具提示)顯示在圖像上方顯示爲亂碼
問題是,文字看不清楚,因爲並非所有文字都停留在其他圖像之上。儘管顏色被更改並保留爲工具提示的顏色,但其他標記的邊緣仍保留在頂部。
這裏是代碼的一部分,以更好地解釋什麼,我試圖做的:
// Common piece of drawing method for markers;
// Note that you should implement this by making calls
// drawMarker and showTitle, which are abstract methods
// implemented in subclasses
public void draw(PGraphics pg, float x, float y) {
// For starter code just drawMaker(...)
if (!hidden) {
drawMarker(pg, x, y);
if (selected) {
showTitle(pg, x, y); // You will implement this in the subclasses
}
}
}
@Override
public void drawMarker(PGraphics pg, float x, float y) {
// TODO Auto-generated method stub
pg.pushStyle();
// IMPLEMENT: drawing triangle for each city
pg.fill(150, 30, 30);
pg.triangle(x, y-TRI_SIZE, x-TRI_SIZE, y+TRI_SIZE, x+TRI_SIZE, y+TRI_SIZE);
// Restore previous drawing style
pg.popStyle();
}
public void showTitle(PGraphics pg, float x, float y)
{
// TODO: Implement this method
pg.pushStyle();
pg.fill(255, 255, 202);
pg.rect(x+TRI_SIZE+1, y-TRI_SIZE, 150, 15);
pg.textAlign(PConstants.LEFT, PConstants.CENTER);
pg.fill(0,0,0);
pg.text(getCity()+", " + getCountry() + ", " + getPopulation(), x+TRI_SIZE+2, y);
// Restore previous drawing style
pg.popStyle();
}
是否可以刪除不顯示一些標記或其他方式的邊緣,以確保提示總是留在上面?在此先感謝