用户注册登陆查询界面

这里写图片描述

用户端

1、用户主界面设计
该界面有注册、登陆、查询三个按钮,分别调用各自的方法。界面图如下:这里写图片描述

此方法利用Jfram创建,非常简单,在三个按钮的方法处调用方法即可,下面是需要调用方法出的代码:


        JButton button = new JButton("注册");
        button.setBounds(60, 197, 67, 28);
        button.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                String username = textField.getText();
                String password = textField_1.getText();
                String message = MyMethods.newInstance().register(username, password);//调用Mythods类中的register方法
                System.out.println(message);//打印register返回的字符串
            }
        });
JButton button_1 = new JButton("登陆");
        button_1.setBounds(91, 156, 107, 28);
        button_1.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                String username = textField.getText();
                String password = textField_1.getText();
                String message = MyMethods.newInstance().login(username, password);//调用Mythods类中的login方法
                System.out.println(message);

            }
        });
        contentPane.add(button_1);

        JButton btnNewButton = new JButton("查询");
        btnNewButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                String message = MyMethods.newInstance().select();//调用Mythods类中的select方法
                System.out.println(message);
            }
        });
        btnNewButton.setBounds(156, 197, 67, 28);
        contentPane.add(btnNewButton);
    }

2、根据MVC编程思想,将三个方法写到一个类中,代码如下

public class MyMethods {
   
   private  MyMethods(){

   }
   private static MyMethods manager;
   //下面是设置单例
   public static synchronized MyMethods newInstance(){
       if(manager == null){
           manager = new MyMethods();
       }
    return manager;
       }
   /*
    下面是注册方法 */

   public String register(String username,String password){
       String url = "http://localhost:8080/MyServiceTest/MyTest";
        HttpClientBuilder  builder = HttpClientBuilder.create();
        builder.setConnectionTimeToLive(3000, TimeUnit.MILLISECONDS);
        HttpClient client = builder.build();
        HttpPost post = new HttpPost(url);
        JSONObject obj = new JSONObject();//利用json封装信息
        obj.put("type","注册");
        JSONObject data = new JSONObject();
        data.put("username", username);//将用户名和密码放进data中
        data.put(
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值