⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 updatephotoinfodialog.java

📁 数码照片管理程序是我们公司在开发过程中的用java编写的模块
💻 JAVA
字号:
/*
 * NewJDialog.java
 *
 * Created on 2008年8月15日, 下午2:31
 */
package com.mwq.album.frame;

import com.mwq.album.dao.Dao;
import com.mwq.album.tool.ScreenSize;
import com.mwq.album.tool.ToolTip;
import java.util.Vector;
import javax.swing.JButton;
import javax.swing.JTextField;

/**
 *
 * @author  Administrator
 */
public class UpdatePhotoInfoDialog extends javax.swing.JDialog {

    private static final Dao dao = Dao.getInstance();
    private JTextField dateTextField;
    private JButton selectedPhoto;

    /** Creates new form NewJDialog */
    public UpdatePhotoInfoDialog(java.awt.Frame parent, boolean modal, JButton selectedPhoto) {
        super(parent, modal);
        initComponents();
        dateTextField = calendarPanel.getTextField();
        Vector photoV = Dao.getInstance().selectPhoto(selectedPhoto.getName());
        titleTextField.setText(photoV.get(3).toString());
        dateTextField.setText(photoV.get(2).toString());
        remarkTextArea.setText(photoV.get(4).toString());
        this.selectedPhoto = selectedPhoto;
        ScreenSize.centered(this);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        titleLabel = new javax.swing.JLabel();
        dateLabel = new javax.swing.JLabel();
        remarkLabel = new javax.swing.JLabel();
        titleTextField = new javax.swing.JTextField();
        calendarPanel = new com.mwq.album.calendar.CalendarPanel();
        remarkScrollPane = new javax.swing.JScrollPane();
        remarkTextArea = new javax.swing.JTextArea();
        exitButton = new javax.swing.JButton();
        submitButton = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("修改信息");

        titleLabel.setText("图片标题:");

        dateLabel.setText("拍摄日期:");

        remarkLabel.setText("图片描述:");

        titleTextField.setColumns(30);
        titleTextField.addCaretListener(new javax.swing.event.CaretListener() {
            public void caretUpdate(javax.swing.event.CaretEvent evt) {
                titleTextFieldCaretUpdate(evt);
            }
        });
        titleTextField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                titleTextFieldKeyTyped(evt);
            }
        });

        remarkTextArea.setColumns(40);
        remarkTextArea.setLineWrap(true);
        remarkTextArea.setRows(5);
        remarkScrollPane.setViewportView(remarkTextArea);

        exitButton.setText("退出");
        exitButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                exitButtonActionPerformed(evt);
            }
        });

        submitButton.setText("确定");
        submitButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                submitButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(titleLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(titleTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(dateLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(calendarPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(remarkLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(remarkScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(200, Short.MAX_VALUE)
                .addComponent(submitButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(exitButton)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(titleLabel)
                    .addComponent(titleTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(calendarPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(dateLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(remarkLabel)
                    .addComponent(remarkScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 21, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(exitButton)
                    .addComponent(submitButton))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>                        

private void submitButtonActionPerformed(java.awt.event.ActionEvent evt) {                                             
// TODO add your handling code here:
    this.dispose();// 销毁对话框

    selectedPhoto.setText(titleTextField.getText());// 修改照片标题

    Vector<String> photoV = dao.selectPhoto(selectedPhoto.getName());// 获得照片信息

    photoV.set(2, dateTextField.getText());// 修改日期

    photoV.set(3, titleTextField.getText());// 修改标题

    photoV.set(4, remarkTextArea.getText());// 修改说明

    ToolTip.set(selectedPhoto, photoV);// 修改工具提示

    dao.updatePhoto(selectedPhoto.getName(), titleTextField.getText(),
            dateTextField.getText(), remarkTextArea.getText());// 将修改保存到数据库
}                                            

private void exitButtonActionPerformed(java.awt.event.ActionEvent evt) {                                           
// TODO add your handling code here:
    this.dispose();
}                                          

private void titleTextFieldKeyTyped(java.awt.event.KeyEvent evt) {                                        
// TODO add your handling code here:
    if (titleTextField.getText().getBytes().length == 20) {// 照片标题最多为10个字符

        evt.consume();// 销毁此次键盘事件

    }
}                                       

private void titleTextFieldCaretUpdate(javax.swing.event.CaretEvent evt) {                                           
// TODO add your handling code here:
    if (titleTextField.getText().trim().length() == 0) {// 标题为空

        submitButton.setEnabled(false);// 将“确定”按钮设置为不可用

    } else {// 标题不为空

        if (!submitButton.isEnabled()) {// 如果“确定”按钮不可用

            submitButton.setEnabled(true);// 将“确定”按钮设置为可用

        }
    }
}                                          

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                UpdatePhotoInfoDialog dialog = new UpdatePhotoInfoDialog(new javax.swing.JFrame(), true, null);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {

                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify                     
    private com.mwq.album.calendar.CalendarPanel calendarPanel;
    private javax.swing.JLabel dateLabel;
    private javax.swing.JButton exitButton;
    private javax.swing.JLabel remarkLabel;
    private javax.swing.JScrollPane remarkScrollPane;
    private javax.swing.JTextArea remarkTextArea;
    private javax.swing.JButton submitButton;
    private javax.swing.JLabel titleLabel;
    private javax.swing.JTextField titleTextField;
    // End of variables declaration                   
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -