Witam :)
Prosze o pomoc w napisaniu aplikacji ktora by umozliwiala otwieranie zdjec.Prosze o wskazanie błędu lub jakiś poprawek, lub jeżeli ktos ma napisaną taką aplikacje w inny sposob to bede wdzieczny za pomoc.
Napisalem cos takiego na razie, jednak po wybraniu pliku jpg pisze tylko "opening" i zdjecie sie nie otwiera :(
Kod wyglada nastepujaco
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.File;
public class projekt extends JFrame implements ActionListener {
JButton open, save;
JTextArea pole;
JFileChooser fc;
projekt(){
pole = new JTextArea(5,20);
fc = new JFileChooser();
open = new JButton("Otworz");
open.addActionListener(this);
save = new JButton("Zapisz");
save.addActionListener(this);
JPanel buttonPanel = new JPanel();
buttonPanel.add(open);
buttonPanel.add(save);
add(buttonPanel, BorderLayout.PAGE_START);
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == open) {
int returnVal = fc.showOpenDialog(projekt.this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = fc.getSelectedFile();
pole.append("Opening: " + file.getName() + "." );
} else {
pole.append("Open command cancelled by user." );
}
pole.setCaretPosition(pole.getDocument().getLength());
}
else if (e.getSource() == save) {
int returnVal = fc.showSaveDialog(projekt.this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = fc.getSelectedFile();
pole.append("Saving: " + file.getName() + "." );
} else {
pole.append("Save command cancelled by user." );
}
pole.setCaretPosition(pole.getDocument().getLength());
}
}
protected static ImageIcon createImageIcon(String path) {
java.net.URL imgURL = FileChooserDemo.class.getResource(path);
if (imgURL != null) {
return new ImageIcon(imgURL);
} else {
System.err.println("Couldn't find file: " + path);
return null;
}
}
private static void createAndShowGUI() {
JFrame frame = new JFrame("przegladarka");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(new FileChooserDemo());
frame.pack();
frame.setVisible(true);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
UIManager.put("swing.boldMetal", Boolean.FALSE);
createAndShowGUI();
}
});
}
}