My java codes goal is to place a image on 2 labels. First the user places a image on label b2. Then the user should be able to place a image on label b33. Right now if a image is already on label b2. The image is replaced with the current one. Nothing is being saved to label b33. I want the 2nd image selected to be saved on label b33.
public class may {
Frame f;
JLabel b2=new JLabel("");;
JLabel b33=new JLabel("");;
may() throws IOException{
f=new JFrame();
JButton b1 = new JButton("Import");
b1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JFileChooser file = new JFileChooser();
file.setCurrentDirectory(new File(System.getProperty("user.home")));
//filter the files
FileNameExtensionFilter filter = new FileNameExtensionFilter("*.Images", "jpg","gif","png");
file.addChoosableFileFilter(filter);
int result = file.showSaveDialog(null);
if(result == JFileChooser.APPROVE_OPTION){
//NotWorking make check null not text
if (b2.getText().isEmpty()) {
File selectedFile = file.getSelectedFile();
String path = selectedFile.getAbsolutePath();
b2.setIcon(ResizeImage(path));
}
else {
File selectedFile = file.getSelectedFile();
String path = selectedFile.getAbsolutePath();
b33.setIcon(ResizeImage(path));
}
}
else if(result == JFileChooser.CANCEL_OPTION){
System.out.println("No File Select");
}
}
});
}
Aucun commentaire:
Enregistrer un commentaire