当前位置:我的异常网» J2SE » 新人 怎么应用java初级知识编写一个类QQ软件
新人 怎么应用java初级知识编写一个类QQ软件
www.myexceptions.net 网友分享于:2014-02-21 浏览:1次
新人求助 如何应用java初级知识编写一个类QQ软件
功能包括登录注册
私聊群聊等
应用数组 集合 io JDBC等知识
客户端的文件夹中存放5个包
userbean-》人员实体类
action—》主函数
view-》GUI 登录界面
server-》登录方法
dao-》和数据库有关的方法
求修改gui 添加登录注册两个选项
package action;
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.FlowLayout;
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
public class QQ{
private JFrame frame= new JFrame("QQ201X登录");
private Container c= frame.getContentPane();
private JTextField username=new JTextField();
private JPasswordField password=new JPasswordField();
private JButton ok=new JButton("确定");
private JButton no=new JButton("取消");
public QQ(){
frame.setSize(300,200);
c.setLayout(new BorderLayout());
initFrame();
frame.setVisible(true);
}
public void initFrame() {
JPanel titlePanel=new JPanel();
titlePanel.setLayout(new FlowLayout());
titlePanel.add(new JLabel("欢迎登录"));
c.add(titlePanel,"North");
JPanel fieldPanel=new JPanel();
fieldPanel.setLayout(null);
JLabel l1=new JLabel("用户名");
l1.setBounds(50,20,50,20);
JLabel l2=new JLabel("密码");
l2.setBounds(50,60,50,20);
fieldPanel.add(l1);
fieldPanel.add(l2);
username.setBounds(110,20,120,20);
password.setBounds(110,60,120,20);
fieldPanel.add(username);
fieldPanel.add(password);
c.add(fieldPanel,"Center");
JPanel buttonPannel=new JPanel();
buttonPannel.setLayout(new FlowLayout());
buttonPannel.add(ok);
buttonPannel.add(no);
c.add(buttonPannel,"South");
}
public static void main(String[] args) {
new QQ();
}
}
附本人写的登录注册方法
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Manage {
Scanner input = new Scanner(System.in);
List list = new ArrayList();
public void Menu(){
System.out.println("1.登录,2.注册");
System.out.println("请输入选项!");
String num = input.next();
switch (Integer.valueOf(num)) {
case 1:
login();
break;
case 2:
register();
break;
default:
System.out.println("输入错误,程序退出");
System.exit(0);
break;
}
}
private void login(){
System.out.println("请输入用户名:");
String name = input.next();
User isOk = isRegister(name);
if (null == isOk) {
System.out.println("用户名不存在!");
login();
return;
}
System.out.println("请输入密码:");
String pwd = input.next();
if (!pwd.equals(isOk.getPwd())) {
System.out.println("密码错误!");
login();
}else {
System.out.println("登录成功 !");
Menu();
}
}
private void register(){
System.out.println("请输入用户名:");
String name = input.next();
User isOk = isRegister(name);
if (null != isOk) {
System.out.println("用户名已存在!");
register();
return;
}
System.out.println("请输入密码:");
String pwd = input.next();
User user = new User(name,pwd);
list.add(user);
System.out.println("注册成功!");
Menu();
}
private User isRegister(String name){
User flag = null;
for (User user : list) {
if (name.toLowerCase().equals(user.getUserName().toLowerCase())) {
flag = user ;
break;
}
}
return flag;
}
}
public class Test {
public static void main(String[] args) {
Manage manage = new Manage();
manage.Menu();
}
}
public class User {
private String userName;
private String pwd;
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getPwd() {
return pwd;
}
public void setPwd(String pwd) {
this.pwd = pwd;
}
public User(String userName, String pwd) {
super();
this.userName = userName;
this.pwd = pwd;
}
public User() {
super();
}
}
io代码
package action;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.Socket;
import java.util.Set;
public class ServerRec extends Thread{
文章评论