Guest User

Untitled

a guest
Aug 4th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. JTextField not correctly updating
  2. connectButton.addActionListener(new ActionListener() {
  3. public void actionPerformed(ActionEvent e) {
  4. statusBar.setText("Connecting...");
  5. }
  6. }
  7. });
  8.  
  9. connectButton.addActionListener(new ActionListener() {
  10. public void actionPerformed(ActionEvent e) {
  11. Class.forName("com.mysql.jdbc.Driver");
  12. statusBar.setText("Connecting...");
  13. connection = DriverManager.getConnection("jdbc:mysql://" + database);
  14. }
  15. }
  16. });
  17.  
  18. connectButton.addActionListener(new ActionListener() {
  19. public void actionPerformed(ActionEvent e) {
  20. statusBar.setText("Connecting...");
  21.  
  22. new SwingWorker<Void, Void>() {
  23. protected Void doInBackground() {
  24. // Called on a background thread.
  25. connectToDatabase();
  26. return null;
  27. }
  28.  
  29. protected void done() {
  30. // Called on Event Dispatch thread once connect routine has completed.
  31. try {
  32. get(); // Propagate any exceptions back to Event Dispatch thread.
  33. } catch (Exception ex) {
  34. ex.printStackTrace();
  35. JOptionPane.showMessageDialog(null,
  36. "Failed to connect: " + ex.getMessage(),
  37. "Error",
  38. JOptionPane.ERROR_MESSAGE);
  39. }
  40. }
  41. }.execute();
  42. }
  43. });
Add Comment
Please, Sign In to add comment