I am very new to Java. I am supposed to have a frame which has two buttons. The first button makes the user browse an image and it works. Second button should ask parameter with dialogbox but it doesn't even appear on the frame.
edit: I have solved the problem in a stupid way but thanks anyway. I added setVisible(true) for button2 and somehow it worked. The weird thing is I didn't do the same thing for button but still it's working. I didn't get it but if it works it works.Thanks again, hope someone else could get a solution from your answers.
public class ImageBrowser extends JFrame {
private static final long serialVersionUID = 1L;
JButton button, button2;
JLabel label;
private int K;
private int IFP;
public ImageBrowser() {
super("Image Browser");
button = new JButton("Browse");
button.setBounds(200, 300, 90, 40);
label = new JLabel();
label.setBounds(10, 10, 256, 256);
button2 = new JButton("Parameters");
button2.setBounds(500, 300, 150, 40);
add(button);
add(label);
add(button2);
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// textArea.setText("");
JFileChooser file = new JFileChooser();
file.setCurrentDirectory(new File(System
.getProperty("user.home")));
// filter the files
FileNameExtensionFilter filter = new FileNameExtensionFilter(
"*.Images", "jpg", "gif", "png", "tif");
file.addChoosableFileFilter(filter);
int result = file.showOpenDialog(null);
if (result == JFileChooser.APPROVE_OPTION) {
File selectedFile = file.getSelectedFile();
String path = selectedFile.getAbsolutePath();
label.setIcon(ResizeImage(path));
getPixels(selectedFile);
}
else if (result == JFileChooser.CANCEL_OPTION) {
System.out.println("No File Select");
}
}
});
button2.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String input = JOptionPane
.showInputDialog("Please input Parameter k");
if (input == null)
return;
int K = Integer.parseInt(input.trim());
input = JOptionPane
.showInputDialog("Please input Parameter ifp");
if (input == null)
return;
int IFK = Integer.parseInt(input.trim());
}
});
setLayout(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocation(100, 100);
setSize(700, 400);
setVisible(true);
}
public static void main(String[] args) throws IOException {
new ImageBrowser();
}
}