Advertisement
Guest User

Untitled

a guest
Mar 21st, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.12 KB | None | 0 0
  1. package user;
  2.  
  3. import java.awt.BorderLayout;
  4. import java.awt.EventQueue;
  5.  
  6. import javax.swing.JFrame;
  7. import javax.swing.JPanel;
  8. import javax.swing.border.EmptyBorder;
  9. import javax.swing.text.JTextComponent;
  10. import javax.swing.JComboBox;
  11. import javax.swing.JTextField;
  12. import javax.swing.JLabel;
  13. import java.awt.Font;
  14. import java.awt.List;
  15. import java.awt.TextArea;
  16.  
  17. import javax.swing.JCheckBoxMenuItem;
  18. import javax.swing.JSplitPane;
  19. import javax.swing.JSeparator;
  20. import javax.swing.SwingConstants;
  21. import java.awt.Color;
  22. import javax.swing.JButton;
  23. import javax.swing.JTextPane;
  24. import javax.swing.JEditorPane;
  25. import javax.swing.JList;
  26. import javax.swing.JTextArea;
  27. import javax.swing.DefaultComboBoxModel;
  28. import java.awt.event.ActionListener;
  29. import java.awt.geom.Area;
  30. import java.sql.Connection;
  31. import java.sql.DriverManager;
  32. import java.sql.PreparedStatement;
  33. import java.sql.ResultSet;
  34. import java.sql.Statement;
  35. import java.awt.event.ActionEvent;
  36.  
  37.  
  38. public class Dashboard extends JFrame {
  39.  
  40. private JPanel contentPane;
  41. private final JSeparator separator = new JSeparator();
  42. private JTextField titre_article;
  43. JTextArea test;
  44.  
  45. /**
  46. * Launch the application.
  47. */
  48. public static void main(String[] args) {
  49. EventQueue.invokeLater(new Runnable() {
  50. public void run() {
  51. try {
  52. Dashboard frame = new Dashboard();
  53. frame.setVisible(true);
  54. } catch (Exception e) {
  55. e.printStackTrace();
  56. }
  57. }
  58. });
  59. }
  60.  
  61. /**
  62. * Create the frame.
  63. */
  64. public Dashboard() {
  65.  
  66. setForeground(Color.RED);
  67. setBackground(Color.BLUE);
  68. setTitle("SupNews");
  69. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  70. setBounds(100, 100, 531, 447);
  71. contentPane = new JPanel();
  72. contentPane.setForeground(Color.RED);
  73. contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
  74. setContentPane(contentPane);
  75. contentPane.setLayout(null);
  76.  
  77. JLabel lblNewArticle = new JLabel("New article");
  78. lblNewArticle.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 18));
  79. lblNewArticle.setBounds(181, 12, 109, 31);
  80. contentPane.add(lblNewArticle);
  81.  
  82. JLabel lblYour = new JLabel("Your articles");
  83. lblYour.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 18));
  84. lblYour.setBounds(26, 12, 122, 31);
  85. contentPane.add(lblYour);
  86. separator.setForeground(Color.BLACK);
  87. separator.setOrientation(SwingConstants.VERTICAL);
  88. separator.setBounds(161, 0, 27, 387);
  89. contentPane.add(separator);
  90.  
  91. JLabel lblTitle = new JLabel("Title");
  92. lblTitle.setFont(new Font("Times New Roman", Font.PLAIN, 17));
  93. lblTitle.setBounds(188, 57, 63, 19);
  94. contentPane.add(lblTitle);
  95.  
  96. titre_article = new JTextField();
  97. titre_article.setBounds(237, 54, 183, 22);
  98. contentPane.add(titre_article);
  99. titre_article.setColumns(10);
  100.  
  101. JComboBox mylist = new JComboBox();
  102. mylist.setBounds(12, 50, 136, 43);
  103. contentPane.add(mylist);
  104.  
  105.  
  106. //*******************************************************************************//
  107. try {
  108. Class.forName("com.mysql.jdbc.Driver");
  109. Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/supnews?useSSL=true","root","");
  110. Statement st =con.createStatement();
  111. String sql = "select Title from article";
  112.  
  113. ResultSet current_data = st.executeQuery(sql);
  114.  
  115. while(current_data.next())
  116. {
  117. mylist.addItem(current_data.getString("Title"));
  118. }
  119. }catch(Exception e) {System.out.print(e);}
  120.  
  121.  
  122. //*********************************************************************************//
  123.  
  124.  
  125. JButton btnSave = new JButton("Save");
  126. btnSave.addActionListener(new ActionListener() {
  127. public void actionPerformed(ActionEvent arg0) {
  128.  
  129. try {
  130. // init et insert
  131. String titre = titre_article.getText();
  132. String champ = test.getText();
  133.  
  134. Class.forName("com.mysql.jdbc.Driver");
  135. Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/supnews?useSSL=true","root","");
  136. Statement st =con.createStatement();
  137. st.executeUpdate("INSERT INTO article (Title, Content) VALUES (\'"+titre+"\', \'"+champ+"\')");
  138.  
  139. Dashboard.this.dispose();
  140. Dashboard Dashboard= new Dashboard();
  141. Dashboard.setVisible(true);
  142.  
  143. }catch(Exception e) {System.out.print(e);}
  144. }
  145.  
  146.  
  147. //*******************************************************************************//
  148.  
  149. });
  150. btnSave.setBounds(438, 329, 63, 25);
  151. contentPane.add(btnSave);
  152.  
  153. JButton btnNewButton = new JButton("Preview");
  154. btnNewButton.setBounds(330, 329, 90, 25);
  155. contentPane.add(btnNewButton);
  156.  
  157. JButton btnNewButton_1 = new JButton("Add image...");
  158. btnNewButton_1.setBounds(175, 329, 115, 25);
  159. contentPane.add(btnNewButton_1);
  160.  
  161. JSeparator separator_1 = new JSeparator();
  162. separator_1.setForeground(Color.BLACK);
  163. separator_1.setBounds(-11, 385, 536, 15);
  164. contentPane.add(separator_1);
  165.  
  166.  
  167. JTextArea area_text = new JTextArea();
  168. area_text.setBounds(175, 89, 326, 225);
  169. test = area_text;
  170. contentPane.add(area_text);
  171.  
  172. //*******************************************************************************//
  173.  
  174. JButton del_article = new JButton("delete");
  175. del_article.addActionListener(new ActionListener() {
  176. public void actionPerformed(ActionEvent arg0) {
  177.  
  178. /*ResultSet result;
  179. String res = null;
  180.  
  181. try {
  182. Class.forName("com.mysql.jdbc.Driver");
  183. Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/supnews?useSSL=true","root","");
  184. Statement st =con.createStatement();
  185.  
  186. result = st.executeQuery("select Title from article = "+mylist.getSelectedItem().toString());
  187.  
  188. while(result.next()){
  189.  
  190. res = result.getString("Title");
  191.  
  192. }
  193.  
  194. st.executeUpdate("DELETE FROM article where Title = " +"'"+res+"'");
  195.  
  196.  
  197. Dashboard.this.dispose();
  198. Dashboard Dashboard= new Dashboard();
  199. Dashboard.setVisible(true);
  200.  
  201.  
  202. }catch(Exception e){System.out.println(e);}*/
  203.  
  204.  
  205. PreparedStatement ps;
  206. String valeur = (String)mylist.getSelectedItem();
  207.  
  208. try {
  209. Class.forName("com.mysql.jdbc.Driver");
  210. Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/supnews?useSSL=true","root","");
  211. Statement st =con.createStatement();
  212.  
  213. ps = con.prepareStatement("DELETE FROM article where Title='"+valeur+"'");
  214.  
  215. ps.execute();
  216.  
  217. Dashboard.this.dispose();
  218. Dashboard Dashboard= new Dashboard();
  219. Dashboard.setVisible(true);
  220.  
  221.  
  222. }catch (Exception error) {
  223. error.printStackTrace();
  224. System.out.println(error);
  225. }
  226. //*******************************************************************************//
  227.  
  228. }
  229. });
  230. del_article.setBounds(52, 329, 97, 25);
  231. contentPane.add(del_article);
  232.  
  233. JButton btnView = new JButton("view");
  234. btnView.addActionListener(new ActionListener() {
  235. public void actionPerformed(ActionEvent arg0) {
  236.  
  237. PreparedStatement ps;
  238. String valeur = (String)mylist.getSelectedItem();
  239.  
  240. try {
  241. Class.forName("com.mysql.jdbc.Driver");
  242. Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/supnews?useSSL=true","root","");
  243. Statement st =con.createStatement();
  244.  
  245. ps = con.prepareStatement("select Title FROM article ='"+test+"'");
  246.  
  247. ps.execute();
  248.  
  249. Dashboard.this.dispose();
  250. Dashboard Dashboard= new Dashboard();
  251. Dashboard.setVisible(true);
  252.  
  253.  
  254. }catch (Exception error) {
  255. error.printStackTrace();
  256. System.out.println(error);
  257. }
  258. }
  259.  
  260. });
  261. btnView.setBounds(52, 272, 97, 25);
  262. contentPane.add(btnView);
  263.  
  264.  
  265.  
  266. }
  267. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement