Advertisement
Guest User

Untitled

a guest
Jul 13th, 2014
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.86 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6.  
  7. package GUI;
  8.  
  9. import BE.Video;
  10. import BLL.videoManager;
  11. import com.sun.corba.se.impl.presentation.rmi.ExceptionHandler;
  12. //import gui.model.VideoTableModel;
  13. import java.io.File;
  14. import java.io.IOException;
  15. import java.sql.Connection;
  16. import java.sql.DriverManager;
  17. import java.sql.ResultSet;
  18. import java.sql.SQLException;
  19. import java.sql.Statement;
  20. import java.util.Observable;
  21. import java.util.Observer;
  22. import java.util.ResourceBundle;
  23. import java.util.logging.Level;
  24. import java.util.logging.Logger;
  25. import javax.swing.DefaultComboBoxModel;
  26. import javax.swing.JFileChooser;
  27. import javax.swing.JOptionPane;
  28. import javax.swing.ListSelectionModel;
  29. import javax.swing.UIManager;
  30. import javax.swing.event.ListSelectionEvent;
  31. import javax.swing.event.ListSelectionListener;
  32. //import GUI.Models.VideoTableModel;
  33.  
  34. /**
  35. *
  36. * @author Hjemme-PC
  37. */
  38. public class Create extends javax.swing.JFrame {
  39.  
  40. // private VideoTableModel modelVideo = null;
  41. private static Create instance = null;
  42. // private VideoTableModel modelVideo = null;
  43. static videoManager managerVideo = null;
  44. videoManager vmgr;
  45.  
  46. public static Create getInstance() throws SQLException
  47. {
  48. if (instance == null)
  49. {
  50. instance = new Create();
  51. }
  52. return instance;
  53.  
  54. }
  55.  
  56. public Create() {
  57. try {
  58. initComponents();
  59. vmgr = videoManager.getInstance();
  60. initComponents();
  61. } catch (IOException ex) {
  62. Logger.getLogger(Create.class.getName()).log(Level.SEVERE, null, ex);
  63. } catch (SQLException ex) {
  64. Logger.getLogger(Create.class.getName()).log(Level.SEVERE, null, ex);
  65. }
  66. }
  67.  
  68. public void addPressed()
  69. {
  70. if (txtName.getText().length() != 0 && txtVideoLocation.getText().length() != 0)
  71. {
  72. String videoName = txtName.getText().trim();
  73. String videoLocation = txtVideoLocation.getText().trim();
  74.  
  75. Video video = new Video(videoName, videoLocation);
  76. try
  77. {
  78. vmgr.add(video);
  79. closePressed();
  80. }
  81. catch (Exception ex)
  82. {
  83. throw;
  84. }
  85. }
  86. else
  87. {
  88. String message = "Det er opstået en ukendt fejl.";
  89. int reply = JOptionPane.showConfirmDialog(this, message, getTitle(), JOptionPane.CLOSED_OPTION);
  90. }
  91. //disable();
  92. clearFields();
  93. // String message = "Video is uploaded to your mobile server.";
  94. // JOptionPane.showMessageDialog(this, message, getTitle(), JOptionPane.ERROR_MESSAGE);
  95. }
  96.  
  97. private void closePressed()
  98. {
  99. String message = "Ny video er tilføjet. Vil du tilføje flere videoer?";
  100. int reply = JOptionPane.showConfirmDialog(this, message, getTitle(), JOptionPane.YES_NO_OPTION);
  101. if (reply == JOptionPane.NO_OPTION)
  102. {
  103. System.exit(0);
  104. }
  105. }
  106.  
  107. public String requiredFields()
  108. {
  109. String errorMessage = "";
  110. if (txtName == null || txtName.getText().trim().isEmpty())
  111. {
  112. errorMessage += "Titel Name is missing\n";
  113. }
  114. if (txtVideoLocation == null || txtVideoLocation.getText().trim().isEmpty())
  115. {
  116. errorMessage += "Video Location is missing\n";
  117. }
  118. return errorMessage;
  119. }
  120.  
  121.  
  122. private void clearFields() {
  123. txtName.setText("");
  124. txtVideoLocation.setText("");
  125. }
  126.  
  127.  
  128. // private void videoListSelectioner() throws IOException, SQLException
  129. // {
  130. // try
  131. // {
  132. // managerVideo.addObserver((Observer) this);
  133. // modelVideo = new VideoTableModel(managerVideo.getAllVideos());
  134. // jTable1.setModel(modelVideo);
  135. // }
  136. // catch (Exception ex)
  137. // {
  138. // }
  139. // }
  140. @SuppressWarnings("unchecked")
  141. // <editor-fold defaultstate="collapsed" desc="Generated Code">
  142. private void initComponents() {
  143.  
  144. jLabel1 = new javax.swing.JLabel();
  145. txtName = new javax.swing.JTextField();
  146. jLabel2 = new javax.swing.JLabel();
  147. txtVideoLocation = new javax.swing.JTextField();
  148. jButton3 = new javax.swing.JButton();
  149. jButton1 = new javax.swing.JButton();
  150. jButton2 = new javax.swing.JButton();
  151. jScrollPane1 = new javax.swing.JScrollPane();
  152. jTable1 = new javax.swing.JTable();
  153.  
  154. setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  155.  
  156. jLabel1.setText("Titel:");
  157.  
  158. jLabel2.setText("Sti:");
  159.  
  160. jButton3.setText("...");
  161. jButton3.addActionListener(new java.awt.event.ActionListener() {
  162. public void actionPerformed(java.awt.event.ActionEvent evt) {
  163. jButton3ActionPerformed(evt);
  164. }
  165. });
  166.  
  167. jButton1.setText("Opret");
  168. jButton1.addActionListener(new java.awt.event.ActionListener() {
  169. public void actionPerformed(java.awt.event.ActionEvent evt) {
  170. jButton1ActionPerformed(evt);
  171. }
  172. });
  173.  
  174. jButton2.setText("Annuller");
  175. jButton2.addActionListener(new java.awt.event.ActionListener() {
  176. public void actionPerformed(java.awt.event.ActionEvent evt) {
  177. jButton2ActionPerformed(evt);
  178. }
  179. });
  180.  
  181. jTable1.setModel(new javax.swing.table.DefaultTableModel(
  182. new Object [][] {
  183. {null, null, null, null},
  184. {null, null, null, null},
  185. {null, null, null, null},
  186. {null, null, null, null}
  187. },
  188. new String [] {
  189. "Title 1", "Title 2", "Title 3", "Title 4"
  190. }
  191. ));
  192. jScrollPane1.setViewportView(jTable1);
  193.  
  194. javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  195. getContentPane().setLayout(layout);
  196. layout.setHorizontalGroup(
  197. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  198. .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
  199. .addContainerGap(15, Short.MAX_VALUE)
  200. .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 418, javax.swing.GroupLayout.PREFERRED_SIZE)
  201. .addContainerGap())
  202. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  203. .addGroup(layout.createSequentialGroup()
  204. .addContainerGap()
  205. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
  206. .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
  207. .addComponent(jLabel1)
  208. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  209. .addComponent(txtName))
  210. .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
  211. .addGap(8, 8, 8)
  212. .addComponent(jLabel2)
  213. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  214. .addComponent(txtVideoLocation)
  215. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  216. .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))
  217. .addGroup(layout.createSequentialGroup()
  218. .addGap(283, 283, 283)
  219. .addComponent(jButton1)
  220. .addGap(8, 8, 8)
  221. .addComponent(jButton2)))
  222. .addContainerGap()))
  223. );
  224. layout.setVerticalGroup(
  225. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  226. .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
  227. .addContainerGap(228, Short.MAX_VALUE)
  228. .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 197, javax.swing.GroupLayout.PREFERRED_SIZE)
  229. .addContainerGap())
  230. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  231. .addGroup(layout.createSequentialGroup()
  232. .addGap(90, 90, 90)
  233. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  234. .addComponent(jLabel1)
  235. .addComponent(txtName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  236. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  237. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  238. .addComponent(jLabel2)
  239. .addComponent(txtVideoLocation, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  240. .addComponent(jButton3))
  241. .addGap(43, 43, 43)
  242. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  243. .addComponent(jButton1)
  244. .addComponent(jButton2))
  245. .addContainerGap(226, Short.MAX_VALUE)))
  246. );
  247.  
  248. pack();
  249. }// </editor-fold>
  250.  
  251. private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
  252. JFileChooser chooser = new JFileChooser();
  253. chooser.showOpenDialog(null);
  254. File f = chooser.getSelectedFile();
  255. String videoname = f.getAbsolutePath();
  256. txtVideoLocation.setText((videoname));
  257. }
  258.  
  259. private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
  260. addPressed();
  261. }
  262.  
  263. private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
  264. System.exit(0);
  265. }
  266.  
  267. /**
  268. * @param args the command line arguments
  269. */
  270. public static void main(String args[]) {
  271. /* Set the Nimbus look and feel */
  272. //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  273. /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
  274. * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  275. */
  276. try {
  277. for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  278. if ("Nimbus".equals(info.getName())) {
  279. javax.swing.UIManager.setLookAndFeel(info.getClassName());
  280. break;
  281. }
  282. }
  283. } catch (ClassNotFoundException ex) {
  284. java.util.logging.Logger.getLogger(Create.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  285. } catch (InstantiationException ex) {
  286. java.util.logging.Logger.getLogger(Create.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  287. } catch (IllegalAccessException ex) {
  288. java.util.logging.Logger.getLogger(Create.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  289. } catch (javax.swing.UnsupportedLookAndFeelException ex) {
  290. java.util.logging.Logger.getLogger(Create.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  291. }
  292. //</editor-fold>
  293.  
  294. /* Create and display the form */
  295. java.awt.EventQueue.invokeLater(new Runnable() {
  296. public void run() {
  297. new Create().setVisible(true);
  298. }
  299. });
  300. }
  301.  
  302. // Variables declaration - do not modify
  303. private javax.swing.JButton jButton1;
  304. private javax.swing.JButton jButton2;
  305. private javax.swing.JButton jButton3;
  306. private javax.swing.JLabel jLabel1;
  307. private javax.swing.JLabel jLabel2;
  308. private javax.swing.JScrollPane jScrollPane1;
  309. private javax.swing.JTable jTable1;
  310. private javax.swing.JTextField txtName;
  311. private javax.swing.JTextField txtVideoLocation;
  312. // End of variables declaration
  313. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement