erro3!me ajudem por favor

2 respostas
M

eu fiz esse programinha … lja me responderam…mas mesmo assim continua dando errado…ele ta copilando mas a janela que ele tinha q aparecer nao ta aparecendo…me ajudem
esse e o codigo:

import <a href="http://java.io">java.io</a>.<em>;

import java.awt.</em>;

import java.awt.event.<em>;

import javax.swing.</em>;
public class Janela extends JFrame {

private JLabel label;

private JButton openButton;

private ObjectInputStream input;
public Janela()

{

super (Visualizador de Imagens);
label = new JLabel ();

getContentPane().add(

label,BorderLayout.CENTER);

//openButton = label.getDoTask1Button();
openButton.setText(“Abrir Arquivo”);

openButton.addActionListener(

new ActionListener() {

public void actionPerformed (ActionEvent event)

{

openFile();

}

}

);
addWindowListener (

new WindowAdapter() {

public void windowClosing (WindowEvent event)

{

if(input!=null)

closeFile();
System.exit(0);

}

}

);
pack();

//setSize(500,600);

setVisible(true);

show();

}
private void openFile()

{

JFileChooser fileChooser = new JFileChooser();

fileChooser.setFileSelectionMode(

JFileChooser.FILES_ONLY);

int result = fileChooser.showOpenDialog(this);

if (result == JFileChooser.CANCEL_OPTION)
return;

File fileName = fileChooser.getSelectedFile();

if(fileName == null || fileName.getName().equals(""))
JOptionPane.showMessageDialog(this,“Nome de Arquivo Invalido”,“Arquivo Invalido”,JOptionPane.ERROR_MESSAGE);

else{

try{
input = new ObjectInputStream( new FileInputStream(fileName));

openButton.setEnabled(false);
}

catch (IOException ioException) {

JOptionPane.showMessageDialog(this,Erro ao Abrir o Arquivo,Erro,JOptionPane.ERROR_MESSAGE);

}

}

}
private void closeFile()

{

try{

input.close();

System.exit(0);

}

catch(IOException ioException) {

JOptionPane.showMessageDialog(this,Error closing file,Error,JOptionPane.ERROR_MESSAGE);
System.exit(1);

}

}
public static void main (String args[])

{

Janela application = new Janela();

application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
new Janela();

}

}

obrigado!!! Smile

2 Respostas

M

não extoura nenhuma exception?

obs: procure postar seus códigos identados e dentro da tag CODE.

J

voce nao inicializa openButton

//openButton = label.getDoTask1Button(); openButton.setText("Abrir Arquivo");
provavelmente ta dando algum NullPointerException nessa linha, antes de voce dar o setVisible(true); se você fizer

openButton = new JButton("TEXTO"); antes disso provavelmente vai funcionar…
outra coisa, bota um tamanho inicial nessa janela(usando setSize ou setbounds), porque senao so aparece o titulo da janela, sem conteudo.

espero ter ajudado

Criado 6 de abril de 2005
Ultima resposta 6 de abr. de 2005
Respostas 2
Participantes 3