Advertisement
Guest User

Untitled

a guest
May 16th, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.98 KB | None | 0 0
  1. import java.awt.Color;
  2. import java.awt.GridBagConstraints;
  3. import java.awt.GridBagLayout;
  4. import java.awt.Insets;
  5. import java.awt.event.ActionEvent;
  6. import java.awt.event.ActionListener;
  7.  
  8. import javax.swing.JButton;
  9. import javax.swing.JComboBox;
  10. import javax.swing.JLabel;
  11. import javax.swing.JPanel;
  12. import javax.swing.JScrollPane;
  13. import javax.swing.JTextArea;
  14. import javax.swing.JTextField;
  15.  
  16. import java.sql.*;
  17.  
  18. public class PanelCreationSujet extends JPanel implements ActionListener
  19. {
  20. String utilisateur;
  21. JTextField jt2;
  22. String motdepasse;
  23. String titre;
  24. String titre2;
  25. int protege = 0;
  26. JButton envoyer;
  27. JTextField jt1 = new JTextField();
  28. JComboBox protection;
  29.  
  30. JLabel text = new JLabel("Contents") ;
  31. JTextArea textArea = new JTextArea() ;
  32. JScrollPane scrollText = new JScrollPane(textArea) ;
  33.  
  34. public PanelCreationSujet(String user, String password)
  35. {
  36. utilisateur = user;
  37. motdepasse = password;
  38. setLayout(new GridBagLayout());
  39.  
  40. GridBagConstraints gbc = new GridBagConstraints();
  41. gbc.gridx = 0;
  42. gbc.gridy = 0;
  43. gbc.weightx = 1;
  44. gbc.weighty = 1;
  45. gbc.fill = GridBagConstraints.BOTH;
  46. gbc.insets = new Insets(10,20,3,20);
  47.  
  48. JLabel entete = new JLabel("");
  49. entete.setText("<HTML><U>New subject :</U></HTML>");
  50. JLabel titre = new JLabel("Title");
  51. JLabel protec = new JLabel("Protection");
  52. String[] options = {"Public","Private"};
  53. protection = new JComboBox(options);
  54. JLabel auteur = new JLabel("User");
  55. envoyer = new JButton("Send");
  56. envoyer.addActionListener(this);
  57.  
  58. jt2 = new JTextField();
  59. jt2.setText(user);
  60. jt2.setEditable(false);
  61.  
  62. add(entete, gbc);
  63.  
  64. gbc.insets = new Insets(3,20,3,20);
  65. gbc.gridy = 1;
  66. add(titre, gbc);
  67.  
  68. gbc.gridy = 2;
  69. add(jt1, gbc);
  70.  
  71. gbc.gridy = 3 ;
  72. add(text,gbc) ;
  73.  
  74. gbc.gridy = 4 ;
  75. gbc.weighty = 8 ;
  76. add(scrollText,gbc) ;
  77.  
  78. gbc.gridy = 5;
  79. gbc.weighty = 1 ;
  80. add(protec, gbc);
  81.  
  82. gbc.gridy = 6;
  83. add(protection, gbc);
  84.  
  85. gbc.gridy = 7;
  86. add(auteur, gbc);
  87.  
  88. gbc.gridy = 8;
  89. add(jt2, gbc);
  90.  
  91. gbc.insets = new Insets(3,20,10,20);
  92. gbc.gridy = 9;
  93. add(envoyer, gbc);
  94. }
  95.  
  96. public void setUserLogin(String pUserLogin)
  97. {
  98. utilisateur = pUserLogin;
  99. jt2.setText(pUserLogin) ;
  100. }
  101.  
  102. public void setUserPassword(String pUserPassword){motdepasse = pUserPassword;}
  103.  
  104. public void actionPerformed(ActionEvent parEvt)
  105. {
  106. if ( parEvt.getSource() == envoyer )
  107. {
  108. if ( jt1.getText().equals("") )
  109. {
  110. javax.swing.JOptionPane.showMessageDialog(null,"The subject is empty!");
  111. }
  112. else
  113. {
  114. if( protection.getSelectedItem() == "Private")
  115. {
  116. System.out.println("Privé");
  117. protege = 1;
  118. }
  119. try
  120. {
  121. DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
  122. Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@139.59.128.221:1521:XE", utilisateur, motdepasse);
  123. Statement stmt = conn.createStatement();
  124. titre = jt1.getText();
  125. if(jt1.getText().equals(""))
  126. {
  127. if (jt1.getText().length() < 10)
  128. {
  129. titre2 = "Vous saurez tout sur ce sujet : " + titre;
  130. stmt.executeUpdate("INSERT INTO INFO.NOUVEAUSUJET VALUES('"+titre2+"', '"+protege+"')");
  131. stmt.executeUpdate("INSERT INTO INFO.NOUVELLELECTURE VALUES('"+titre2+"')");
  132. if (textArea.getText().equals(""))
  133. stmt.executeUpdate("INSERT INTO INFO.MODIFICATIONCONTENU VALUES('"+titre2+"', 'newsubject')");
  134. else
  135. stmt.executeUpdate("INSERT INTO INFO.MODIFICATIONCONTENU VALUES('"+titre2+"', '"+textArea.getText()+"')");
  136. }
  137. else
  138. {
  139. stmt.executeUpdate("INSERT INTO INFO.NOUVEAUSUJET VALUES('"+titre+"', '"+protege+"')");
  140. stmt.executeUpdate("INSERT INTO INFO.NOUVELLELECTURE VALUES('"+titre+"')");
  141. if (textArea.getText().equals(""))
  142. stmt.executeUpdate("INSERT INTO INFO.MODIFICATIONCONTENU VALUES('"+titre+"', 'newsubject')");
  143. else
  144. stmt.executeUpdate("INSERT INTO INFO.MODIFICATIONCONTENU VALUES('"+titre+"', '"+textArea.getText()+"')");
  145. }
  146. }
  147. else
  148. {
  149. javax.swing.JOptionPane.showMessageDialog(null,"The subject is empty!");
  150. }
  151. }
  152. catch (SQLException e)
  153. {
  154. javax.swing.JOptionPane.showMessageDialog(null,e);
  155. }
  156. }
  157.  
  158. /*
  159. stmt.executeUpdate("DELETE * FROM AVION");
  160.  
  161. stmt.executeUpdate("CREATE TABLE AVION (Code_Avion CHAR(6), Designation_Avion CHAR (5), Code_Compagnie CHAR(6))");
  162.  
  163. stmt.executeUpdate("INSERT INTO AVION VALUES('7TRJ', 'B731', 'FR1024')");
  164.  
  165. ResultSet rset1 = stmt.executeQuery ("SELECT * FROM AVION");
  166. */
  167. }
  168. }
  169.  
  170. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement