8:30-9:00 学习打卡
9:30-12:00 写qq项目
15:00-17:00 写qq项目
1.注册类
写好swing注册界面,图片,名称,账号,密码格式正确上传到服务器,服务器申请成功返回。
package qqc.view;
import qqc.massage.Massage;
import qqc.mode.qqlogin;
import javax.swing.*;
import javax.swing.filechooser.FileNameExtensionFilter;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;
public class qqzhu extends JFrame implements ActionListener {
JPanel jp;
JPanel jp1,jp2,jp3;
JLabel jl1,jl2,jl3,jp4,jp5,jp6,JL,jl7;
JTextField jt1,jt2,jt3;
JButton jb1,jb2;
JFileChooser jfc;
String ss;
String tupian;
qqzhu() throws IOException {
jp4=new JLabel("请输入1-10数字",SwingConstants.CENTER);
jp5=new JLabel("请输入1-10数字或字母",SwingConstants.CENTER);
jp6=new JLabel("任意输入20以内",SwingConstants.CENTER);
jp2=new JPanel();
jb1=new JButton("提交");
jp1=new JPanel(new GridLayout(3,3,0,0));
jl1=new JLabel("qq账号",SwingConstants.CENTER);
jl2=new JLabel("密码",SwingConstants.CENTER);
jl3=new JLabel("昵称",SwingConstants.CENTER);
jt1=new JTextField();
jt2=new JTextField();
jt3=new JTextField();
jp1.add(jl1);
jp1.add(jt1);
jp1.add(jp4);
jp1.add(jl2);
jp1.add(jt2);
jp1.add(jp5);
jp1.add(jl3);
jp1.add(jt3);
jp2.add(jb1);
jp1.add(jp6);
jp3=new JPanel();
jb2=new JButton("浏览");
jb1.addActionListener(this);
tupian="空白.jpg";
jb2.addActionListener(this);
File fl=new File("src\\qqc\\view\\空白.jpg");
ImageIcon imge=new ImageIcon(fl.getCanonicalPath());
Image img=imge.getImage();
img=img.getScaledInstance(100,100,Image.SCALE_DEFAULT);
imge.setImage(img);
JL=new JLabel(imge);
jl7=new JLabel("背景图片");
jp3.add(jl7,SwingConstants.CENTER);
jp3.add(JL);
jp3.add(jb2);
jp=new JPanel();
this.setSize(370,260);
jp.add(jp3,BorderLayout.NORTH);
jp.add(jp1,BorderLayout.CENTER);
jp.add(jp2,BorderLayout.SOUTH);
jp.setBorder(BorderFactory.createLineBorder(Color.BLUE));
this.add(jp,BorderLayout.CENTER);
this.setVisible(true);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public static void main(String[] args) throws IOException {
new qqzhu();
}
@Override
public void actionPerformed(ActionEvent e) {//注册提交的按钮
if(e.getSource()==jb1){
String s=jt1.getText().trim();
if(s.length()>10||s.equals("")){
JOptionPane.showConfirmDialog(null,"账号输入不正确","提示",JOptionPane.WARNING_MESSAGE);
return;
}
s=jt2.getText().trim();
if(s.length()>10||s.equals("")){
JOptionPane.showConfirmDialog(null,"密码输入不正确","提示",JOptionPane.WARNING_MESSAGE);
return;
}
s=jt3.getText().trim();
if(s.length()>20||s.equals("")) {
JOptionPane.showConfirmDialog(null,"昵称不正确","提示",JOptionPane.WARNING_MESSAGE);
return;
}
Massage m=new Massage();
m.setMyname(jt3.getText().trim());
m.setMyid(jt1.getText().trim());
m.setUserpassward(jt2.getText().trim());
qqlogin ql=new qqlogin();
ql.inlt(m);
}else if(e.getSource()==jb2){
jfc=new JFileChooser();
jfc.setFileSelectionMode(JFileChooser.FILES_ONLY);
FileNameExtensionFilter filte=new FileNameExtensionFilter("图片","jpg");
jfc.setDialogTitle("请选择图片");
if(JFileChooser.APPROVE_OPTION==jfc.showOpenDialog(null)){
ss=jfc.getSelectedFile().getAbsolutePath();
System.out.println(ss);
}
}
}
}