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

📄 joinworkspacedialog.java

📁 基于jxta的局域网P2P文件共享,可以实现局域网中的文件p2p共享,实现文件快速传输及交流
💻 JAVA
字号:
package connex.app.wsUI;

import java.awt.*;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import java.awt.event.WindowEvent;
import java.awt.event.WindowAdapter;
import connex.core.WS.*;
import java.awt.event.KeyEvent;
import java.awt.event.KeyAdapter;

public class JoinWorkspaceDialog extends JDialog {
    BorderLayout borderLayout1 = new BorderLayout();
    JPanel jPanel1 = new JPanel();
    JTextField logname = new JTextField();
    JLabel jLabel1 = new JLabel();
    JPasswordField pass = new JPasswordField();
    JLabel jLabel2 = new JLabel();
    JPanel jPanel2 = new JPanel();
    JButton Join = new JButton();
    JButton cancel = new JButton();
    Workspace toJoin;
    boolean canceled = false;
    JLabel status = new JLabel();
    public JoinWorkspaceDialog(Frame frame, Workspace ws) {
        super(frame, true);
        this.setTitle(ws.getName());
        this.toJoin = ws;
        try {
            jbInit();
        } catch (Exception exception) {
            exception.printStackTrace();
        }

    }

    public JoinWorkspaceDialog() {
        try {
            jbInit();
        } catch (Exception exception) {
            exception.printStackTrace();
        }
    }

    private void jbInit() throws Exception {
        this.setSize(334, 189);
        getContentPane().setLayout(borderLayout1);
        jPanel1.setLayout(null);
        logname.setBounds(new Rectangle(129, 20, 176, 24));
        if (toJoin.getName().equals("NetPeerGroup")) {

            logname.setText(toJoin.getPeerAdv().getName());
        }

        jLabel1.setText("* Login name");
        jLabel1.setBounds(new Rectangle(18, 20, 113, 22));
        pass.setBounds(new Rectangle(129, 57, 176, 24));
        pass.addKeyListener(new JoinWorkspaceDialog_pass_keyAdapter(this));
        jLabel2.setText("* Password");
        jLabel2.setBounds(new Rectangle(18, 54, 113, 22));
        Join.setText("Join");
        Join.addActionListener(new JoinWorkspaceDialog_actionAdapter(this));
        cancel.setText("Cancel");
        cancel.addActionListener(new JoinWorkspaceDialog_actionAdapter(this));
        jPanel2.setBorder(BorderFactory.createEtchedBorder());
        jPanel1.setBorder(BorderFactory.createEtchedBorder());
        this.addWindowListener(new JoinWorkspaceDialog_this_windowAdapter(this));
        status.setPreferredSize(new Dimension(0, 20));
        status.setText("");
        jPanel1.add(logname);
        jPanel1.add(jLabel1);
        jPanel1.add(pass);
        jPanel1.add(jLabel2);
        jPanel2.add(Join);
        jPanel2.add(cancel);
        this.getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER);

        this.getContentPane().add(jPanel2, java.awt.BorderLayout.SOUTH);
        this.getContentPane().add(status, java.awt.BorderLayout.NORTH);

        centerFrame();
        this.setAlwaysOnTop(true);
    }

    private void centerFrame() {

        // Center the window
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        Dimension frameSize = this.getSize();
        if (frameSize.height > screenSize.height) {
            frameSize.height = screenSize.height;
        }
        if (frameSize.width > screenSize.width) {
            frameSize.width = screenSize.width;
        }
        this.setLocation((screenSize.width - frameSize.width) / 2,
                         (screenSize.height - frameSize.height) / 2);
        setVisible(true);
    }

    public boolean isCanceled() {
        return this.canceled;
    }

    public String getLoginName() {
        return logname.getText();
    }

    public String getPass() {
        return new String(pass.getPassword());
    }

    public void Join_actionPerformed(ActionEvent e) {

        if ((getLoginName().trim().equals("")) || (getPass().trim().equals(""))) {
            status.setText("please enter Workspace login and password !!");
            return;
        }
        boolean b = true;
        if (!WorkspaceUtil.isAuthenticated(toJoin)) {

            System.err.println("joining :" + toJoin.getName());
            if (!toJoin.getName().equals("NetPeerGroup")) {
                b = WorkspaceUtil.joinWorkspace(toJoin,
                                                getLoginName(),
                                                getPass());
            } else {

                b = Boot.login(getLoginName(), getPass());
            }
        }

        if (WorkspaceUtil.isAuthenticated(toJoin)) {
            System.out.println(toJoin.getName() + ": has been joined ");
            WorkspaceManager.getInstance().setCurrentWorkspace(toJoin);
        }
        if (!b) {
            status.setText("wrong ID or password !! please try again");

            return;
        }
        this.dispose();

    }

    public void cancel_actionPerformed(ActionEvent e) {
        this.canceled = true;
        this.dispose();

    }

    public void this_windowClosing(WindowEvent e) {
        this.canceled = true;
        this.dispose();
    }

    public void pass_keyTyped(KeyEvent e) {
        if (e.getKeyChar() == '\n') {
            Join_actionPerformed(null);
        }

    }


}


class JoinWorkspaceDialog_pass_keyAdapter extends KeyAdapter {
    private JoinWorkspaceDialog adaptee;
    JoinWorkspaceDialog_pass_keyAdapter(JoinWorkspaceDialog adaptee) {
        this.adaptee = adaptee; }

    public void keyTyped(KeyEvent e) {
        adaptee.pass_keyTyped(e); }}


class JoinWorkspaceDialog_this_windowAdapter extends WindowAdapter {
    private JoinWorkspaceDialog adaptee;
    JoinWorkspaceDialog_this_windowAdapter(JoinWorkspaceDialog adaptee) {
        this.adaptee = adaptee;
    }

    public void windowClosing(WindowEvent e) {
        adaptee.this_windowClosing(e);
    }
}


class JoinWorkspaceDialog_actionAdapter implements ActionListener {
    private JoinWorkspaceDialog adaptee;
    JoinWorkspaceDialog_actionAdapter(JoinWorkspaceDialog adaptee) {
        this.adaptee = adaptee;
    }


    public void actionPerformed(ActionEvent e) {
        if (e.getActionCommand().equals("Cancel")) {
            adaptee.cancel_actionPerformed(e);
        }
        if (e.getActionCommand().equals("Join")) {
            adaptee.Join_actionPerformed(e);
        }

    }
}

⌨️ 快捷键说明

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