entaum esse e o codigo: vou explicar +ou- como ele tem q funcionar>>
vc clica no botao, ele abre aquela janela padrao de procurar arquivos>vc seleciona uma imagem ,ai ele abre e fica tudo certo…mas eu meu faz ate a parte da janela de procura abrir.,ma ele naum abre a imagem…me ajude com isso por favor!!!
olha o codigo!!!eu sou iniciante nisso ainda…me ajudem por favor!!!
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);
}
}
obrigado…se vc quizerem dar mais dicas podem fazer!!!
