java代码转接qq 如何将java代码发给别人使用

java编程——让程序运行例如让QQ运行把QQ.exe加入到环境变量中,
然后写个批处理,里面写QQ.exe 就行了
怎么用java打开qqjava实现简单QQ登陆界面:
1.生成界面的java代码
package QQ2014;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class QQ2014 {
//创建登陆界面类
public void showLoginFrame(){
//创建船体对象
JFrame loginFrame=new JFrame();
//设置大小 , 位置,标题
loginFrame.setSize(300,200);
loginFrame.setTitle("QQ2014");
loginFrame.setLocationRelativeTo(null);
//创建流式分布对象
FlowLayout layout=new FlowLayout();
loginFrame.setLayout(layout);
//创建账户名 , 密码和输入框
JLabel user_name=new JLabel("账号:");
JLabel user_password=new JLabel("密码:");
JTextField field_name=new JTextField(20);
JPasswordField field_password=new JPasswordField(20);
//创建登陆,重置按钮
JButton button_reset=new JButton("重置");
JButton button_login=new JButton("登陆");
//设置窗体可见
loginFrame.setVisible(true);
//创建事件监听对象
ActionListener action_listener1=new ActionListener(){
public void actionPerformed(ActionEvent e){
String name=field_name.getText();
String password=field_password.getText();
if("zhaoxin".equals(name)"123".equals(password))
{
showIndexFrame();
loginFrame.setDefaultCloseOperation(3);
loginFrame.setVisible(false);
}
else{
System.out.println("密码错误,重新输入!");
}
}
};
ActionListener action_listener2=new ActionListener(){
public void actionPerformed(ActionEvent e){
field_name.setText("");
field_password.setText("");
}
};
//将文本输入框,按钮,事件监听对象添加
loginFrame.add(user_name);
loginFrame.add(field_name);
loginFrame.add(user_password);
loginFrame.add(field_password);
loginFrame.add(button_reset);
loginFrame.add(button_login);
button_reset.addActionListener(action_listener2);
button_login.addActionListener(action_listener1);
}
public void showIndexFrame(){
//创建窗体对象
JFrame indexFrame=new JFrame();
indexFrame.setSize(200,500);
indexFrame.setTitle("QQ好友列表");
indexFrame.setLocationRelativeTo(null);
//设置流式分布对象
FlowLayout layout=new FlowLayout(FlowLayout.CENTER,100,10);
indexFrame.setLayout(layout);
//创建好友按钮
for(int i=0;i10;i)
{
JButton button_friend=new JButton("friend" i);
//创建动作事件监听对象
ActionListener action_listener=new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
showChatFrame();
indexFrame.setVisible(false);
indexFrame.setDefaultCloseOperation(3);
}
};
button_friend.addActionListener(action_listener);
indexFrame.add(button_friend);
}
//设置窗体可见
indexFrame.setVisible(true);
}
public void showChatFrame(){
//创建窗体,大?。?位置,标题
JFrame chatFrame=new JFrame();
chatFrame.setSize(400,400);
chatFrame.setTitle("正在聊天中...");
chatFrame.setLocationRelativeTo(null);
//创建聊天记录 , 输入域
JTextArea area_input=new JTextArea(10,30);
JTextArea area_record=new JTextArea(5,30);
//创建流式分布对象
FlowLayout layout=new FlowLayout(FlowLayout.CENTER,0,10);
chatFrame.setLayout(layout);
//创建发送,关闭按扭
JButton button_send=new JButton("发送");
JButton button_close=new JButton("关闭");
//创建动作事件监听对象
ActionListener action_listener1=new ActionListener()
{
public void actionPerformed(ActionEvent e){
area_record.setText(area_record.getText() "\n" area_input.getText());
area_input.setText("");
}
};
ActionListener action_listener2=new ActionListener()
{
public void actionPerformed(ActionEvent e){
chatFrame.setVisible(false);
chatFrame.setDefaultCloseOperation(3);
}
};
//设置窗体可见
chatFrame.setVisible(true);
//添加按钮,事件监听对象
chatFrame.add(area_record);
chatFrame.add(area_input);
chatFrame.add(button_send);
chatFrame.add(button_close);
button_send.addActionListener(action_listener1);
button_close.addActionListener(action_listener2);
}
}
复制代码
2.java main方法调用
package QQ2014;
public class Test {
public static void main(String[] args){
QQ2014 qq=new QQ2014();
qq.showLoginFrame();
}
}
怎样有java socket实现发送接受表情类似QQ详细点代码哈 我正好在做一个类似qq的系统,不过还没完工,不过可以运行 , 现在只实现了登录,显示分组,列出好友,查看好友信息功册,看看代码吧
哎 类太多了,像什么vo类及实现类我就不发了 , 再说这些类没什么技术含量
如果有必要的话 你留下邮箱,我将两个工程和数据库代码发给你
服务器类:
package chat;
import impl.UserImpl;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;
import vo.Userinfo;
import dao.UserDao;
/**
* 服务器类,用于接受来自客户端的请求,本系统规定来自客户端每一次请求 所传过来的参数不少于两个 , 第一个用来标识此次请求将做什么操作,后面
* 的参数为客户端请求服务所需的必要参数
*
* @author 程胜
* @version 0.1
* @date 09-01-08
*
*/
public class ChatServer extends Thread {
// 定义最大连接数
private static final int MAXLINK = 50;
// 记录当前连接数
public static int linkNum = 0;
// 定义服务连接对象
private static ServerSocket ss;
public static void main(String[] args) throws Exception {
// 实例化服务类
ss = new ServerSocket(8001);
// 启用多线程:其实就是调用run方法,好像没必要另启线程,哎 写好了 就不改了
new ChatServer().start();
System.out.println("服务器已成功启动…………");
}
/*
* 覆写run方法
*/
public void run() {
Socket soc = null;
try {
// 循环监听客户端请求
while (true) {
while (true) {
// 如果连接数已满,则等待
if (linkNum = MAXLINK)
this.sleep(100);
else {
break;
}
}
// 监听请求
soc = ss.accept();
// 将连接加一
linkNum;
// 获得socket对象后调用处理类
new Operate(soc);
}
} catch (Exception e) {
System.out.println(e);
} finally {
if (soc != null) {
try {
soc.close();
ss.close();
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("服务器出现莫名故障 , 服务器退出!");
}
}
}
}
/**
* 操作类,用来处理来自客户端的请求
*
* @author Administrator
*
*/
class Operate {
// 接定义用于实别客户端发来的头号请求将做何操作的变量
private String operate;
/**
* 以下几行用于声明网络操作的必要变量
*/
private Socket soc = null;
private InputStream ips = null;
private OutputStream ops = null;
private ObjectOutputStream soops = null;
private ObjectInputStream soips = null;
/**
* 构造函数 , 在其中为以上定义的变量的赋值
*
* @param soc
*/
Operate(Socket soc) {
this.soc = soc;
try {
ips = soc.getInputStream();
ops = soc.getOutputStream();
soips = new ObjectInputStream(ips);
// 接收从客户端发来的头号请求,它用于实别此次请求的内容
operate = soips.readObject().toString();
} catch (Exception e) {
System.out.println(e);
}
// 调用实际操作方法
whichOpe();
}
/**
* 判断是哪个操作
*/
private void whichOpe() {
if ("login".equals(operate)) {
login();
} else {
if ("".equals(operate)) {
}
}
}
/**
* 连接数据库,进行登录验证
*/
private void login() {
UserDao userdao = new UserImpl();
Userinfo user = null;
try {
// 读取从客户端传过来的数据
user = (Userinfo) soips.readObject();
user = userdao.login(user);
soops = new ObjectOutputStream(ops);
// 将结果传给客户端
soops.writeObject(user);
soops.flush();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
soops.close();
soips.close();
soc.close();
// 将连接数减一
ChatServer.linkNum--;
} catch (IOException e) {
System.out.println(e);
}
}
}
}
客户端的两个类:
package client;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.TextField;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.net.Socket;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import vo.Userinfo;
/**
* 登录界面,继承自jframe类
*
* @author 程胜
* @version 0.1
* @date 09-01-08
* @address 学校寝室:综合楼424
*
*/
public class Login extends JFrame {
private final int TEXTSIZE = 10;// 定义文本长度的值
private JLabel lname = new JLabel("用户名");
private JLabel lpassword = new JLabel("密码");
private JLabel lhead = new JLabel("用户登录");
private JButton bok = new JButton("登录");
private JButton bcancel = new JButton("退出");
private JPanel pcenter = new JPanel();
private JPanel pname = new JPanel();
private JPanel ppwd = new JPanel();
private JPanel psouth = new JPanel();
private JPanel pnorth = new JPanel();
private TextField pwd = new TextField(TEXTSIZE);
private JTextField name = new JTextField(TEXTSIZE);
private GridLayout glayout = new GridLayout();
public Login() {
// 设置界面大小及位置
this.setBounds(300, 200, 320, 250);
this.setTitle("用户登录");
this.setResizable(false);
// 设置窗口的关闭方式
this.setDefaultCloseOperation(this.EXIT_ON_CLOSE);
// 布置窗口
this.frameLayout();
// 添加事件
this.addAction();
// 显示窗口
this.show();
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
new Login();
}
/**
* 布置容器
*/
private final void frameLayout() {
lhead.setFont(new Font("", Font.BOLD, 28));
glayout.setColumns(1);
glayout.setRows(2);
pcenter.setLayout(glayout);
pname.add(lname);
pname.add(name);
pwd.setEchoChar('*');
ppwd.add(lpassword);
ppwd.add(pwd);
pnorth.add(lhead);
psouth.add(bok);
psouth.add(bcancel);
pcenter.add(pname);
pcenter.add(ppwd);
this.add(pnorth, "North");
this.add(pcenter, "Center");
this.add(psouth, "South");
}
/**
* 添加事件
*/
private final void addAction() {
bok.addActionListener(new AddAction());
bcancel.addActionListener(new AddAction());
name.addActionListener(new AddAction());
pwd.addActionListener(new AddAction());
}
/**
* 此类为内置类 , 用于事件处理
*
* @author Administrator
*
*/
private class AddAction implements ActionListener {
public void actionPerformed(ActionEvent e) {
if (e.getSource() == bcancel) {
System.exit(0);
} else {
if ("".equals(name.getText()) || "".equals(pwd.getText())) {
JOptionPane.showMessageDialog(Login.this, "用户名和密码不能为空");
} else {
try {
// 判断输入的数据是否合法
Integer.parseInt(name.getText());
} catch (Exception ex) {
JOptionPane.showMessageDialog(Login.this, "请正确输入号码");
return;
}
new TcpLogin(name.getText(), pwd.getText()).check();
}
}
}
}
/**
* 登录验证类,内置类 将用户名和密码传到服务器做验证
*
* @author 程胜
* @version 0.1
* @date 09-01-08
*/
class TcpLogin {
private int name;
private String pwd = "";
/**
* 构造函数,初始化用户名和密码的值
*
* @param name
* @param pwd
*/
TcpLogin(String name, String pwd) {
this.name = Integer.parseInt(name);
this.pwd = pwd;
}
/**
* 连接服务器,验证用户信息方法
*/
void check() {
Window waitWin=new Window(Login.this);
// 获得界面
Login login = Login.this;
Userinfo user = new Userinfo();
user.setUserId(name);
user.setPassword(pwd);
Socket soc = null;
InputStream ips = null;
OutputStream ops = null;
ObjectInputStream coips = null;
ObjectOutputStream coops = null;
try {
soc = new Socket("127.0.0.1", 8001);
ips = soc.getInputStream();
ops = soc.getOutputStream();
coops = new ObjectOutputStream(ops);
coops.writeObject("login");
coops.writeObject(user);
coops.flush();
ObjectInputStream oips = new ObjectInputStream(ips);
user = null;
user = (Userinfo) oips.readObject();
if (user != null){
new XiHa(user);
login.dispose();
}
else {
JOptionPane.showMessageDialog(login, "用户名和密码错误");
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
ips.close();
ops.close();
soc.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
package client;
import java.awt.GridLayout;
import java.awt.TextArea;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.JTree;
import javax.swing.Timer;
import javax.swing.tree.DefaultMutableTreeNode;
import vo.Groupinfo;
import vo.Relationinfo;
import vo.Userinfo;
/**
* 此类为本程序客户端的主界面,刚想了好会儿决定取名叫’嘻哈‘ 意为’嘻嘻哈哈‘
*
* @author 程胜
* @version 0.1
* @date 09-01-08
* @address 学校寝室:综合楼424
*/
public class XiHa extends JFrame {
// 好友信息
static ListUserinfo friends = new ArrayListUserinfo();
// 用户信息
private Userinfo user = null;
private JPanel ptree = new JPanel();
private JPanel psouth = new JPanel();
private JButton bfind = new JButton("查找");
private JButton bsystem = new JButton("系统设置");
/**
* 构造函数,设置界面基本参数
*/
public XiHa(Userinfo user) {
this.user = user;
this.setTitle("嘻嘻哈哈");
this.setDefaultCloseOperation(this.EXIT_ON_CLOSE);
this.setBounds(800, 100, 200, 500);
this.setResizable(false);
// 布置界面
initFrame();
// this.pack();
this.setVisible(true);
}
/**
* 用于界面布置
*/
private void initFrame() {
ptree.add(new JScrollPane(new CreateTree(user).createNode()));
psouth.add(bsystem);
psouth.add(bfind);
this.add(ptree, "Center");
this.add(psouth, "South");
}
}
/**
* 本类用于创建以用户信息为节点的树
*
* @author 程胜
* @version 0.1
* @date 09-01-08
* @address 学校寝室:综合楼424
*
*/
class CreateTree {
JTree tree=null;
private Userinfo user = null;
CreateTree(Userinfo user) {
this.user = user;
}
/**
* 用服务器传回的数据创建一棵树
*
* @return
*/
JTree createNode() {
//根结点
DefaultMutableTreeNode all = new DefaultMutableTreeNode("所有好友");
SetGroupinfo groups = user.getGroupinfos();
SetRelationinfo relations = user.getRelationinfosForUserId();
IteratorGroupinfo ig = groups.iterator();
IteratorRelationinfo ir = null;
Groupinfo group = null;
Relationinfo relation = null;
DefaultMutableTreeNode friendNode = null;
Userinfo friend = null;
while (ig.hasNext()) {
group = ig.next();
friendNode = new DefaultMutableTreeNode(group.getGroupName());
ir = relations.iterator();
while (ir.hasNext()) {
relation = ir.next();
if (relation.getResideGroupId() == group.getGroupId()) {
friend = relation.getFriend();
friendNode.add(new DefaultMutableTreeNode(friend
.getPetname()
"("relation.getFriendId()")"));
XiHa.friends.add(friend);
}
}
all.add(friendNode);
// rootTree.add(friendNode);
}
tree=new JTree(all);
tree.addMouseListener(new TreeListener());
return tree;
}
/**
* 此类为创建树的内置类,用于对结点的事件处理
*
* @author 程胜
* @version 0.1
* @date 09-01-09
* @address 学校寝室:综合楼424
*/
class TreeListener extends MouseAdapter{
private JFrame friendInfo=null;
private String nodeInfo="";
//用于区分单击双击
Timer mouseTimer =null;
/*
* 覆写mouseAdapter中的mouseClicked方法 , 鼠标点击时触发
*/
public void mouseClicked(MouseEvent e){
//返回选定的结点
DefaultMutableTreeNode treeNode =null;
treeNode =(DefaultMutableTreeNode)CreateTree.this.tree.getLastSelectedPathComponent();
if(treeNode==null)return;
//如果它不是叶子结点就返回
if(!treeNode.isLeaf())return;
nodeInfo=treeNode.toString();
if(e.getClickCount()==1){
mouseTimer = new javax.swing.Timer(350, new ActionListener() {
public void actionPerformed(ActionEvent evt) {
//布置信息界面
initFriendInfo();
mouseTimer.stop();
}
});
mouseTimer.restart();
}else{
if(e.getClickCount()==2mouseTimer.isRunning()){
mouseTimer.stop();
//实例化聊天界面
new WinChat();
}
}
}
/**
* 布置friendInfo的界面
*/
private void initFriendInfo() {
friendInfo=new JFrame();
friendInfo.setSize(300,120);
friendInfo.setDefaultCloseOperation(friendInfo.DISPOSE_ON_CLOSE);
friendInfo.setLocationRelativeTo(null);
friendInfoContent(this.treat());
friendInfo.setVisible(true);
}
/**
* 设置窗口中的具体内容
* @param friendId
* @return
*/
private void friendInfoContent(int friendId) {
friendInfo.dispose();
Userinfo friend=this.findFriend(friendId);
JPanel pmain=new JPanel();
pmain.setLayout(new GridLayout(3,1));
JPanel panel1=new JPanel();
panel1.add(new JLabel("嘻哈号:" friend.getUserId() " " "昵称:" friend.getPetname()));
JPanel panel2=new JPanel();
panel2.add(new JLabel("姓名:" (friend.getName()==null?"":friend.getName()) " " "年龄:" friend.getAge() " " "性别:" friend.getSex()));
JPanel panel3=new JPanel();
panel3.add(new JLabel("个性签名: " (friend.getAutograph()==null?"":friend.getAutograph())));
pmain.add(panel1);pmain.add(panel2);pmain.add(panel3);
friendInfo.add(pmain);
}
/**
* 此方法用于获得好友的id号 从节点上的文本中获取
* @return 好友id
*/
private int treat(){
int len=nodeInfo.getBytes().length;
int friendId=Integer.parseInt(new String(nodeInfo.getBytes(),len-5,4));
return friendId;
}
/**
* 此方法用于按id查找好友信息
* @param friendId
* @return 好友信息
*/
private Userinfo findFriend(int friendId){
Userinfo friend=null;
Iterator friends=XiHa.friends.iterator();
while(friends.hasNext()){
Userinfo ifriend=(Userinfo)friends.next();
if(ifriend.getUserId()==friendId){
friend=ifriend;
break;
}
}
return friend;
}
}
}
/**
* 本类聊天窗口类,还不知道该怎么写,现在有点茫然,刚跟网友交流了一下
* 觉得前面写的通信代码很不规范,应该重新写,哎 先把界面写好再说
*
* 一会儿就要回去过年了,可能就没那么时间写这个系统了
* @author 程胜
* @version 0.1
* @date 09-01-11
* @address 学校寝室:综合楼424
*
*/
class WinChat extends JFrame{
private JPanel pmain=new JPanel();
private JPanel pcether=new JPanel();
private JPanel psouth=new JPanel();
//private JTextArea precod=new JTextArea(JTextArea.);
}
用JAVA怎么写QQ用java是可以写出qq的,只不过用java开发c/s的软件不是java特长的,你要是真的想写,就写着练练手吧,最起码可以巩固java se上的知识 。
具体怎么写,给你个大概的思路吧,因为我没办法在这个有限的输入框内把所有的代码写完 。
【1】先写出qq的简单界面
【2】给每个按钮添加监听
【3】按钮事件(方法)定义
【4】连接网络(socket)
【5】测试
【5】其他功能添加
【6】测试
【java代码转接qq 如何将java代码发给别人使用】java代码转接qq的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于如何将java代码发给别人使用、java代码转接qq的信息别忘了在本站进行查找喔 。

    推荐阅读