event-dispatch-thread

Calling JFileChooser twice in invokelater causes program not to exit

情到浓时终转凉″ 提交于 2020-01-06 19:34:30
问题 I am writing a program to collect information from two text files to add to tables in a database. In order to permit the user to select his own files I created a non-static method called chooseFile() that uses JFileChooser class to present a showOpenDialog (I've also tried it as a static method with the same results. If this sounds like I'm guessing, you're correct - I'm only so-so with programming). My understanding is that calls to Swing classes in main() should be done using invokelater .

Calling JFileChooser twice in invokelater causes program not to exit

你离开我真会死。 提交于 2020-01-06 19:34:02
问题 I am writing a program to collect information from two text files to add to tables in a database. In order to permit the user to select his own files I created a non-static method called chooseFile() that uses JFileChooser class to present a showOpenDialog (I've also tried it as a static method with the same results. If this sounds like I'm guessing, you're correct - I'm only so-so with programming). My understanding is that calls to Swing classes in main() should be done using invokelater .

Open card after certain time

北城余情 提交于 2020-01-06 17:55:21
问题 i'm programming a blackjack (single thread) for a university project and the dealer is the computer (e.g. no player action)... Does someone know how can I program in Java something like this: while (dealerpoints < 17) open card and repaint frame wait 1 sec (to run again the condition test for while) THe thing is, I don't want all dealer cards painted at once... Thanks in advance, Gabriel Sotero UPDATE: this is my code (that doesn't work) while (Dealer.getInstance().dealerPoints < 17){ Dealer

Updating the GUI in real time from SwingWorker

血红的双手。 提交于 2020-01-06 15:13:34
问题 Ok, this is a follow-up question to my question from yesterday, "Error handling in SwingWorker." In consideration of the fact that it might be ok to call SwingUtilities#invokeAndWait() inside of SwingWorker#doInBackground() , I want to push it a step further and ask: might it also be ok to call SwingUtilities#invokeLater() inside the background thread? Another SSCCE to illustrate: public class NewClass extends javax.swing.JFrame { public NewClass() { jScrollPane1 = new javax.swing.JScrollPane

Forcing a GUI update inside of a thread - JSlider updates

廉价感情. 提交于 2020-01-06 13:31:32
问题 I'm trying to simulate betting results on a "horse race" by setting JSlider positions within a loop utilizing random numbers. My problem is that, of course, I can't get the GUI to update while the thread is executing, whereby my JSliders do not seem to be racing, they are going from start to finish. I've tried playing around with the code and separating them out into different methods, but I can't get around the single threaded swing issue. Is there a way to force an update or stop the thread

Forcing a GUI update inside of a thread - JSlider updates

家住魔仙堡 提交于 2020-01-06 13:31:29
问题 I'm trying to simulate betting results on a "horse race" by setting JSlider positions within a loop utilizing random numbers. My problem is that, of course, I can't get the GUI to update while the thread is executing, whereby my JSliders do not seem to be racing, they are going from start to finish. I've tried playing around with the code and separating them out into different methods, but I can't get around the single threaded swing issue. Is there a way to force an update or stop the thread

Forcing a GUI update inside of a thread - JSlider updates

筅森魡賤 提交于 2020-01-06 13:31:19
问题 I'm trying to simulate betting results on a "horse race" by setting JSlider positions within a loop utilizing random numbers. My problem is that, of course, I can't get the GUI to update while the thread is executing, whereby my JSliders do not seem to be racing, they are going from start to finish. I've tried playing around with the code and separating them out into different methods, but I can't get around the single threaded swing issue. Is there a way to force an update or stop the thread

Updating Swing GUI with while loop and delay

百般思念 提交于 2020-01-06 05:48:05
问题 I have a while loop that is supposed to update the program data and the GUI, but the GUI part freezes until the while loop is done executing. Here is my code: while(game.getCompTotal() < 17) { try { Thread.sleep(2500); } catch (Exception ex){ ex.printStackTrace(); } game.compHit(); // Program data update updateCardPanels(); // GUI update -- Does not update until the while loop finishes. if(game.checkCompBust()){ if(JOptionPane.showConfirmDialog(this, "Dealer Busted. Play again?") ==

How to run method with JProgressBar

可紊 提交于 2020-01-06 04:45:30
问题 I have a function called CreateAccount . I need it to run and also need to show a progress bar. When I click the button, the method will start. And I need to start showing loading progress bar. Once method is done progress bar also should stop at 100. If the method gets more time to do the job, progress bar also needs to load slowly. I tried using following code but it is not synchronizing progress bar with the method. So how can I do that? Here is my code: private static int t = 0; private

Java JButton actionPerformed freezing

孤人 提交于 2020-01-05 10:11:34
问题 I've been fooling around with Java and I was trying to make a program that starts to ping an address and printing out the "ms". I have a JButton: JButton start = new JButton("START"); start.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ try { doCommand(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } }); And the doCommand() method looks like this: public static void doCommand() throws IOException{ String s = null;