Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Color;
- import java.awt.GridBagConstraints;
- import java.awt.GridBagLayout;
- import java.awt.Insets;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import javax.swing.JButton;
- import javax.swing.JComboBox;
- import javax.swing.JLabel;
- import javax.swing.JPanel;
- import javax.swing.JScrollPane;
- import javax.swing.JTextArea;
- import javax.swing.JTextField;
- import java.sql.*;
- public class PanelCreationSujet extends JPanel implements ActionListener
- {
- String utilisateur;
- JTextField jt2;
- String motdepasse;
- String titre;
- String titre2;
- int protege = 0;
- JButton envoyer;
- JTextField jt1 = new JTextField();
- JComboBox protection;
- JLabel text = new JLabel("Contents") ;
- JTextArea textArea = new JTextArea() ;
- JScrollPane scrollText = new JScrollPane(textArea) ;
- public PanelCreationSujet(String user, String password)
- {
- utilisateur = user;
- motdepasse = password;
- setLayout(new GridBagLayout());
- GridBagConstraints gbc = new GridBagConstraints();
- gbc.gridx = 0;
- gbc.gridy = 0;
- gbc.weightx = 1;
- gbc.weighty = 1;
- gbc.fill = GridBagConstraints.BOTH;
- gbc.insets = new Insets(10,20,3,20);
- JLabel entete = new JLabel("");
- entete.setText("<HTML><U>New subject :</U></HTML>");
- JLabel titre = new JLabel("Title");
- JLabel protec = new JLabel("Protection");
- String[] options = {"Public","Private"};
- protection = new JComboBox(options);
- JLabel auteur = new JLabel("User");
- envoyer = new JButton("Send");
- envoyer.addActionListener(this);
- jt2 = new JTextField();
- jt2.setText(user);
- jt2.setEditable(false);
- add(entete, gbc);
- gbc.insets = new Insets(3,20,3,20);
- gbc.gridy = 1;
- add(titre, gbc);
- gbc.gridy = 2;
- add(jt1, gbc);
- gbc.gridy = 3 ;
- add(text,gbc) ;
- gbc.gridy = 4 ;
- gbc.weighty = 8 ;
- add(scrollText,gbc) ;
- gbc.gridy = 5;
- gbc.weighty = 1 ;
- add(protec, gbc);
- gbc.gridy = 6;
- add(protection, gbc);
- gbc.gridy = 7;
- add(auteur, gbc);
- gbc.gridy = 8;
- add(jt2, gbc);
- gbc.insets = new Insets(3,20,10,20);
- gbc.gridy = 9;
- add(envoyer, gbc);
- }
- public void setUserLogin(String pUserLogin)
- {
- utilisateur = pUserLogin;
- jt2.setText(pUserLogin) ;
- }
- public void setUserPassword(String pUserPassword){motdepasse = pUserPassword;}
- public void actionPerformed(ActionEvent parEvt)
- {
- if ( parEvt.getSource() == envoyer )
- {
- if ( jt1.getText().equals("") )
- {
- javax.swing.JOptionPane.showMessageDialog(null,"The subject is empty!");
- }
- else
- {
- if( protection.getSelectedItem() == "Private")
- {
- System.out.println("Privé");
- protege = 1;
- }
- try
- {
- DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
- Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@139.59.128.221:1521:XE", utilisateur, motdepasse);
- Statement stmt = conn.createStatement();
- titre = jt1.getText();
- if(jt1.getText().equals(""))
- {
- if (jt1.getText().length() < 10)
- {
- titre2 = "Vous saurez tout sur ce sujet : " + titre;
- stmt.executeUpdate("INSERT INTO INFO.NOUVEAUSUJET VALUES('"+titre2+"', '"+protege+"')");
- stmt.executeUpdate("INSERT INTO INFO.NOUVELLELECTURE VALUES('"+titre2+"')");
- if (textArea.getText().equals(""))
- stmt.executeUpdate("INSERT INTO INFO.MODIFICATIONCONTENU VALUES('"+titre2+"', 'newsubject')");
- else
- stmt.executeUpdate("INSERT INTO INFO.MODIFICATIONCONTENU VALUES('"+titre2+"', '"+textArea.getText()+"')");
- }
- else
- {
- stmt.executeUpdate("INSERT INTO INFO.NOUVEAUSUJET VALUES('"+titre+"', '"+protege+"')");
- stmt.executeUpdate("INSERT INTO INFO.NOUVELLELECTURE VALUES('"+titre+"')");
- if (textArea.getText().equals(""))
- stmt.executeUpdate("INSERT INTO INFO.MODIFICATIONCONTENU VALUES('"+titre+"', 'newsubject')");
- else
- stmt.executeUpdate("INSERT INTO INFO.MODIFICATIONCONTENU VALUES('"+titre+"', '"+textArea.getText()+"')");
- }
- }
- else
- {
- javax.swing.JOptionPane.showMessageDialog(null,"The subject is empty!");
- }
- }
- catch (SQLException e)
- {
- javax.swing.JOptionPane.showMessageDialog(null,e);
- }
- }
- /*
- stmt.executeUpdate("DELETE * FROM AVION");
- stmt.executeUpdate("CREATE TABLE AVION (Code_Avion CHAR(6), Designation_Avion CHAR (5), Code_Compagnie CHAR(6))");
- stmt.executeUpdate("INSERT INTO AVION VALUES('7TRJ', 'B731', 'FR1024')");
- ResultSet rset1 = stmt.executeQuery ("SELECT * FROM AVION");
- */
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement