![]() |
#2
HeiN2010-05-21 22:24
|

页面用GUI来做~
我的想法是在swing界面中~ 把注册邮箱需要的信息收集起来~
然后发送给服务器端~
但是不知道如何发送~
另外还有个接收服务器端传递过来验证码的问题也不知道该怎么解决~
能不能给我个思路~
让我顺着路子走下去
![]() |
#2
HeiN2010-05-21 22:24
GUI没有用过,在网上找GUI:简称 图形用户接口,以前做验证码都是根据输入 的和 生成的验证码(放作用域中) 做对比,
|
![]() |
#3
baifenghan2010-05-22 00:33
基本上有一些思路:
1.使用socket直接通信; 2.使用进一步的RMI。 3.使用cobar。 我先写一个soket的吧,比较好搞点。 关于验证码的话我记得我在J2EE板块回过一个帖子。 |
![]() |
#4
baifenghan2010-05-22 02:06
我写了一个简单的,保存到一个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 编辑 ] |
![]() |
#5
chump3452010-05-22 18:15
谢谢你的回贴· 我会认真看的·
|