java - 使用或覆盖已弃用的 API

标签 java swing awt

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/

相关文章:

java - 如何更改或查找 JTable 中的列类型

Java:如何将 JMenu 添加到 JPanel 或创建下拉按钮?

java - 确定 Canvas 何时调整大小的最佳实践是什么?

java - 为什么 paint() 方法不执行 update() 或 paint() 方法?

java - 计算java字符串中句子的个数

java - Wicket setPageExpiredErrorPage 仅针对特定页面?

java - Jslider不会出现在网格上

java - Graphics.drawString() 不是绘图

java - 从类方法返回 HSSFSheet

java - 如何在 HttpURLConnection 上设置实体