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

📄 groupcreatepanel.java

📁 用jxse开发的一个p2p通讯软件 有聊天 文件共享 视频3大功能
💻 JAVA
字号:
/**  Copyright (c) 2001 Sun Microsystems, Inc.  All rights*  reserved.**  Redistribution and use in source and binary forms, with or without*  modification, are permitted provided that the following conditions*  are met:**  1. Redistributions of source code must retain the above copyright*  notice, this list of conditions and the following disclaimer.**  2. Redistributions in binary form must reproduce the above copyright*  notice, this list of conditions and the following disclaimer in*  the documentation and/or other materials provided with the*  distribution.**  3. The end-user documentation included with the redistribution,*  if any, must include the following acknowledgment:*  "This product includes software developed by the*  Sun Microsystems, Inc. for Project JXTA."*  Alternately, this acknowledgment may appear in the software itself,*  if and wherever such third-party acknowledgments normally appear.**  4. The groups "Sun", "Sun Microsystems, Inc.", "JXTA" and "Project JXTA"*  must not be used to endorse or promote products derived from this*  software without prior written permission. For written*  permission, please contact Project JXTA at http://www.jxta.org.**  5. Products derived from this software may not be called "JXTA",*  nor may "JXTA" appear in their group, without prior written*  permission of Sun.**  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED*  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES*  OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE*  DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR*  ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,*  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT*  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF*  USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND*  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,*  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT*  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF*  SUCH DAMAGE.*  ====================================================================**  This software consists of voluntary contributions made by many*  individuals on behalf of Project JXTA.  For more*  information on Project JXTA, please see*  <http://www.jxta.org/>.**  This license is based on the BSD license adopted by the Apache Foundation.**  $Id: GroupCreatePanel.java,v 1.7 2005/10/28 18:01:48 nano Exp $*/package net.jxta.myjxta.ui;import net.jxta.myjxta.util.Resources;import java.awt.GridBagConstraints;import java.awt.GridBagLayout;import java.awt.GridLayout;import java.awt.Insets;import java.awt.event.ActionEvent;import java.awt.event.KeyAdapter;import java.awt.event.KeyEvent;import javax.swing.AbstractAction;import javax.swing.BorderFactory;import javax.swing.JButton;import javax.swing.JLabel;import javax.swing.JPanel;import javax.swing.JSlider;import javax.swing.JTextField;import javax.swing.JPasswordField;import java.util.ResourceBundle;/** * * @version $Id: GroupCreatePanel.java,v 1.7 2005/10/28 18:01:48 nano Exp $ * * @author james todd [gonzo at jxta dot org] */public class GroupCreatePanel    extends JPanel {    private static final ResourceBundle STRINGS = Resources.getStrings();    private static final int MINIMUM_EXPIRATION = 2;    private static final int INITIAL_EXPIRATION = 14;    private static final int MAXIMUM_EXPIRATION = 104;        private JTextField name = null;    private JTextField description = null;    private JPasswordField pwd = null;    private JPasswordField vpwd = null;    private JSlider expiration = null;    private boolean isCancel = false;    private JButton ok = null;    public GroupCreatePanel() {        super();        ui();    }    public String getName() {        return this.name.getText().trim();    }    public String getDescription() {        return this.description.getText().trim();    }    public int getExpirationDays() {        return this.expiration.getValue();    }        public String getPassword() {        String pwd = new String(this.pwd.getPassword()).trim();        return pwd.length() > 0 ? pwd : null;    }    public boolean isCancel() {        return this.isCancel;    }    private void ui() {        GridBagLayout gb = new GridBagLayout();        GridBagConstraints gbc = new GridBagConstraints();        setLayout(gb);        setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));        JLabel l = new JLabel(STRINGS.getString("label.group.name"));        gbc.gridx = 0;        gbc.gridy = 0;        gbc.gridwidth = 1;        gbc.gridheight = 1;        gbc.weightx = 1.0;        gbc.weighty = 1.0;        gbc.anchor = GridBagConstraints.FIRST_LINE_START;        gbc.fill = GridBagConstraints.BOTH;        gbc.insets = new Insets(3, 3, 3, 3);        gbc.ipadx = 0;        gbc.ipady = 0;        gb.setConstraints(l, gbc);        add(l);        this.name = new JTextField(15);                this.name.addKeyListener(new KeyAdapter() {            public void keyReleased(KeyEvent ke) {                ok.setEnabled(isValidInput());            }        });                gbc.gridx++;        gbc.gridwidth = GridBagConstraints.REMAINDER;        gb.setConstraints(this.name, gbc);        add(this.name);        l = new JLabel(STRINGS.getString("label.group.description"));        gbc.gridx = 0;        gbc.gridy++;        gbc.gridwidth = 1;        gbc.anchor = GridBagConstraints.LINE_START;        gb.setConstraints(l, gbc);        add(l);        this.description = new JTextField(15);        this.description.addKeyListener(new KeyAdapter() {            public void keyReleased(KeyEvent ke) {                ok.setEnabled(isValidInput());            }        });        gbc.gridx++;        gbc.gridwidth = GridBagConstraints.REMAINDER;                gb.setConstraints(this.description, gbc);        add(this.description);        l = new JLabel(STRINGS.getString("label.group.expiration"));        gbc.gridx = 0;        gbc.gridy++;        gbc.gridwidth = 1;        gbc.anchor = GridBagConstraints.LINE_START;        gb.setConstraints(l, gbc);        add(l);                this.expiration = new JSlider(JSlider.HORIZONTAL,            MINIMUM_EXPIRATION, MAXIMUM_EXPIRATION, INITIAL_EXPIRATION);                this.expiration.setMajorTickSpacing(INITIAL_EXPIRATION);        this.expiration.setMinorTickSpacing(MINIMUM_EXPIRATION);        this.expiration.setPaintTicks(true);        this.expiration.setPaintLabels(true);                gbc.gridx++;        gbc.gridwidth = GridBagConstraints.REMAINDER;                gb.setConstraints(this.expiration, gbc);                add(this.expiration);                l = new JLabel(STRINGS.getString("label.group.password"));        gbc.gridx = 0;        gbc.gridy++;        gbc.gridwidth = 1;        gbc.anchor = GridBagConstraints.LINE_START;        gb.setConstraints(l, gbc);        add(l);        this.pwd = new JPasswordField(15);        this.pwd.addKeyListener(new KeyAdapter() {            public void keyReleased(KeyEvent ke) {                ok.setEnabled(isValidInput());            }        });                gbc.gridx++;        gbc.gridwidth = GridBagConstraints.REMAINDER;        gb.setConstraints(this.pwd, gbc);        add(this.pwd);        l = new JLabel(STRINGS.getString("label.group.password.validate"));        gbc.gridx = 0;        gbc.gridy++;        gbc.gridwidth = 1;        gbc.anchor = GridBagConstraints.LINE_START;        gb.setConstraints(l, gbc);        add(l);        this.vpwd = new JPasswordField(15);        this.vpwd.addKeyListener(new KeyAdapter() {            public void keyReleased(KeyEvent ke) {                ok.setEnabled(isValidInput());            }        });                gbc.gridx++;        gbc.gridwidth = GridBagConstraints.REMAINDER;                gb.setConstraints(this.vpwd, gbc);        add(this.vpwd);                JPanel bp = new JPanel();                bp.setLayout(new GridLayout(1, 0));                this.ok = new JButton(new AbstractAction() {            public void actionPerformed(ActionEvent ae) {                if (isValidInput()) {                    exit();                }            }        });                this.ok.setText(STRINGS.getString("action.ok"));        this.ok.addKeyListener(new AbstractButtonKeyListener(this.ok) {            public void keyReleased(KeyEvent ke) {                getButton().getAction().actionPerformed(null);            }        });        this.ok.setEnabled(isValidInput());                bp.add(this.ok);        JButton b = new JButton(new AbstractAction() {            public void actionPerformed(ActionEvent ae) {                clear();            }        });        b.setText(STRINGS.getString("action.clear"));        b.addKeyListener(new AbstractButtonKeyListener(b) {            public void keyReleased(KeyEvent ke) {                getButton().getAction().actionPerformed(null);            }        });        bp.add(b);        b = new JButton(new AbstractAction() {            public void actionPerformed(ActionEvent ae) {                setCancel(true);                exit();            }        });        b.setText(STRINGS.getString("action.cancel"));        b.addKeyListener(new AbstractButtonKeyListener(b) {            public void keyReleased(KeyEvent ke) {                getButton().getAction().actionPerformed(null);            }        });        bp.add(b);        gbc.gridx = 0;        gbc.gridy++;        gbc.gridwidth = 2;        gbc.anchor = GridBagConstraints.LAST_LINE_END;        gbc.fill = GridBagConstraints.NONE;        gb.setConstraints(bp, gbc);        add(bp);//        getRootPane().setDefaultButton(this.ok);    }    private void setCancel(boolean isCancel) {        this.isCancel = isCancel;    }    private void clear() {        this.name.setText(null);        this.description.setText(null);        this.expiration.setValue(INITIAL_EXPIRATION);        this.pwd.setText(null);        this.vpwd.setText(null);        validate();    }    private void exit() {        getRootPane().getParent().setVisible(false);    }    private boolean isValidInput() {        String n = this.name.getText().trim();//        String d = this.description.getText().trim();        String p = String.valueOf(this.pwd.getPassword()).trim();        String vp = String.valueOf(this.vpwd.getPassword()).trim();        boolean isValid = n.length() > 0 &&            p.equals(vp);        if (! isValid) {            validate();        }        return isValid;    }}

⌨️ 快捷键说明

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