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
Smooth vector fields on a surface modulo diffeomorphisms
Is it a Cyclops number? "Nobody" knows!
Finding the minimum value of a function without using Calculus
Is there a logarithm base for which the logarithm becomes an identity function?
Would those living in a "perfect society" not understand satire
Why do we say 'Pairwise Disjoint', rather than 'Disjoint'?
Should we avoid writing fiction about historical events without extensive research?
Rationale to prefer local variables over instance variables?
The (Easy) Road to Code
Strange opamp's output impedance in spice
Use Mercury as quenching liquid for swords?
Translation of 答えを知っている人はいませんでした
Idiom for feeling after taking risk and someone else being rewarded
Has a sovereign Communist government ever run, and conceded loss, on a fair election?
How can I portion out frozen cookie dough?
Sampling from Gaussian mixture models, when are the sampled data independent?
Help! My Character is too much for her story!
Is this Paypal Github SDK reference really a dangerous site?
Is divide-by-zero a security vulnerability?
Why is there an extra space when I type "ls" on the Desktop?
Can one live in the U.S. and not use a credit card?
If nine coins are tossed, what is the probability that the number of heads is even?
Graphic representation of a triangle using ArrayPlot
What will happen if my luggage gets delayed?
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
New contributor
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
New contributor
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
2 days ago
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
New contributor
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
New contributor
New contributor
New contributor
asked Mar 6 at 23:12
PalmyraPalmyra
1
1
New contributor
New contributor
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
2 days ago
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
2 days ago
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
2 days ago
Thank you for the help!
– Palmyra
2 days ago
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
);
);
Palmyra is a new contributor. Be nice, and check out our Code of Conduct.
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
Palmyra is a new contributor. Be nice, and check out our Code of Conduct.
Palmyra is a new contributor. Be nice, and check out our Code of Conduct.
Palmyra is a new contributor. Be nice, and check out our Code of Conduct.
Palmyra is a new contributor. Be nice, and check out our Code of Conduct.
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
2 days ago