?? updatephotoinfodialog.java
字號(hào):
/*
* 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("圖片標(biāo)題:");
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();// 銷毀對(duì)話框
selectedPhoto.setText(titleTextField.getText());// 修改照片標(biāo)題
Vector<String> photoV = dao.selectPhoto(selectedPhoto.getName());// 獲得照片信息
photoV.set(2, dateTextField.getText());// 修改日期
photoV.set(3, titleTextField.getText());// 修改標(biāo)題
photoV.set(4, remarkTextArea.getText());// 修改說明
ToolTip.set(selectedPhoto, photoV);// 修改工具提示
dao.updatePhoto(selectedPhoto.getName(), titleTextField.getText(),
dateTextField.getText(), remarkTextArea.getText());// 將修改保存到數(shù)據(jù)庫
}
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) {// 照片標(biāo)題最多為10個(gè)字符
evt.consume();// 銷毀此次鍵盤事件
}
}
private void titleTextFieldCaretUpdate(javax.swing.event.CaretEvent evt) {
// TODO add your handling code here:
if (titleTextField.getText().trim().length() == 0) {// 標(biāo)題為空
submitButton.setEnabled(false);// 將“確定”按鈕設(shè)置為不可用
} else {// 標(biāo)題不為空
if (!submitButton.isEnabled()) {// 如果“確定”按鈕不可用
submitButton.setEnabled(true);// 將“確定”按鈕設(shè)置為可用
}
}
}
/**
* @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
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -