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

📄 addremindui.java

📁 用JAVA开发的提醒精灵
💻 JAVA
字号:
package com.liming.remind.ui;


import java.awt.BorderLayout;
import java.awt.FlowLayout;
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.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;

import com.liming.remind.common.RemindUtils;
import com.liming.remind.dto.Remind;


/**
 * Function : Provide UI to add Remind
 * 
 * @author Liming
 * @time Dec 17, 2008 8:32:56 PM
 * @version 1.0
 */
public class AddRemindUI extends JDialog {

    /**
     * Field : serialVersionUID
     */
    private static final long serialVersionUID = 1255439622994306473L;
    private JLabel remindTimeLb;
    private JLabel remindContentLb;
    private JTextField remindTimeTf;
    private JTextField remindContentTf;
    private JButton okBtn;
    private JButton cancelBtn;

    private Remind remind;
    private boolean isRemindNull;

    public AddRemindUI() {
        isRemindNull = true;

        // Set modal
        setModal(true);
        // Get windows lookAndFeel
        RemindUtils.getWindowsLookAndFeel(this);

        // Get Content Pane
        JPanel panel = (JPanel) getContentPane();
        BorderLayout border = new BorderLayout();
        setLayout(border);

        // Add input fields to Pane
        panel.add(getInputField(), BorderLayout.NORTH);
        // Add buttons to Pane
        panel.add(getButton(), BorderLayout.CENTER);

        initStatus();

    }

    /**
     * @return the remind
     */
    public Remind getRemind() {
        return remind;
    }

    /**
     * @return the isRemindNull
     */
    public boolean isRemindNull() {
        return isRemindNull;
    }

    /**
     * Function : Get input fields
     * 
     * @return
     */
    private JPanel getInputField() {
        JPanel inputPanel = new JPanel();
        GridBagLayout gbc = new GridBagLayout();

        // Set GridBagLayout to the JPanel
        inputPanel.setLayout(gbc);
        GridBagConstraints gc = new GridBagConstraints();
        gc.insets = new Insets(10, 10, 10, 10);

        gc.gridx = 0;
        gc.gridy = 0;
        remindTimeLb = new JLabel("Warning Time:");
        inputPanel.add(remindTimeLb, gc);

        gc.gridx = 1;
        gc.gridy = 0;
        remindTimeTf = new JTextField("18:00");
        remindTimeTf.setColumns(15);
        inputPanel.add(remindTimeTf, gc);

        gc.gridx = 0;
        gc.gridy = 1;
        remindContentLb = new JLabel("Warning Content:");
        inputPanel.add(remindContentLb, gc);

        gc.gridx = 1;
        gc.gridy = 1;
        remindContentTf = new JTextField();
        remindContentTf.setColumns(15);
        inputPanel.add(remindContentTf, gc);

        return inputPanel;
    }

    /**
     * Function : Get OK and cancel buttons
     * 
     * @return
     */
    private JPanel getButton() {
        JPanel buttonPanel = new JPanel();

        // Set FlowLayout to Jpanel
        FlowLayout flowLayout = new FlowLayout();
        buttonPanel.setLayout(flowLayout);

        okBtn = new JButton("Ok");
        okBtn.setActionCommand("ok");
        okBtn.addActionListener(new MyActionListener());
        buttonPanel.add(okBtn);

        cancelBtn = new JButton("Cancel");
        cancelBtn.setActionCommand("cancel");
        cancelBtn.addActionListener(new MyActionListener());
        buttonPanel.add(cancelBtn);

        return buttonPanel;
    }

    /**
     * Function : initial status
     */
    private void initStatus() {
        setTitle("Add Remind");

        // Set default close operation
        setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

        // Set the size of JDialog
        setSize(250, 150);

        RemindUtils.setUIMiddleOfTheWindow(this);

        // Can not be reSized
        setResizable(false);
    }

    /**
     * Function : The inner class to handle the click events
     * 
     * @author Liming
     * @time Dec 17, 2008 10:04:42 PM
     * @version 1.0
     */
    private class MyActionListener implements ActionListener {

        public void actionPerformed(ActionEvent e) {
            if (e.getActionCommand().equals("ok")) {
                boolean validTime = RemindUtils
                        .validateTimePattern(remindTimeTf.getText());
                boolean isEmpty = (remindContentTf.getText().trim().length() == 0);

                // Judge the time pattern is valid or not
                if (!validTime) {
                    JOptionPane.showMessageDialog(null,
                            "Time format is wrong.", "System Warning",
                            JOptionPane.YES_OPTION,
                            new ImageIcon("res/tip.gif"));
                    return;
                }

                // Judge the content is empty or not
                if (isEmpty) {
                    JOptionPane.showMessageDialog(null,
                            "The Content can not be null.", "System Warning",
                            JOptionPane.YES_OPTION,
                            new ImageIcon("res/tip.gif"));
                    return;
                }

                // Create a new Remind
                remind = new Remind();
                remind.setTime(RemindUtils.changeToStrictPatter(remindTimeTf
                        .getText()));
                remind.setTips(remindContentTf.getText());

                // Set the variable 'isRemindNul' is false
                isRemindNull = false;
                dispose();
            }
            if (e.getActionCommand().equals("cancel")) {
                dispose();
            }
        }
    }

}

⌨️ 快捷键说明

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