Ajuda!nao consegui ainda!

1 resposta
M

olá!!!

eu ainda nao consegui … olhem o codigo q eu fiz me digam aonde eu errei>>.pois ja faz um tempo q eu mandei esse codigo aqui e ninguem conseguiu me ajudar…e um programa de visualização de imagens…eu clico no botao ele abre aquela janela de procurar aqui …quando eu seleciono a imagem ele nao apareçe a imagem…eu preciso q isso funcione, se alguem pode me ajudar agradeceria muito

o codigo aqui >>>>>

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;

private RandomAccessFile output;

private Image imagem;
public Janela()
{
	super ("Visualizador de Imagens");
	
	Container container = getContentPane();
	
	label = new JLabel ();
	getContentPane().add(
		label,BorderLayout.CENTER);

JPanel northPanel = new JPanel();
northPanel.setLayout(new GridLayout(3,1,0,5));
		
container.add(northPanel,BorderLayout.NORTH);		

openButton = new JButton("Abrir Arquivo");
//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,450);
	setVisible(true);
	show();
	northPanel.add(openButton);
	
}



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();
		
		label = new JLabel(icons[0]);
		//container.add(label);
		
		setSize(400,300);
		setVisible(true);
		
		
		if(fileName == null || fileName.getName().equals(""))
		JOptionPane.showMessageDialog(this,"Nome de Arquivo Invalido","Arquivo Invalido",JOptionPane.ERROR_MESSAGE);
		
		
		
		else{
			
			try{
				output = new RandomAccessFile (fileName,"r");
				
				input = new ObjectInputStream( new FileInputStream(fileName));
				
				openButton.setEnabled(true);
			}
			
			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);
		application.setVisible(true);

	}

}

muito obrigado aqueles q poderem me ajudar e os q nao conseguiu eu agradeço mesmo assim

valeu :twisted:

1 Resposta

B

post o erro que está sendo apresentado!

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