2013-11-15 45 views
0
import java.awt.*; 
import javax.swing.*; 
import java.util.*; 

public class JBall extends JFrame{ 
JBallPanel news=new JBallPanel(); 
public JBall(){ 

super("JBall"); 
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
setSize(420,220); 
JPanel pane=new JPanel(); 
pane.setLayout(new GridLayout(1,1,15,15)); 
    pane.add(news); 
    setContentPane(pane); 
show(); 
news.scroll(); 
} 
public static void main(String arg[]){ 
JBall head=new JBall(); 
} 
} 
class JBallPanel extends JPanel{ 
String[] headlines={"hello","how are you?"}; 
int y=76; 
void scroll(){ 
while(true){ 
y=y-1; 
if(y<-7) 
y=76; 
repaint(); 
try{ 
Thread.sleep(250); 
}catch(InterruptedException e){} 
} 
} 
public void paintComponent(Graphics comp){ 
Graphics2D comp2D=(Graphics2D)comp; 
comp.setColor(getBackground()); 
comp.fillRect(0,0,getSize().width,getSize().height); 
comp2D.setColor(Color.blue); 
for(int i=0;i<headlines.length;i++) 
comp2D.drawString(headlines[i],5,y+(20*i)); 
} 
} 

當我運行上面的代碼時,它說JBall.java使用或覆蓋棄用的API並使用-Xlint:deprecation重新編譯以獲取詳細信息。請幫我弄清楚我出錯的地方。謝謝使用或覆蓋棄用的API

+0

「用-Xlint重新編譯:deprecation for details」 –

+1

[Recompile with -Xlint:deprecation for details](http://stackoverflow.com/questions/12558231/recompile-with-xlintdeprecation-for-details) –

回答

1

show();是使用setVisible(true)查看。

以下是對java文檔的描述。

已棄用。從JDK 1.5版開始,由setVisible(boolean)取代。

使窗口可見。如果窗口和/或其所有者尚不可顯示,則兩者均可顯示。在使窗口可見之前,該窗口將被驗證爲 。如果窗口已經可見,這個 將把窗口放在前面。

0

show()函數已被棄用;將其替換爲setVisible(true)

只是爲了理解:使用不推薦使用的東西在大多數情況下仍然適用,編寫代碼的人只是建議您不要。這裏的想法是通常應該替換一段代碼,但不應該破壞兼容性;因此舊功能被標記爲@Deprecated批註已廢棄,如果正確完成,將從現在開始描述使用什麼。在該軟件的未來版本中,標記爲棄用的功能可能會被刪除。

+0

非常感謝百萬 – user81883

+0

不客氣。讀取錯誤代碼有助於很多IDE和許多IDE將標記在錯誤代碼中指定的代碼片段。 – blalasaadri