Advertisement
Guest User

Untitled

a guest
Dec 23rd, 2016
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.12 KB | None | 0 0
  1. updateMYSQL callDatabaseUpdate = new updateMYSQL(firstName , surname);
  2. callDatabaseUpdate.viewTable(firstName,surname);
  3.  
  4. import java.awt.event.*;
  5. import javax.swing.*;
  6. import javax.swing.JOptionPane;
  7. import javax.swing.JFrame;
  8. import java.sql.*;
  9. import javax.swing.JPanel;
  10. import javax.swing.ImageIcon;
  11. import java.io.File;
  12.  
  13. public class FrontScreen implements ActionListener
  14. {
  15. private static JRadioButton rb1, rb2, rb3;
  16. private static JFrame f = new JFrame("Welcome to Ballon d'or , created by Darren Estcourt");
  17. private static JButton b;
  18. private static JPanel myFirstPanel;
  19.  
  20.  
  21.  
  22.  
  23. public FrontScreen()
  24. {
  25. }
  26.  
  27. public void CreateAndShowFrontScreen()
  28. {
  29.  
  30. rb1 = new JRadioButton("Start New Game");
  31. rb2 = new JRadioButton("Load Game");
  32. rb3 = new JRadioButton("Quit");
  33.  
  34. f.setExtendedState(JFrame.MAXIMIZED_BOTH);
  35. f.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
  36.  
  37. myFirstPanel = new JPanel();
  38. f.add(myFirstPanel);
  39. b = new JButton("OK");
  40.  
  41. myFirstPanel.add(rb1);
  42. myFirstPanel.add(rb2);
  43. myFirstPanel.add(rb3);
  44.  
  45. ButtonGroup bg=new ButtonGroup();
  46. bg.add(rb1);
  47. bg.add(rb2);
  48. bg.add(rb3);
  49.  
  50.  
  51. myFirstPanel.add(b);
  52.  
  53. b.addActionListener(this);
  54.  
  55. f.addWindowListener(new WindowAdapter()
  56. {
  57.  
  58. @Override public void windowClosing(WindowEvent e)
  59. {
  60. if(JOptionPane.showConfirmDialog(f, "Are you sure ?") == JOptionPane.YES_NO_OPTION)
  61. {
  62. f.setVisible(false);
  63. f.dispose();
  64. }
  65. }
  66. });
  67. }
  68. @Override public void actionPerformed(ActionEvent e)
  69. {
  70. if(rb1.isSelected())
  71. {
  72. f.dispose();
  73. ManagerName startNewGame = new ManagerName();
  74. startNewGame.getFrame().setVisible(true);
  75. }
  76.  
  77. if(rb2.isSelected())
  78. {
  79. JOptionPane.showMessageDialog(null,"Plesae select a saved game" , "Load game" , JOptionPane.QUESTION_MESSAGE);
  80. }
  81.  
  82. if(rb3.isSelected())
  83. {
  84. System.exit(0);
  85. }
  86. }
  87.  
  88.  
  89.  
  90.  
  91.  
  92. public static void main(String[] args)
  93. {
  94. String dirname = "/home/cabox/workspace/savedgames";
  95. String dirname2 = "/home/cabox/workspace/drivers";
  96. File d = new File(dirname);
  97. File d2 = new File(dirname2);
  98. // Create directory now.
  99. d.mkdirs();
  100. d2.mkdirs();
  101. SwingUtilities.invokeLater(new Runnable()
  102. {
  103. public void run()
  104. {
  105. FrontScreen test = new FrontScreen();
  106. test.CreateAndShowFrontScreen();
  107.  
  108. }
  109. });
  110. ManagerName test = new ManagerName();
  111. test.getManagerFirstName();
  112. ManagerName test2 = new ManagerName();
  113. test.getManagerSurName();
  114. updateMYSQL callDatabaseUpdate = new updateMYSQL(firstName , surname);
  115. callDatabaseUpdate.viewTable(firstName,surname);
  116. f.pack();
  117. f.setVisible(true);
  118. } // end main
  119.  
  120.  
  121.  
  122. }
  123.  
  124. import java.awt.event.*;
  125. import javax.swing.*;
  126. import javax.swing.JOptionPane;
  127. import javax.swing.JFrame;
  128. import java.sql.*;
  129. import javax.swing.JPanel;
  130. import javax.swing.ImageIcon;
  131.  
  132. public class updateMYSQL
  133. {
  134.  
  135.  
  136. public updateMYSQL(ManagerName firstName , ManagerName surname)
  137. {
  138.  
  139. String myDriver = "org.gjt.mm.mysql.Driver";
  140. String myUrl = "jdbc:mysql://localhost:3306/ballondor?autoReconnect=true&useSSL=false";
  141.  
  142. Connection conn = DriverManager.getConnection(myUrl, "root", "Lucia290907");
  143. String query = "SELECT * FROM clubInfo";
  144.  
  145. try(Statement st = conn.createStatement())
  146. {
  147. Class.forName(myDriver).newInstance();
  148.  
  149. ResultSet rs = st.executeQuery(query);
  150. st.executeQuery("insert into name (first,last) values('"+firstName+"' , '"+surname+"')"); // UPDATING MYSQL DATABASE
  151. while (rs.next())
  152. {
  153. int TeamID = rs.getInt("TeamID");
  154. String TeamName = rs.getString("TeamName");
  155. // print the results
  156. JOptionPane.showMessageDialog(null,"List of team names" ,TeamName, JOptionPane.QUESTION_MESSAGE);
  157. System.out.format("%s, n", TeamName);
  158. } // end while loop
  159.  
  160. st.close();
  161. } // end try
  162.  
  163. catch (Exception e)
  164. {
  165. System.err.println("Got an exception! ");
  166. System.err.println(e.getMessage());
  167. }
  168.  
  169.  
  170. }
  171.  
  172. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement