Open and Save buttons
in
Contributed Library Questions
•
1 year ago
Dear all, I am currently creating a GUI which involves a save and an open button which will call out the Opendialog box.
However, when running my code, the following is always encountered:
1) The opendialogbox will appear but do not always show its content in it and when this happen, it is hanged.
2) the opendialogbox with its content is shown, but when I cancel it, it hanged.
Basically, the GUI kept hanging!
I am starting to realise I need some update frame function? which I am clueless of where to inject them.
The code is as shown below:
import javax.swing.*;
import interfascia.*;
GUIController c;
IFButton b_o, b_s;
void setup()
{
size(900, 600);
smooth();
background(0); // R G B
frameRate(30);
c = new GUIController (this);
b_o = new IFButton ("Open", 40, 40, 40, 17);
b_s = new IFButton ("Save", 120, 40, 40, 17);
b_o.addActionListener(this);
b_s.addActionListener(this);
c.add (b_o);
c.add (b_s);
}
void draw()
{
}
void actionPerformed (GUIEvent e)
{
if (e.getSource() == b_o)
{
final JFileChooser fc = new JFileChooser();
int returnVal = fc.showOpenDialog(this);
if(returnVal == JFileChooser.APPROVE_OPTION)
{
File file = fc.getSelectedFile();
}
}
if(e.getSource() == b_s)
{
final JFileChooser fc = new JFileChooser();
fc.setSelectedFile(new File("fileToSave.txt"));
int returnVal = fc.showSaveDialog(this);
}
}
1