-Xlint:deprecation

1 resposta
M

Ao compilar a classe abaixo ele diz para usar javac -Xlint:deprecation… e quando usos esse negócio ele aparece: deprecation show() in java.awt.window has been deprecated… porque?

import java.sql.<em>;

import javax.swing.</em>;

import java.awt.<em>;

import java.awt.event.</em>;
class Exemplo1303 extends JFrame implements ActionListener

{

JLabel L1,L2,L3,L4,L5,L6,L7,L8;

JButton b1,b2,b3,b4,b5,b6;

JTextField tfCodigo,tfNome,tfGenero,tfProdut,tfDatcom,tfAnopro,tfTemdur;

JPanel p1 = new JPanel();

ResultSet rs;
public static void main(String args[])

{

JFrame Janela = new Exemplo1303();

Janela.show();

WindowListener x = new WindowAdapter()

{

public void windowClosing(WindowEvent e)

{

System.exit(0);

}

};

Janela.addWindowListener(x);

}
Exemplo1303()

{

p1.setLayout(new FlowLayout(FlowLayout.LEFT));

L1 = new JLabel(“Código “);

L2 = new JLabel(“Título”);

L3 = new JLabel(“Gênero”);

L4 = new JLabel(“Produtora”);

L5 = new JLabel(“Data de Compra  “);

L6 = new JLabel(“Ano de Produção”);

L7 = new JLabel(“Tempo de Duração”);

L8 = new JLabel(” “);

for (int i=0;i<60;i++)

L8.setText(L8.getText()+” “);

tfCodigo = new JTextField(10);

tfCodigo.addActionListener(this);

tfNome = new JTextField(35);

tfGenero = new JTextField(10);

tfProdut = new JTextField(15);

tfDatcom = new JTextField(8);

tfAnopro = new JTextField(5);

tfTemdur = new JTextField(5);

b1=new JButton(“Próximo”);

b2=new JButton(“Anterior”);

b3=new JButton(“Primeiro”);

b4=new JButton(“Último”);

b5=new JButton(”+10 registros”);

b6=new JButton(”-10 registros”);

b1.setBackground(new Color(180,180,250));

b2.setBackground(new Color(180,180,250));

b3.setBackground(new Color(180,180,250));

b4.setBackground(new Color(180,180,250));

b5.setBackground(new Color(180,180,250));

b6.setBackground(new Color(180,180,250));

b1.addActionListener(this);

b2.addActionListener(this);

b3.addActionListener(this);

b4.addActionListener(this);

b5.addActionListener(this);

b6.addActionListener(this);

p1.add(L1); p1.add(tfCodigo); p1.add(L2); p1.add(tfNome);

p1.add(L3); p1.add(tfGenero); p1.add(L4); p1.add(tfProdut);

p1.add(L5); p1.add(tfDatcom); p1.add(L6); p1.add(tfAnopro);

p1.add(L7); p1.add(tfTemdur); p1.add(L8); p1.add(b3);

p1.add(b2); p1.add(b1); p1.add(b4);p1.add(b5);p1.add(b6);

getContentPane().add(p1);

setTitle(“Navegação da tabela de Filmes”);

setSize(600,140);

setResizable(false);

String url = “jdbc:odbc:MeuBanco”;

try

{

Class.forName( “sun.jdbc.odbc.JdbcOdbcDriver” );

Connection MinhaConexao = DriverManager.getConnection(url);

Statement MeuState = MinhaConexao.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,

ResultSet.CONCUR_READ_ONLY);

rs = MeuState.executeQuery(“SELECT * FROM Filmes”);

rs.first();

atualizaCampos();

}

catch(ClassNotFoundException ex)

{

System.out.println(“Driver JDBC-ODBC não encontrado!”);

}

catch(SQLException ex)

{

System.out.println(“Problemas na conexao com a fonte de dados”);

}

}
public void actionPerformed(ActionEvent e)

{

try

{

if (e.getSource()==b1)

rs.next();

if (e.getSource()==b2)

rs.previous();

if (e.getSource()==b3)

rs.first();

if (e.getSource()==b4)

rs.last();

if (e.getSource()==b5)

rs.relative(10);

if (e.getSource()==b6)

rs.relative(-10);
atualizaCampos(); 
} 
catch(SQLException ex)
{
	// tratamento de erros durante a navegação
}

}

public void atualizaCampos()

{

try

{

tfCodigo.setText(rs.getString(“Ficodigo”));

tfNome.setText(rs.getString(“Finome”));

tfGenero.setText(rs.getString(“Figenero”));

tfProdut.setText(rs.getString(“Fiprodut”));

tfDatcom.setText(""+rs.getDate(“Fidatcom”));

tfAnopro.setText(rs.getString(“Fianopro”));

tfTemdur.setText(rs.getString(“Fitemdur”));

}

catch(SQLException ex)

{  }

}

}

1 Resposta

D

Quando aparece essa mensagem é porque você usou um método depreciado.

No entanto, mesmo assim, ele compila o código, gerando o .class

Todavia, evite usar métodos depreciados, pois eles são inadequados e existem métodos melhores.

No seu caso, você usou o show(), mas o método adequado seria o setVisible(true)

Falow

Criado 28 de abril de 2005
Ultima resposta 29 de abr. de 2005
Respostas 1
Participantes 2