Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package user;
- import java.awt.BorderLayout;
- import java.awt.EventQueue;
- import javax.swing.JFrame;
- import javax.swing.JPanel;
- import javax.swing.border.EmptyBorder;
- import javax.swing.text.JTextComponent;
- import javax.swing.JComboBox;
- import javax.swing.JTextField;
- import javax.swing.JLabel;
- import java.awt.Font;
- import java.awt.List;
- import java.awt.TextArea;
- import javax.swing.JCheckBoxMenuItem;
- import javax.swing.JSplitPane;
- import javax.swing.JSeparator;
- import javax.swing.SwingConstants;
- import java.awt.Color;
- import javax.swing.JButton;
- import javax.swing.JTextPane;
- import javax.swing.JEditorPane;
- import javax.swing.JList;
- import javax.swing.JTextArea;
- import javax.swing.DefaultComboBoxModel;
- import java.awt.event.ActionListener;
- import java.awt.geom.Area;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.Statement;
- import java.awt.event.ActionEvent;
- public class Dashboard extends JFrame {
- private JPanel contentPane;
- private final JSeparator separator = new JSeparator();
- private JTextField titre_article;
- JTextArea test;
- /**
- * Launch the application.
- */
- public static void main(String[] args) {
- EventQueue.invokeLater(new Runnable() {
- public void run() {
- try {
- Dashboard frame = new Dashboard();
- frame.setVisible(true);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- }
- /**
- * Create the frame.
- */
- public Dashboard() {
- setForeground(Color.RED);
- setBackground(Color.BLUE);
- setTitle("SupNews");
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- setBounds(100, 100, 531, 447);
- contentPane = new JPanel();
- contentPane.setForeground(Color.RED);
- contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
- setContentPane(contentPane);
- contentPane.setLayout(null);
- JLabel lblNewArticle = new JLabel("New article");
- lblNewArticle.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 18));
- lblNewArticle.setBounds(181, 12, 109, 31);
- contentPane.add(lblNewArticle);
- JLabel lblYour = new JLabel("Your articles");
- lblYour.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 18));
- lblYour.setBounds(26, 12, 122, 31);
- contentPane.add(lblYour);
- separator.setForeground(Color.BLACK);
- separator.setOrientation(SwingConstants.VERTICAL);
- separator.setBounds(161, 0, 27, 387);
- contentPane.add(separator);
- JLabel lblTitle = new JLabel("Title");
- lblTitle.setFont(new Font("Times New Roman", Font.PLAIN, 17));
- lblTitle.setBounds(188, 57, 63, 19);
- contentPane.add(lblTitle);
- titre_article = new JTextField();
- titre_article.setBounds(237, 54, 183, 22);
- contentPane.add(titre_article);
- titre_article.setColumns(10);
- JComboBox mylist = new JComboBox();
- mylist.setBounds(12, 50, 136, 43);
- contentPane.add(mylist);
- //*******************************************************************************//
- try {
- Class.forName("com.mysql.jdbc.Driver");
- Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/supnews?useSSL=true","root","");
- Statement st =con.createStatement();
- String sql = "select Title from article";
- ResultSet current_data = st.executeQuery(sql);
- while(current_data.next())
- {
- mylist.addItem(current_data.getString("Title"));
- }
- }catch(Exception e) {System.out.print(e);}
- //*********************************************************************************//
- JButton btnSave = new JButton("Save");
- btnSave.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- try {
- // init et insert
- String titre = titre_article.getText();
- String champ = test.getText();
- Class.forName("com.mysql.jdbc.Driver");
- Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/supnews?useSSL=true","root","");
- Statement st =con.createStatement();
- st.executeUpdate("INSERT INTO article (Title, Content) VALUES (\'"+titre+"\', \'"+champ+"\')");
- Dashboard.this.dispose();
- Dashboard Dashboard= new Dashboard();
- Dashboard.setVisible(true);
- }catch(Exception e) {System.out.print(e);}
- }
- //*******************************************************************************//
- });
- btnSave.setBounds(438, 329, 63, 25);
- contentPane.add(btnSave);
- JButton btnNewButton = new JButton("Preview");
- btnNewButton.setBounds(330, 329, 90, 25);
- contentPane.add(btnNewButton);
- JButton btnNewButton_1 = new JButton("Add image...");
- btnNewButton_1.setBounds(175, 329, 115, 25);
- contentPane.add(btnNewButton_1);
- JSeparator separator_1 = new JSeparator();
- separator_1.setForeground(Color.BLACK);
- separator_1.setBounds(-11, 385, 536, 15);
- contentPane.add(separator_1);
- JTextArea area_text = new JTextArea();
- area_text.setBounds(175, 89, 326, 225);
- test = area_text;
- contentPane.add(area_text);
- //*******************************************************************************//
- JButton del_article = new JButton("delete");
- del_article.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- /*ResultSet result;
- String res = null;
- try {
- Class.forName("com.mysql.jdbc.Driver");
- Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/supnews?useSSL=true","root","");
- Statement st =con.createStatement();
- result = st.executeQuery("select Title from article = "+mylist.getSelectedItem().toString());
- while(result.next()){
- res = result.getString("Title");
- }
- st.executeUpdate("DELETE FROM article where Title = " +"'"+res+"'");
- Dashboard.this.dispose();
- Dashboard Dashboard= new Dashboard();
- Dashboard.setVisible(true);
- }catch(Exception e){System.out.println(e);}*/
- PreparedStatement ps;
- String valeur = (String)mylist.getSelectedItem();
- try {
- Class.forName("com.mysql.jdbc.Driver");
- Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/supnews?useSSL=true","root","");
- Statement st =con.createStatement();
- ps = con.prepareStatement("DELETE FROM article where Title='"+valeur+"'");
- ps.execute();
- Dashboard.this.dispose();
- Dashboard Dashboard= new Dashboard();
- Dashboard.setVisible(true);
- }catch (Exception error) {
- error.printStackTrace();
- System.out.println(error);
- }
- //*******************************************************************************//
- }
- });
- del_article.setBounds(52, 329, 97, 25);
- contentPane.add(del_article);
- JButton btnView = new JButton("view");
- btnView.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- PreparedStatement ps;
- String valeur = (String)mylist.getSelectedItem();
- try {
- Class.forName("com.mysql.jdbc.Driver");
- Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/supnews?useSSL=true","root","");
- Statement st =con.createStatement();
- ps = con.prepareStatement("select Title FROM article ='"+test+"'");
- ps.execute();
- Dashboard.this.dispose();
- Dashboard Dashboard= new Dashboard();
- Dashboard.setVisible(true);
- }catch (Exception error) {
- error.printStackTrace();
- System.out.println(error);
- }
- }
- });
- btnView.setBounds(52, 272, 97, 25);
- contentPane.add(btnView);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement