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 重新编译以获取详细信息。请帮我找出哪里出错了。谢谢
最佳答案
show();
已弃用,请使用 setVisible(true)
进行查看。
以下是java文档的描述。
Deprecated. As of JDK version 1.5, replaced by setVisible(boolean).
Makes the Window visible. If the Window and/or its owner are not yet displayable, both are made displayable. The Window will be validated prior to being made visible. If the Window is already visible, this will bring the Window to the front.
关于java - 使用或覆盖已弃用的 API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19999396/