| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 749 人关注过本帖
标题:请教一个简单的数据交互问题
只看楼主 加入收藏
chump345
Rank: 1
来 自:家里蹲大学
等 级:新手上路
帖 子:108
专家分:5
注 册:2007-11-24
结帖率:93.33%
收藏
已结贴  问题点数:20 回复次数:4 
请教一个简单的数据交互问题
我想制作一个注册邮箱的工具~
页面用GUI来做~
我的想法是在swing界面中~  把注册邮箱需要的信息收集起来~
然后发送给服务器端~
但是不知道如何发送~
另外还有个接收服务器端传递过来验证码的问题也不知道该怎么解决~
能不能给我个思路~
让我顺着路子走下去
搜索更多相关主题的帖子: 交互 数据 
2010-05-21 19:26
HeiN
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:53
专家分:193
注 册:2010-3-30
收藏
得分:10 
GUI没有用过,在网上找GUI:简称 图形用户接口,以前做验证码都是根据输入 的和 生成的验证码(放作用域中) 做对比,
2010-05-21 22:24
baifenghan
Rank: 8Rank: 8
等 级:贵宾
威 望:10
帖 子:258
专家分:952
注 册:2006-3-17
收藏
得分:10 
基本上有一些思路:
1.使用socket直接通信;
2.使用进一步的RMI。
3.使用cobar。
我先写一个soket的吧,比较好搞点。

关于验证码的话我记得我在J2EE板块回过一个帖子。
2010-05-22 00:33
baifenghan
Rank: 8Rank: 8
等 级:贵宾
威 望:10
帖 子:258
专家分:952
注 册:2006-3-17
收藏
得分:0 
我写了一个简单的,保存到一个xml文件中,你可以根据需要根据上面的回帖改动。
GUI界面程序:
package client;

import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Point;
import java.awt.Toolkit;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;

import bean.EmailInfo;

public class ClientFrame extends JFrame {
   
    private JLabel emailNameLbl;
    private JLabel passwordLbl;
    private JLabel rePasswordLbl;
    private JLabel serverLbl;
    private JTextField emailNameTxt;
    private JPasswordField passwordTxt;
    private JPasswordField rePasswordTxt;
    private JButton submitBtn;
    private JButton cancleBtn;
    private JButton exitBtn;
   
    public ClientFrame() {
        super("邮箱注册");
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        initGUI();
        addListeners();
        pack();
        centerWindow(this);
    }
   
    private void initGUI() {

        JPanel namePnl = new JPanel();
        namePnl.setLayout(new FlowLayout(FlowLayout.LEFT));
        emailNameLbl = new JLabel("邮箱名 :    ");
        emailNameTxt = new JTextField(20);
        serverLbl = new JLabel("@);
        namePnl.add(emailNameLbl);
        namePnl.add(emailNameTxt);
        namePnl.add(serverLbl);
        
        JPanel passwordPnl = new JPanel();
        passwordPnl.setLayout(new FlowLayout(FlowLayout.LEFT));
        passwordLbl = new JLabel("密码:         ");
        passwordTxt = new JPasswordField(10);
        passwordPnl.add(passwordLbl);
        passwordPnl.add(passwordTxt);
        
        JPanel rePasswordPnl = new JPanel();
        rePasswordPnl.setLayout(new FlowLayout(FlowLayout.LEFT));
        rePasswordLbl = new JLabel("密码确认:");
        rePasswordTxt = new JPasswordField(10);
        rePasswordPnl.add(rePasswordLbl);
        rePasswordPnl.add(rePasswordTxt);
        
        JPanel mainContentPnl = new JPanel();
        mainContentPnl.setLayout(new BoxLayout(mainContentPnl, BoxLayout.Y_AXIS ));
        mainContentPnl.add(namePnl);
        mainContentPnl.add(passwordPnl);
        mainContentPnl.add(rePasswordPnl);
        
        JPanel buttonPnl = new JPanel();
        buttonPnl.setLayout(new FlowLayout(FlowLayout.RIGHT));
        submitBtn = new JButton();
        cancleBtn = new JButton("取消");
        exitBtn = new JButton("退出");
        buttonPnl.add(submitBtn);
        buttonPnl.add(cancleBtn);
        buttonPnl.add(exitBtn);
        
        Container c = getContentPane();
        c.add(mainContentPnl, BorderLayout.CENTER);
        c.add(buttonPnl, BorderLayout.PAGE_END);
        
    }
   
    private void addListeners() {
        submitBtn.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                EmailInfo info = new EmailInfo();
                info.setEmailName(emailNameTxt.getText() + "test@.com");
                info.setPassword(new String(passwordTxt.getPassword()));
                info.setRePassword(new String(rePasswordTxt.getPassword()));
                MyAction action = new MyAction(info);
                action.actionPerformed(e);
                if (action.getIsSaveSuc())
                {
                    emailNameTxt.setText("");
                    passwordTxt.setText("");
                    rePasswordTxt.setText("");
                }
            }
        });
        submitBtn.setText("提交");
        cancleBtn.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent arg0) {
                emailNameTxt.setText("");
                passwordTxt.setText("");
                rePasswordTxt.setText("");
            }
        });
        exitBtn.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent arg0) {
                System.exit(0);
            }
        });

    }
   
    private void centerWindow(Window w)
    {
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        Dimension windowSize = w.getSize();
        int x = (screenSize.width - windowSize.width) / 2;
        int y = (screenSize.height - windowSize.height) / 2;
        w.setLocation(new Point(x, y));
    }
   
    public static void main(String[] args) {
        new ClientFrame().setVisible(true);
    }

}
保存邮箱信息的bean:
package bean;

public class EmailInfo {

    private String emailName;
    private String password;
    private String rePassword;

    public EmailInfo() {
    }

    public EmailInfo(String emailName, String password, String rePassword) {
        this.emailName = emailName;
        this.password = password;
        this.rePassword = rePassword;
    }

    public String getEmailName() {
        return emailName;
    }

    public void setEmailName(String emailName) {
        this.emailName = emailName;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getRePassword() {
        return rePassword;
    }

    public void setRePassword(String rePassword) {
        this.rePassword = rePassword;
    }

}

校验和保存的逻辑:
package client;

import java.awt.event.ActionEvent;
import java.beans.XMLEncoder;
import
import
import
import
import

import javax.swing.AbstractAction;
import javax.swing.JOptionPane;

import bean.EmailInfo;

public class MyAction extends AbstractAction {

    private EmailInfo info;
    private String path = "c:/info.xml";
    private boolean isSaveSuc = false;
   
    public MyAction(EmailInfo info) {
        this.info = info;
    }
    @Override
    public void actionPerformed(ActionEvent event) {
        if (validateInfo())
        {
            saveAsXml();
            JOptionPane.showMessageDialog(null, "保存成功。");
            isSaveSuc = true;
        }

    }
   
    public boolean getIsSaveSuc()
    {
        return isSaveSuc;
    }
   
    private boolean validateInfo()
    {
        String name = info.getEmailName();
        if (name == null || name.trim().length() == 0)
        {
            JOptionPane.showMessageDialog(null, "邮箱名不能为空");
            return false;
        }
        String password = info.getPassword();
        String rePassword = info.getRePassword();
        if (password == null || password.trim().length() == 0)
        {
            JOptionPane.showMessageDialog(null, "密码不能为空");
            return false;
        }
        else if (!password.equals(rePassword))
        {
            JOptionPane.showMessageDialog(null, "两次输入密码不同,请重新输入。");
            return false;
        }
        
        return true;
        
    }
   
    /**
     * 将一个JavaBean存储为一个XML格式的文件
     */
    private void saveAsXml()
    {
        try {
            //添加参数true,每次只是追加在文件的末尾
            OutputStream out = new FileOutputStream(path, true);
            XMLEncoder e = new XMLEncoder(new BufferedOutputStream(out));
            e.writeObject(info);
            e.close();
            out.close();
        } catch (FileNotFoundException e1) {
            e1.printStackTrace();
            JOptionPane.showMessageDialog(null, "保存失败.");
        } catch (IOException e) {
            e.printStackTrace();
            JOptionPane.showMessageDialog(null, "保存失败.");
        }
        
    }

}
运行效果:
图片附件: 游客没有浏览图片的权限,请 登录注册



[ 本帖最后由 baifenghan 于 2010-5-22 02:07 编辑 ]
2010-05-22 02:06
chump345
Rank: 1
来 自:家里蹲大学
等 级:新手上路
帖 子:108
专家分:5
注 册:2007-11-24
收藏
得分:0 
谢谢你的回贴·  我会认真看的·

凤凰涅磐,浴火重生!

2010-05-22 18:15
快速回复:请教一个简单的数据交互问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.018589 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved