资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

java添加好友代码,java实现添加好友功能

用java实现添加陌生人到好友列表中?急急急啊!

这是一个我自己写的类,希望能给你帮助:

成都创新互联是专业的梁平网站建设公司,梁平接单;提供成都网站制作、网站设计、外贸网站建设,网页设计,网站设计,建网站,PHP网站建设等专业做网站服务;采用PHP框架,可快速的进行梁平网站开发网页制作和功能扩展;专业做搜索引擎喜爱的网站,专业的做网站团队,希望更多企业前来合作!

类名:AddeleteDialog.java

public class AddeleteDialog extends Dialog implements View.OnClickListener

{

Context context;

View alertDialogView;

ListView noList, yesList;

ArrayListString noArray, exportArray;

ArrayAdapterString noAdapter, yesAdapter;

ArrayListHashMapString, String array_controlList;

ArrayListString yesArray = new ArrayListString();

/**

* 两侧ListView可添加删除的自定义Dialog

* @param theme

*            Style中自定义的dialog样式

* @param noArray

*            界面左侧显示的尚未添加的项目列表,调用此类后 该传入的Array内容 不会改变

* @param exportArray

*            调用此类后会修改 该传入的Array内容 为右侧已添加的项目列表

*/

@SuppressLint("InflateParams")

@SuppressWarnings({ "deprecation", "unchecked" })

public AddeleteDialog(Context context, int theme, ArrayListString noArray, ArrayListString exportArray)

{

super(context, theme);

LayoutInflater inflater = this.getLayoutInflater();

alertDialogView = inflater.inflate(R.layout.style_dialog_control, null);

this.setContentView(alertDialogView);

this.context = context;

this.exportArray = exportArray;

this.noArray = (ArrayListString) noArray.clone();

widgetInit();

WindowManager.LayoutParams lp = this.getWindow().getAttributes();

WindowManager winManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);

lp.height = winManager.getDefaultDisplay().getHeight() * 2 / 3;

lp.width = winManager.getDefaultDisplay().getWidth() - 30;

this.getWindow().setAttributes(lp);

}

private void widgetInit()

{

((Button) alertDialogView.findViewById(R.id.cancel)).setOnClickListener(this);

((Button) alertDialogView.findViewById(R.id.enter)).setOnClickListener(this);

noList = (ListView) alertDialogView.findViewById(R.id.device_no);

noAdapter = new ArrayAdapterString(context, R.layout.style_listview_control, noArray);

noList.setAdapter(noAdapter);

yesList = (ListView) alertDialogView.findViewById(R.id.device_yes);

yesAdapter = new ArrayAdapterString(context, R.layout.style_listview_control, yesArray);

yesList.setAdapter(yesAdapter);

noList.setOnItemClickListener(new OnItemClickListener()

{

@Override

public void onItemClick(AdapterView? parent, View view, int position, long id)

{

String check = ((TextView) view).getText().toString();

noArray.remove(check);

yesArray.add(check);

noAdapter.notifyDataSetChanged();

yesAdapter.notifyDataSetChanged();

}

});

yesList.setOnItemClickListener(new OnItemClickListener()

{

@Override

public void onItemClick(AdapterView? parent, View view, int position, long id)

{

String check = ((TextView) view).getText().toString();

yesArray.remove(check);

noArray.add(check);

yesAdapter.notifyDataSetChanged();

noAdapter.notifyDataSetChanged();

}

});

}

public void onClick(View v)

{

switch (v.getId())

{

case R.id.cancel:

this.dismiss();

break;

case R.id.enter:

for (int i = 0; i  yesArray.size(); i++)

{

exportArray.add(yesArray.get(i));

}

this.dismiss();

break;

default:

break;

}

}

}

布局文件:style_dialog_control.xml

?xml version="1.0" encoding="utf-8"?

LinearLayout xmlns:android=""

android:id="@+id/RelativeLayout"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:background="#E3E3E3"

android:orientation="vertical" 

RelativeLayout

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:background="#DA4E7D" 

TextView

android:id="@+id/title_no"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:paddingLeft="5dp"

android:text="待添加设备"

android:textSize="25sp" /

requestFocus /

TextView

android:id="@+id/title_yes"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentRight="true"

android:paddingRight="5dp"

android:text="已添加设备"

android:textSize="25sp" /

/RelativeLayout

LinearLayout

android:layout_width="match_parent"

android:layout_height="0dp"

android:layout_weight="15"

android:baselineAligned="false"

android:orientation="horizontal"

android:padding="2dp" 

ListView

android:id="@+id/device_no"

android:layout_width="0dp"

android:layout_height="match_parent"

android:layout_weight="1"

android:background="@drawable/style_stroke"

android:padding="1dp" 

/ListView

ListView

android:id="@+id/device_yes"

android:layout_width="0dp"

android:layout_height="match_parent"

android:layout_weight="1"

android:background="@drawable/style_stroke"

android:padding="1dp" 

/ListView

/LinearLayout

LinearLayout

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_weight="1"

android:orientation="horizontal" 

Button

android:id="@+id/cancel"

style="?android:attr/buttonBarButtonStyle"

android:layout_width="0dp"

android:layout_height="match_parent"

android:layout_marginRight="1dp"

android:layout_weight="1"

android:background="@drawable/style_button"

android:text="取消"

android:textColor="#FFFFFF"

android:textSize="18sp" /

Button

android:id="@+id/enter"

style="?android:attr/buttonBarButtonStyle"

android:layout_width="0dp"

android:layout_height="match_parent"

android:layout_marginLeft="1dp"

android:layout_weight="1"

android:background="@drawable/style_button"

android:singleLine="true"

android:text="确定"

android:textColor="#FFFFFF"

android:textSize="18sp" /

/LinearLayout

/LinearLayout

布局文件:style_listview_control.xml

?xml version="1.0" encoding="utf-8"?

TextView xmlns:android="

"

android:id="@+id/text"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:layout_alignParentLeft="true"

android:layout_alignParentRight="true"

android:layout_centerVertical="true"

android:gravity="center_vertical|center_horizontal"

android:minHeight="32dp"

android:text="TextView"

android:textSize="22sp" /

用JAVA代码实现添加好友模版

import javax.swing.*;

import javax.swing.text.JTextComponent;

import java.awt.*;

import java.awt.event.*;

public class ChatFrame extends JFrame implements ActionListener {

private JLabel id;

private JLabel group;

private JLabel allas;

public JTextField inputId;

public JTextField inputGroup;

public JTextField inputAllas;

private JButton submit;

private JPanel pane;

public ChatFrame(){

id = new JLabel("Id");

group = new JLabel("Group");

allas = new JLabel("Allas");

inputId = new JTextField();

inputGroup = new JTextField();

inputAllas = new JTextField();

submit = new JButton("确定");

pane=new JPanel();

pane.setLayout(null);

this.getContentPane().add(pane).setBackground(Color.white);

this.getContentPane().add(pane);

pane.add(id);

pane.add(group);

pane.add(allas);

pane.add(inputId);

pane.add(inputGroup);

pane.add(inputAllas);

pane.add(submit);

id.setBounds(5,5,50,30);

group.setBounds(5,35,50,30);

allas.setBounds(5,65,50,50);

inputId.setBounds(70,5,100,30);

inputGroup.setBounds(70,35,100,30);

inputAllas.setBounds(70,65,100,30);

submit.setBounds(150,100,60,30);

submit.addActionListener(this);

this.setSize(240,180);

this.setLocation(300,300);

this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

this.setVisible(true);

}

public void actionPerformed(ActionEvent e){

//按键监听,可添加连接数据库的操作

}

public static void main(String args[]){

new ChatFrame();

}

}

java如何实现QQ加好友功能

思路就是加一张好友表,如表ID,用户id,用户id2,是否为好友;加一个好友,通过Java操作数据库,添加一条数据,并显示出来。


文章标题:java添加好友代码,java实现添加好友功能
网站链接:http://cdkjz.cn/article/hdsiii.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220