How can I make my program wait for the user to interact with my JFrame?2019 Community Moderator ElectionHow can I concatenate two arrays in Java?How can I create an executable JAR with dependencies using Maven?How do I make python to wait for a pressed keyHow can I convert a stack trace to a string?Access a class object from its inner classproblem in setting scrollpane for canvasOne JButton to call member functions based on user inputDrawing an image in JScrollPane within scaleWorking on a java based chatting application using threadingHaving trouble storing objects into an arraylist using ObjectInputStream
Fair way to split coins
Does the Shadow Magic sorcerer's Eyes of the Dark feature work on all Darkness spells or just his/her own?
Should a narrator ever describe things based on a characters view instead of fact?
Why is "la Gestapo" feminine?
Why doesn't the fusion process of the sun speed up?
When did hardware antialiasing start being available?
Does fire aspect on a sword, destroy mob drops?
The English Debate
Hackerrank All Women's Codesprint 2019: Name the Product
What are the rules for concealing thieves' tools (or items in general)?
What is the reasoning behind standardization (dividing by standard deviation)?
Determine voltage drop over 10G resistors with cheap multimeter
Should I be concerned about student access to a test bank?
UK Tourist Visa- Enquiry
How can an organ that provides biological immortality be unable to regenerate?
What (if any) is the reason to buy in small local stores?
Do people actually use the word "kaputt" in conversation?
Pre-Employment Background Check With Consent For Future Checks
Why does Surtur say that Thor is Asgard's doom?
How to balance a monster modification (zombie)?
Animating wave motion in water
Help with identifying unique aircraft over NE Pennsylvania
Error in master's thesis, I do not know what to do
Jem'Hadar, something strange about their life expectancy
How can I make my program wait for the user to interact with my JFrame?
2019 Community Moderator ElectionHow can I concatenate two arrays in Java?How can I create an executable JAR with dependencies using Maven?How do I make python to wait for a pressed keyHow can I convert a stack trace to a string?Access a class object from its inner classproblem in setting scrollpane for canvasOne JButton to call member functions based on user inputDrawing an image in JScrollPane within scaleWorking on a java based chatting application using threadingHaving trouble storing objects into an arraylist using ObjectInputStream
I am trying to write a file processing application but the program won't wait for the user to select a file before moving and finishing the function. I've tried to use wait() and notify() to make it stop but the program now freezes and buttons d and e never show up.
import javax.swing.*;
import java.awt.event.*;
import java.io.File;
public class pdfEditor
static JFrame inter = new JFrame("The Point Updater");
static JLabel reminder = new JLabel("Please select a function:");
static boolean i = false;
JButton a, b, c, d, e;
JFileChooser fc;
public static void main(String[] args)
//Sets the window
inter.setSize(750, 250);
inter.setLocation(100, 150);
inter.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
inter.setLayout(null);
//Label for commands for the user
reminder.setBounds(50, 50, 650, 30);
//add a button
JButton b = new JButton("Update Trainings");
b.setBounds(50, 150, 135, 30);
JButton c = new JButton("Update Employees");
c.setBounds(200, 150, 140, 30);
JButton a = new JButton("Export Points");
a.setBounds(355, 150, 135, 30);
//add them to the frame
inter.add(reminder);
inter.add(a);
inter.add(b);
inter.add(c);
inter.setVisible(true);
//Process selection
//TODO add catches for unformatted spreadsheets
a.addActionListener(new ActionListener() //If export Points button is selected
@Override
public void actionPerformed(ActionEvent arg0)
reminder.setText("Kashikomarimashita!");
exportPoints();
);
b.addActionListener(new ActionListener() //If update trainings is selected
@Override
public void actionPerformed(ActionEvent arg0)
reminder.setText("Make sure the type is Individual Completions and the columns are set to Training, Employee and Date.");
File file = null;
try
file = requestInputSpreadsheet();
catch (InterruptedException e)
// TODO Auto-generated catch block
e.printStackTrace();
updateTraining(file);
);
c.addActionListener(new ActionListener() //If update employees is selected
@Override
public void actionPerformed(ActionEvent arg0)
reminder.setText("Please import a employee list from iScout or Quickbase.");
File file = null;
try
file = requestInputSpreadsheet();
catch (InterruptedException e)
// TODO Auto-generated catch block
e.printStackTrace();
updateEmployees(file);
);
//Asks the user for a spreadsheet to be used in processing.
public static File requestInputSpreadsheet() throws InterruptedException
//makes file chooser
JFileChooser fc = new JFileChooser();
fc.addChoosableFileFilter(new SpreadsheetFilter());
fc.setAcceptAllFileFilterUsed(false);
//makes new buttons and label
JLabel name = new JLabel();
name.setBounds(180, 100, 270, 30);
JButton d = new JButton("Choose File...");
d.setBounds(50, 100, 135, 30);
JButton e = new JButton("Go!");
e.setBounds(450, 100, 50, 30);
inter.add(d);
SwingUtilities.updateComponentTreeUI(inter);
//switch for the file chooser if file was chosen successfully
i = false;
File file = null;
d.addActionListener(new ActionListener() //begins file choosing process
@Override
public void actionPerformed(ActionEvent arg0)
int returnVal = fc.showOpenDialog(inter);
if (returnVal == JFileChooser.APPROVE_OPTION)
//processes file and displays name
File file = fc.getSelectedFile();
name.setName(file.getName());
inter.add(name);
inter.add(e);
SwingUtilities.updateComponentTreeUI(inter);
);
e.addActionListener(new ActionListener() //returns the selected file
@Override
public void actionPerformed(ActionEvent arg0)
i = true;
synchronized (e)
e.notify();
);
synchronized(e)
e.wait();
//removes the button!
inter.remove(d);
inter.remove(e);
SwingUtilities.updateComponentTreeUI(inter);
if (i == true)
return file;
return null;
//Updates completed training list and awards points based on a spreadsheet exported from the database
public static boolean updateTraining(File file)
// still working on the processing
if (file == null)
return false;
else
System.out.println("Updated Training!!");
return true;
//Updates the employee list using an employee list exported from the database
public static boolean updateEmployees(File file)
if (file == null)
return false;
else
System.out.println("Updated Employees!!");
return true;
//Creates and exports a spreadsheet with employee names and current points
public static boolean exportPoints()
System.out.println("Exported Points!");
return true;
I included all of the code just in case.
java actionlistener wait notify
add a comment |
I am trying to write a file processing application but the program won't wait for the user to select a file before moving and finishing the function. I've tried to use wait() and notify() to make it stop but the program now freezes and buttons d and e never show up.
import javax.swing.*;
import java.awt.event.*;
import java.io.File;
public class pdfEditor
static JFrame inter = new JFrame("The Point Updater");
static JLabel reminder = new JLabel("Please select a function:");
static boolean i = false;
JButton a, b, c, d, e;
JFileChooser fc;
public static void main(String[] args)
//Sets the window
inter.setSize(750, 250);
inter.setLocation(100, 150);
inter.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
inter.setLayout(null);
//Label for commands for the user
reminder.setBounds(50, 50, 650, 30);
//add a button
JButton b = new JButton("Update Trainings");
b.setBounds(50, 150, 135, 30);
JButton c = new JButton("Update Employees");
c.setBounds(200, 150, 140, 30);
JButton a = new JButton("Export Points");
a.setBounds(355, 150, 135, 30);
//add them to the frame
inter.add(reminder);
inter.add(a);
inter.add(b);
inter.add(c);
inter.setVisible(true);
//Process selection
//TODO add catches for unformatted spreadsheets
a.addActionListener(new ActionListener() //If export Points button is selected
@Override
public void actionPerformed(ActionEvent arg0)
reminder.setText("Kashikomarimashita!");
exportPoints();
);
b.addActionListener(new ActionListener() //If update trainings is selected
@Override
public void actionPerformed(ActionEvent arg0)
reminder.setText("Make sure the type is Individual Completions and the columns are set to Training, Employee and Date.");
File file = null;
try
file = requestInputSpreadsheet();
catch (InterruptedException e)
// TODO Auto-generated catch block
e.printStackTrace();
updateTraining(file);
);
c.addActionListener(new ActionListener() //If update employees is selected
@Override
public void actionPerformed(ActionEvent arg0)
reminder.setText("Please import a employee list from iScout or Quickbase.");
File file = null;
try
file = requestInputSpreadsheet();
catch (InterruptedException e)
// TODO Auto-generated catch block
e.printStackTrace();
updateEmployees(file);
);
//Asks the user for a spreadsheet to be used in processing.
public static File requestInputSpreadsheet() throws InterruptedException
//makes file chooser
JFileChooser fc = new JFileChooser();
fc.addChoosableFileFilter(new SpreadsheetFilter());
fc.setAcceptAllFileFilterUsed(false);
//makes new buttons and label
JLabel name = new JLabel();
name.setBounds(180, 100, 270, 30);
JButton d = new JButton("Choose File...");
d.setBounds(50, 100, 135, 30);
JButton e = new JButton("Go!");
e.setBounds(450, 100, 50, 30);
inter.add(d);
SwingUtilities.updateComponentTreeUI(inter);
//switch for the file chooser if file was chosen successfully
i = false;
File file = null;
d.addActionListener(new ActionListener() //begins file choosing process
@Override
public void actionPerformed(ActionEvent arg0)
int returnVal = fc.showOpenDialog(inter);
if (returnVal == JFileChooser.APPROVE_OPTION)
//processes file and displays name
File file = fc.getSelectedFile();
name.setName(file.getName());
inter.add(name);
inter.add(e);
SwingUtilities.updateComponentTreeUI(inter);
);
e.addActionListener(new ActionListener() //returns the selected file
@Override
public void actionPerformed(ActionEvent arg0)
i = true;
synchronized (e)
e.notify();
);
synchronized(e)
e.wait();
//removes the button!
inter.remove(d);
inter.remove(e);
SwingUtilities.updateComponentTreeUI(inter);
if (i == true)
return file;
return null;
//Updates completed training list and awards points based on a spreadsheet exported from the database
public static boolean updateTraining(File file)
// still working on the processing
if (file == null)
return false;
else
System.out.println("Updated Training!!");
return true;
//Updates the employee list using an employee list exported from the database
public static boolean updateEmployees(File file)
if (file == null)
return false;
else
System.out.println("Updated Employees!!");
return true;
//Creates and exports a spreadsheet with employee names and current points
public static boolean exportPoints()
System.out.println("Exported Points!");
return true;
I included all of the code just in case.
java actionlistener wait notify
That's a lot of craziness going on there. First. Swing, like most GUI frameworks, is single threaded. All the "wait" and "notifies" are dangerous and could end up locking up your application (as they wait on and notify one the same thread).JFileChooser#showXxx
will create a modal dialog. This will block the execution flow until the dialog is closed, so you need to work that into your design. GUIs tend to be event driven (something happens, you respond to it) as apposed to procedural or linear, which you might be use to in a console environment
– MadProgrammer
Mar 6 at 23:20
In event-driven programs like GUIs, you never wait for things to happen. You set up your UI, and you attach event handlers (likeonClick
) to your elements; this code gets run when the user interacts with your UI.
– chrylis
Mar 6 at 23:21
Thank you for the help!
– Palmyra
Mar 7 at 17:24
add a comment |
I am trying to write a file processing application but the program won't wait for the user to select a file before moving and finishing the function. I've tried to use wait() and notify() to make it stop but the program now freezes and buttons d and e never show up.
import javax.swing.*;
import java.awt.event.*;
import java.io.File;
public class pdfEditor
static JFrame inter = new JFrame("The Point Updater");
static JLabel reminder = new JLabel("Please select a function:");
static boolean i = false;
JButton a, b, c, d, e;
JFileChooser fc;
public static void main(String[] args)
//Sets the window
inter.setSize(750, 250);
inter.setLocation(100, 150);
inter.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
inter.setLayout(null);
//Label for commands for the user
reminder.setBounds(50, 50, 650, 30);
//add a button
JButton b = new JButton("Update Trainings");
b.setBounds(50, 150, 135, 30);
JButton c = new JButton("Update Employees");
c.setBounds(200, 150, 140, 30);
JButton a = new JButton("Export Points");
a.setBounds(355, 150, 135, 30);
//add them to the frame
inter.add(reminder);
inter.add(a);
inter.add(b);
inter.add(c);
inter.setVisible(true);
//Process selection
//TODO add catches for unformatted spreadsheets
a.addActionListener(new ActionListener() //If export Points button is selected
@Override
public void actionPerformed(ActionEvent arg0)
reminder.setText("Kashikomarimashita!");
exportPoints();
);
b.addActionListener(new ActionListener() //If update trainings is selected
@Override
public void actionPerformed(ActionEvent arg0)
reminder.setText("Make sure the type is Individual Completions and the columns are set to Training, Employee and Date.");
File file = null;
try
file = requestInputSpreadsheet();
catch (InterruptedException e)
// TODO Auto-generated catch block
e.printStackTrace();
updateTraining(file);
);
c.addActionListener(new ActionListener() //If update employees is selected
@Override
public void actionPerformed(ActionEvent arg0)
reminder.setText("Please import a employee list from iScout or Quickbase.");
File file = null;
try
file = requestInputSpreadsheet();
catch (InterruptedException e)
// TODO Auto-generated catch block
e.printStackTrace();
updateEmployees(file);
);
//Asks the user for a spreadsheet to be used in processing.
public static File requestInputSpreadsheet() throws InterruptedException
//makes file chooser
JFileChooser fc = new JFileChooser();
fc.addChoosableFileFilter(new SpreadsheetFilter());
fc.setAcceptAllFileFilterUsed(false);
//makes new buttons and label
JLabel name = new JLabel();
name.setBounds(180, 100, 270, 30);
JButton d = new JButton("Choose File...");
d.setBounds(50, 100, 135, 30);
JButton e = new JButton("Go!");
e.setBounds(450, 100, 50, 30);
inter.add(d);
SwingUtilities.updateComponentTreeUI(inter);
//switch for the file chooser if file was chosen successfully
i = false;
File file = null;
d.addActionListener(new ActionListener() //begins file choosing process
@Override
public void actionPerformed(ActionEvent arg0)
int returnVal = fc.showOpenDialog(inter);
if (returnVal == JFileChooser.APPROVE_OPTION)
//processes file and displays name
File file = fc.getSelectedFile();
name.setName(file.getName());
inter.add(name);
inter.add(e);
SwingUtilities.updateComponentTreeUI(inter);
);
e.addActionListener(new ActionListener() //returns the selected file
@Override
public void actionPerformed(ActionEvent arg0)
i = true;
synchronized (e)
e.notify();
);
synchronized(e)
e.wait();
//removes the button!
inter.remove(d);
inter.remove(e);
SwingUtilities.updateComponentTreeUI(inter);
if (i == true)
return file;
return null;
//Updates completed training list and awards points based on a spreadsheet exported from the database
public static boolean updateTraining(File file)
// still working on the processing
if (file == null)
return false;
else
System.out.println("Updated Training!!");
return true;
//Updates the employee list using an employee list exported from the database
public static boolean updateEmployees(File file)
if (file == null)
return false;
else
System.out.println("Updated Employees!!");
return true;
//Creates and exports a spreadsheet with employee names and current points
public static boolean exportPoints()
System.out.println("Exported Points!");
return true;
I included all of the code just in case.
java actionlistener wait notify
I am trying to write a file processing application but the program won't wait for the user to select a file before moving and finishing the function. I've tried to use wait() and notify() to make it stop but the program now freezes and buttons d and e never show up.
import javax.swing.*;
import java.awt.event.*;
import java.io.File;
public class pdfEditor
static JFrame inter = new JFrame("The Point Updater");
static JLabel reminder = new JLabel("Please select a function:");
static boolean i = false;
JButton a, b, c, d, e;
JFileChooser fc;
public static void main(String[] args)
//Sets the window
inter.setSize(750, 250);
inter.setLocation(100, 150);
inter.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
inter.setLayout(null);
//Label for commands for the user
reminder.setBounds(50, 50, 650, 30);
//add a button
JButton b = new JButton("Update Trainings");
b.setBounds(50, 150, 135, 30);
JButton c = new JButton("Update Employees");
c.setBounds(200, 150, 140, 30);
JButton a = new JButton("Export Points");
a.setBounds(355, 150, 135, 30);
//add them to the frame
inter.add(reminder);
inter.add(a);
inter.add(b);
inter.add(c);
inter.setVisible(true);
//Process selection
//TODO add catches for unformatted spreadsheets
a.addActionListener(new ActionListener() //If export Points button is selected
@Override
public void actionPerformed(ActionEvent arg0)
reminder.setText("Kashikomarimashita!");
exportPoints();
);
b.addActionListener(new ActionListener() //If update trainings is selected
@Override
public void actionPerformed(ActionEvent arg0)
reminder.setText("Make sure the type is Individual Completions and the columns are set to Training, Employee and Date.");
File file = null;
try
file = requestInputSpreadsheet();
catch (InterruptedException e)
// TODO Auto-generated catch block
e.printStackTrace();
updateTraining(file);
);
c.addActionListener(new ActionListener() //If update employees is selected
@Override
public void actionPerformed(ActionEvent arg0)
reminder.setText("Please import a employee list from iScout or Quickbase.");
File file = null;
try
file = requestInputSpreadsheet();
catch (InterruptedException e)
// TODO Auto-generated catch block
e.printStackTrace();
updateEmployees(file);
);
//Asks the user for a spreadsheet to be used in processing.
public static File requestInputSpreadsheet() throws InterruptedException
//makes file chooser
JFileChooser fc = new JFileChooser();
fc.addChoosableFileFilter(new SpreadsheetFilter());
fc.setAcceptAllFileFilterUsed(false);
//makes new buttons and label
JLabel name = new JLabel();
name.setBounds(180, 100, 270, 30);
JButton d = new JButton("Choose File...");
d.setBounds(50, 100, 135, 30);
JButton e = new JButton("Go!");
e.setBounds(450, 100, 50, 30);
inter.add(d);
SwingUtilities.updateComponentTreeUI(inter);
//switch for the file chooser if file was chosen successfully
i = false;
File file = null;
d.addActionListener(new ActionListener() //begins file choosing process
@Override
public void actionPerformed(ActionEvent arg0)
int returnVal = fc.showOpenDialog(inter);
if (returnVal == JFileChooser.APPROVE_OPTION)
//processes file and displays name
File file = fc.getSelectedFile();
name.setName(file.getName());
inter.add(name);
inter.add(e);
SwingUtilities.updateComponentTreeUI(inter);
);
e.addActionListener(new ActionListener() //returns the selected file
@Override
public void actionPerformed(ActionEvent arg0)
i = true;
synchronized (e)
e.notify();
);
synchronized(e)
e.wait();
//removes the button!
inter.remove(d);
inter.remove(e);
SwingUtilities.updateComponentTreeUI(inter);
if (i == true)
return file;
return null;
//Updates completed training list and awards points based on a spreadsheet exported from the database
public static boolean updateTraining(File file)
// still working on the processing
if (file == null)
return false;
else
System.out.println("Updated Training!!");
return true;
//Updates the employee list using an employee list exported from the database
public static boolean updateEmployees(File file)
if (file == null)
return false;
else
System.out.println("Updated Employees!!");
return true;
//Creates and exports a spreadsheet with employee names and current points
public static boolean exportPoints()
System.out.println("Exported Points!");
return true;
I included all of the code just in case.
java actionlistener wait notify
java actionlistener wait notify
asked Mar 6 at 23:12
PalmyraPalmyra
1
1
That's a lot of craziness going on there. First. Swing, like most GUI frameworks, is single threaded. All the "wait" and "notifies" are dangerous and could end up locking up your application (as they wait on and notify one the same thread).JFileChooser#showXxx
will create a modal dialog. This will block the execution flow until the dialog is closed, so you need to work that into your design. GUIs tend to be event driven (something happens, you respond to it) as apposed to procedural or linear, which you might be use to in a console environment
– MadProgrammer
Mar 6 at 23:20
In event-driven programs like GUIs, you never wait for things to happen. You set up your UI, and you attach event handlers (likeonClick
) to your elements; this code gets run when the user interacts with your UI.
– chrylis
Mar 6 at 23:21
Thank you for the help!
– Palmyra
Mar 7 at 17:24
add a comment |
That's a lot of craziness going on there. First. Swing, like most GUI frameworks, is single threaded. All the "wait" and "notifies" are dangerous and could end up locking up your application (as they wait on and notify one the same thread).JFileChooser#showXxx
will create a modal dialog. This will block the execution flow until the dialog is closed, so you need to work that into your design. GUIs tend to be event driven (something happens, you respond to it) as apposed to procedural or linear, which you might be use to in a console environment
– MadProgrammer
Mar 6 at 23:20
In event-driven programs like GUIs, you never wait for things to happen. You set up your UI, and you attach event handlers (likeonClick
) to your elements; this code gets run when the user interacts with your UI.
– chrylis
Mar 6 at 23:21
Thank you for the help!
– Palmyra
Mar 7 at 17:24
That's a lot of craziness going on there. First. Swing, like most GUI frameworks, is single threaded. All the "wait" and "notifies" are dangerous and could end up locking up your application (as they wait on and notify one the same thread).
JFileChooser#showXxx
will create a modal dialog. This will block the execution flow until the dialog is closed, so you need to work that into your design. GUIs tend to be event driven (something happens, you respond to it) as apposed to procedural or linear, which you might be use to in a console environment– MadProgrammer
Mar 6 at 23:20
That's a lot of craziness going on there. First. Swing, like most GUI frameworks, is single threaded. All the "wait" and "notifies" are dangerous and could end up locking up your application (as they wait on and notify one the same thread).
JFileChooser#showXxx
will create a modal dialog. This will block the execution flow until the dialog is closed, so you need to work that into your design. GUIs tend to be event driven (something happens, you respond to it) as apposed to procedural or linear, which you might be use to in a console environment– MadProgrammer
Mar 6 at 23:20
In event-driven programs like GUIs, you never wait for things to happen. You set up your UI, and you attach event handlers (like
onClick
) to your elements; this code gets run when the user interacts with your UI.– chrylis
Mar 6 at 23:21
In event-driven programs like GUIs, you never wait for things to happen. You set up your UI, and you attach event handlers (like
onClick
) to your elements; this code gets run when the user interacts with your UI.– chrylis
Mar 6 at 23:21
Thank you for the help!
– Palmyra
Mar 7 at 17:24
Thank you for the help!
– Palmyra
Mar 7 at 17:24
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55033660%2fhow-can-i-make-my-program-wait-for-the-user-to-interact-with-my-jframe%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55033660%2fhow-can-i-make-my-program-wait-for-the-user-to-interact-with-my-jframe%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
That's a lot of craziness going on there. First. Swing, like most GUI frameworks, is single threaded. All the "wait" and "notifies" are dangerous and could end up locking up your application (as they wait on and notify one the same thread).
JFileChooser#showXxx
will create a modal dialog. This will block the execution flow until the dialog is closed, so you need to work that into your design. GUIs tend to be event driven (something happens, you respond to it) as apposed to procedural or linear, which you might be use to in a console environment– MadProgrammer
Mar 6 at 23:20
In event-driven programs like GUIs, you never wait for things to happen. You set up your UI, and you attach event handlers (like
onClick
) to your elements; this code gets run when the user interacts with your UI.– chrylis
Mar 6 at 23:21
Thank you for the help!
– Palmyra
Mar 7 at 17:24