Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package GUI;
- import BE.Video;
- import BLL.videoManager;
- import com.sun.corba.se.impl.presentation.rmi.ExceptionHandler;
- //import gui.model.VideoTableModel;
- import java.io.File;
- import java.io.IOException;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- import java.util.Observable;
- import java.util.Observer;
- import java.util.ResourceBundle;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import javax.swing.DefaultComboBoxModel;
- import javax.swing.JFileChooser;
- import javax.swing.JOptionPane;
- import javax.swing.ListSelectionModel;
- import javax.swing.UIManager;
- import javax.swing.event.ListSelectionEvent;
- import javax.swing.event.ListSelectionListener;
- //import GUI.Models.VideoTableModel;
- /**
- *
- * @author Hjemme-PC
- */
- public class Create extends javax.swing.JFrame {
- // private VideoTableModel modelVideo = null;
- private static Create instance = null;
- // private VideoTableModel modelVideo = null;
- static videoManager managerVideo = null;
- videoManager vmgr;
- public static Create getInstance() throws SQLException
- {
- if (instance == null)
- {
- instance = new Create();
- }
- return instance;
- }
- public Create() {
- try {
- initComponents();
- vmgr = videoManager.getInstance();
- initComponents();
- } catch (IOException ex) {
- Logger.getLogger(Create.class.getName()).log(Level.SEVERE, null, ex);
- } catch (SQLException ex) {
- Logger.getLogger(Create.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- public void addPressed()
- {
- if (txtName.getText().length() != 0 && txtVideoLocation.getText().length() != 0)
- {
- String videoName = txtName.getText().trim();
- String videoLocation = txtVideoLocation.getText().trim();
- Video video = new Video(videoName, videoLocation);
- try
- {
- vmgr.add(video);
- closePressed();
- }
- catch (Exception ex)
- {
- throw;
- }
- }
- else
- {
- String message = "Det er opstået en ukendt fejl.";
- int reply = JOptionPane.showConfirmDialog(this, message, getTitle(), JOptionPane.CLOSED_OPTION);
- }
- //disable();
- clearFields();
- // String message = "Video is uploaded to your mobile server.";
- // JOptionPane.showMessageDialog(this, message, getTitle(), JOptionPane.ERROR_MESSAGE);
- }
- private void closePressed()
- {
- String message = "Ny video er tilføjet. Vil du tilføje flere videoer?";
- int reply = JOptionPane.showConfirmDialog(this, message, getTitle(), JOptionPane.YES_NO_OPTION);
- if (reply == JOptionPane.NO_OPTION)
- {
- System.exit(0);
- }
- }
- public String requiredFields()
- {
- String errorMessage = "";
- if (txtName == null || txtName.getText().trim().isEmpty())
- {
- errorMessage += "Titel Name is missing\n";
- }
- if (txtVideoLocation == null || txtVideoLocation.getText().trim().isEmpty())
- {
- errorMessage += "Video Location is missing\n";
- }
- return errorMessage;
- }
- private void clearFields() {
- txtName.setText("");
- txtVideoLocation.setText("");
- }
- // private void videoListSelectioner() throws IOException, SQLException
- // {
- // try
- // {
- // managerVideo.addObserver((Observer) this);
- // modelVideo = new VideoTableModel(managerVideo.getAllVideos());
- // jTable1.setModel(modelVideo);
- // }
- // catch (Exception ex)
- // {
- // }
- // }
- @SuppressWarnings("unchecked")
- // <editor-fold defaultstate="collapsed" desc="Generated Code">
- private void initComponents() {
- jLabel1 = new javax.swing.JLabel();
- txtName = new javax.swing.JTextField();
- jLabel2 = new javax.swing.JLabel();
- txtVideoLocation = new javax.swing.JTextField();
- jButton3 = new javax.swing.JButton();
- jButton1 = new javax.swing.JButton();
- jButton2 = new javax.swing.JButton();
- jScrollPane1 = new javax.swing.JScrollPane();
- jTable1 = new javax.swing.JTable();
- setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
- jLabel1.setText("Titel:");
- jLabel2.setText("Sti:");
- jButton3.setText("...");
- jButton3.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton3ActionPerformed(evt);
- }
- });
- jButton1.setText("Opret");
- jButton1.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton1ActionPerformed(evt);
- }
- });
- jButton2.setText("Annuller");
- jButton2.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton2ActionPerformed(evt);
- }
- });
- jTable1.setModel(new javax.swing.table.DefaultTableModel(
- new Object [][] {
- {null, null, null, null},
- {null, null, null, null},
- {null, null, null, null},
- {null, null, null, null}
- },
- new String [] {
- "Title 1", "Title 2", "Title 3", "Title 4"
- }
- ));
- jScrollPane1.setViewportView(jTable1);
- javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
- getContentPane().setLayout(layout);
- layout.setHorizontalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
- .addContainerGap(15, Short.MAX_VALUE)
- .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 418, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addContainerGap())
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addContainerGap()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
- .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
- .addComponent(jLabel1)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addComponent(txtName))
- .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
- .addGap(8, 8, 8)
- .addComponent(jLabel2)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addComponent(txtVideoLocation)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGroup(layout.createSequentialGroup()
- .addGap(283, 283, 283)
- .addComponent(jButton1)
- .addGap(8, 8, 8)
- .addComponent(jButton2)))
- .addContainerGap()))
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
- .addContainerGap(228, Short.MAX_VALUE)
- .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 197, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addContainerGap())
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addGap(90, 90, 90)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jLabel1)
- .addComponent(txtName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jLabel2)
- .addComponent(txtVideoLocation, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(jButton3))
- .addGap(43, 43, 43)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jButton1)
- .addComponent(jButton2))
- .addContainerGap(226, Short.MAX_VALUE)))
- );
- pack();
- }// </editor-fold>
- private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
- JFileChooser chooser = new JFileChooser();
- chooser.showOpenDialog(null);
- File f = chooser.getSelectedFile();
- String videoname = f.getAbsolutePath();
- txtVideoLocation.setText((videoname));
- }
- private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
- addPressed();
- }
- private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
- System.exit(0);
- }
- /**
- * @param args the command line arguments
- */
- public static void main(String args[]) {
- /* Set the Nimbus look and feel */
- //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
- /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
- * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
- */
- try {
- for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
- if ("Nimbus".equals(info.getName())) {
- javax.swing.UIManager.setLookAndFeel(info.getClassName());
- break;
- }
- }
- } catch (ClassNotFoundException ex) {
- java.util.logging.Logger.getLogger(Create.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (InstantiationException ex) {
- java.util.logging.Logger.getLogger(Create.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (IllegalAccessException ex) {
- java.util.logging.Logger.getLogger(Create.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (javax.swing.UnsupportedLookAndFeelException ex) {
- java.util.logging.Logger.getLogger(Create.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- }
- //</editor-fold>
- /* Create and display the form */
- java.awt.EventQueue.invokeLater(new Runnable() {
- public void run() {
- new Create().setVisible(true);
- }
- });
- }
- // Variables declaration - do not modify
- private javax.swing.JButton jButton1;
- private javax.swing.JButton jButton2;
- private javax.swing.JButton jButton3;
- private javax.swing.JLabel jLabel1;
- private javax.swing.JLabel jLabel2;
- private javax.swing.JScrollPane jScrollPane1;
- private javax.swing.JTable jTable1;
- private javax.swing.JTextField txtName;
- private javax.swing.JTextField txtVideoLocation;
- // End of variables declaration
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement