干货,仿qq列表,手把手实现分类悬浮提示

合集下载

Java语言程序设计课程设计实训项目——应用Eclipse Swing可视化开发实现仿QQ程序的界面(第1部分)

Java语言程序设计课程设计实训项目——应用Eclipse Swing可视化开发实现仿QQ程序的界面(第1部分)

1.1应用Eclipse Swing可视化开发实现仿QQ程序的界面(第1部分)1.1.1利用Eclipse Swing可视化开发实现QQ登录主窗口本示例的操作结果如下所示:1、新建一个名称为IMSystem的Java项目2、在该项目中新建QQ登录主窗口(1)选择File>New>Other... ,然后再选择MyEclipse>Swing>Matisse Form,点击Next按钮。

(2)输入包名称为com.px1987.imsystem.frame,类名称为QQLoginMainFrame,并选择Swing JFrame类型点击“Finish”按钮,将进入可视化设计器视图同时也会在项目中自动添加系统库swing-layout-1.0.3.jar和AbsoluteLayout.jar()包文件3、设置QQLoginMainFrame窗口的属性(1)由于需要监控窗口的关闭行为,因此不应该再直接关闭窗口和退出程序因此首先选中主窗口,然后在属性面板中设置defaultCloseOperation项目为DO_NOTHING_ON_CLOSE。

(2)将窗口的标题条属性title项目设置为“QQ登录主窗口”(3)设置窗口内的文字的字体为“宋体”、12号、正常体由于font属性为对象属性项目,因此需要点击最右面的“浏览”按钮,进入自定义对话框中进行设置,如下图所示——在预览中识别是否为中文“宋体”:(4)设置窗口的图标由于iconImage也是对象属性,同样也需要进入自定义对象的对话框,并选择该属性的设置方式为“Custom code”类型——而采用其他方式时的图像文件都是本地磁盘的绝对路径。

然后输入下面黑体形式的代码——下面的代码是创建出一个Image类型的对象实例:java.awt.Toolkit.getDefaultToolkit().getImage(getClass().getResource("/images/loginframe/qqicon.jpg"))当然,首先需要在项目中拷贝相关的图像文件,系统最后会自动地产生出下面形式的语句:this.setIconImage(java.awt.Toolkit.Toolkit.getDefaultToolkit().getImage(getClass().getResource("/images/loginframe/qqicon.jpg")));(5)设置窗口的背景颜色为[232, 245, 255](6)再设置窗口的如下属性项目this.setResizable(false); //不能改变大小this.setAlwaysOnTop(true); //设置为最顶层的窗口(7)设置窗口的宽度和高度——在源代码窗口中找到下面的代码this.setSize(390, 350);this.setLocationRelativeTo(null); //居中显示4、测试目前的效果(1)由于系统在该类中已经自动添加了main()方法准备好项目中所需要的各种图标图像文件,由于在窗口类中自动添加有main方法,因此可以直接执行。

VisualC++设计超强仿QQ自动伸缩窗口

VisualC++设计超强仿QQ自动伸缩窗口

VisualC++设计超强仿QQ自动伸缩窗口某天在论坛上看到有人发帖询问QQ自动伸缩窗口是怎么实现的,我也好想知道,于是到百度一搜索,结果不多,来来去去都是那几篇,下载那些demo运行一下,发觉效果与QQ相差很大,于是决定自己动手做个,要求要近乎完美地模仿这个功能。

由于是些效果的东西,贴图也看不出来,所以文章里就不截图了,想看效果的就直接运行源代码的demo吧。

一、观察模仿前最重要的一步就是观察,经过半天对QQ的摆弄和摸索,总结出了以下一些特点:1、窗口开始粘附时,检测的是鼠标坐标与桌面边界的距离,特别地,粘附在下面的时候,检测的是与任务栏的距离;2、在向上移动窗口时,窗口边界永远不会超出桌面上面边界;3、窗口是个 TopMost 风格;4、当窗口粘附在上面、左边或右边并显示时,你把鼠标移动到最顶端,光标变成改变窗口大小的图标,而单单是把窗口的top坐标设置为0是不行的;5、粘附在下面的时候,当处于移动状态,那么窗口的底边是与任务栏顶边对齐的,但从隐藏到显示的时候,窗口的底端是与屏幕底边对齐的;6、隐藏后显露出来的那条线可能是一个Border,但肯定的是绝不包含Client区域;7、关于响应鼠标的进入与移出窗口,绝对不是WM_MOUSEMOVE、WM_MOUSELEAVE。

证明:你以及其慢的速度接触隐藏状态的QQ边界,你会发现几乎是"一触即发",你又以及其慢的速度移出显示状态的QQ,你会发现它的收缩反而不是"一触即发"的,而是离边缘10象素左右。

而WM_MOUSEMOVE,WM_MOUSELEAVE,只有在进入、移出Client区域才响应,明显和QQ 不同,其实从第6点也可以知道;8、粘附在两边的时候,高度会调整为桌面上边界到任务栏下边界的距离;9、在"拖动时显示窗口内容"模式下(桌面属性-外观-效果),粘附在两边的拖动出来时;如果收缩之前高度比收缩后小则回复原来高度,在非"拖动时显示窗口内容"模式下,光栅会回复原来高度,但释放左键时,高度却是收缩时调整后的高度,一开始我以为这是个BUG,但我编写时同样出现这个问题,发现这两种模式会影响WM_MOVING参数的意义;10、粘附在两边的时候当你设置任务栏自动隐藏,QQ窗口会自动调整高度充满屏幕高度;11、窗口显示或隐藏不是一瞬间的,这点在第9点提到的两种模式下,会有所不同;12、任务栏并不显示QQ窗口;二、编写代码观察完毕,就开始编写了。

自定义QToolTip样式

自定义QToolTip样式

本文写作纯属个人兴趣使然,界面没有美化什么,纯属学习之用,如果有当之处,还请大家海涵,进入正题。

本文主要讲述了利用Qt5实现类似QQ好友列表中,当鼠标悬停在头像上面时弹出QQ好友信息的功能,总共包括2个部分,其一列表显示部分(显示QQ 好友,包括头像、姓名、简要概述),其二CToolTip部分,用于显示当前用户的信息,话不多说,直接上代码和图QQ好友条信息显示部分:这个功能其实网上有相关的资料的,直接上代码吧:ItemWidget.h#ifndef ITEMWIDGET_H#define ITEMWIDGET_H#include <QWidget>#include <QLabel>#include <QPushButton>#include <QVBoxLayout>#include <QHBoxLayout>//class CLabel;class ItemWidget : public QWidget{Q_OBJECTpublic:explicit ItemWidget(QWidget *parent = 0);void setText(QPixmap pixmap, QString name, QString info);void setText(QString info);signals:public slots:private:QLabel *labelIcon;QLabel *labelName;QLabel *labelInfo;QHBoxLayout *horLayout;QVBoxLayout *verlayout;protected:bool event(QEvent *e);};#endif // ITEMWIDGET_HItemWidget.cpp#include "itemwidget.h"#include "global.h"#include "ctooltip.h"#include <QEvent>#include <QCursor>ItemWidget::ItemWidget(QWidget *parent) :QWidget(parent){labelIcon = new QLabel(this);labelName = new QLabel(this);labelName->setStyleSheet("QLabel{color: green; font: 13pt bold;}"); labelInfo = new QLabel(this);labelInfo->setStyleSheet("QLabel{color: gray;}");verlayout = new QVBoxLayout();verlayout->setContentsMargins(0, 0, 0, 0);verlayout->addWidget(labelName);verlayout->addWidget(labelInfo);horLayout = new QHBoxLayout(this);horLayout->setContentsMargins(2, 2, 2, 2);horLayout->addWidget(labelIcon, 1, Qt::AlignTop);horLayout->addLayout(verlayout, 4);}void ItemWidget::setText(QPixmap pixmap, QString name, QString info) { labelIcon->setPixmap(pixmap);labelName->setText(name);labelInfo->setText(info);}// 测试用的void ItemWidget::setText(QString info) {labelIcon->setText(info);}// 鼠标悬停的时候,显示当前用户简要信息bool ItemWidget::event(QEvent *e) {if (e->type() == QEvent::ToolTip) {qDebug() << "tool tip show";g_toolTip->showMessage(labelIcon->pixmap(),labelName->text(),labelInfo->text(),QCursor::pos());} else if (e->type() == QEvent::Leave) {qDebug() << "tool tip leave";g_toolTip->hide();}return QWidget::event(e);}然后是CToolTip自定义样式部分:.h#ifndef CTOOLTIP_H#define CTOOLTIP_H#include <QWidget>#include <QLabel>#include <QPushButton>#include <QGroupBox>#include <QVBoxLayout>#include <QHBoxLayout>class CToolTip : public QWidget{Q_OBJECTpublic:explicit CToolTip(QWidget *parent = 0);void showMessage(const QPixmap *pixmap, QString name, QString info, QPoint point);void showMessage(const QPixmap *pixmap, QPoint point);signals:public slots:private:QLabel *labelIcon;QLabel *labelName;QLabel *labelInfo;QHBoxLayout *horLayout;QVBoxLayout *verlayout;QGroupBox *groupBox;protected:void hoverEvent(QHoverEvent *);};#endif // CTOOLTIP_HCToolTip.cpp#include "ctooltip.h"#include <QDebug>#include <QApplication>#include <QDesktopWidget>CToolTip::CToolTip(QWidget *parent) :QWidget(parent){this->setWindowFlags(Qt::FramelessWindowHint |Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint);this->resize(200, 100); ;this->setObjectName("CToolTip");this->setStyleSheet("QWidget#CToolTip {border: 2px solid green; background-color: skyblue;}");groupBox = new QGroupBox(this);groupBox->setGeometry(10, 10, 180, 80);groupBox->setTitle("用户信息");labelIcon = new QLabel(groupBox);labelName = new QLabel(groupBox);labelInfo = new QLabel(groupBox);verlayout = new QVBoxLayout();verlayout->setContentsMargins(0, 0, 0, 0);verlayout->addWidget(labelName);verlayout->addWidget(labelInfo);horLayout = new QHBoxLayout(groupBox);horLayout->setContentsMargins(10, 10, 10, 10);horLayout->addWidget(labelIcon, 1, Qt::AlignTop);horLayout->addLayout(verlayout, 4);}// 显示ToolTip消息void CToolTip::showMessage(const QPixmap *pixmap, QString name, QString info, QPoint point) {labelIcon->setPixmap(*pixmap);labelName->setText(name);labelInfo->setText(info);// 重新定义CToolTip的坐标int rectX;int rectY;if (point.rx() < 200) {rectX = point.rx() + 10;} else {rectX = point.rx() - 240;}rectY = point.ry();move(QPoint(rectX, rectY));QWidget::show();}// 显示ToolTip消息void CToolTip::showMessage(const QPixmap *pixmap, QPoint point) { labelIcon->setPixmap(*pixmap);labelName->setText("自己想办法获取");labelInfo->setText("自己动手,丰衣足食");// 此处可以作为QToolTip样式进行显示move(point);QWidget::show();}// 当鼠标进入事件时,让界面隐藏掉void CToolTip::hoverEvent(QHoverEvent *) {hide();}// 最后一个组合界面,mainWidget.h#ifndef MAINWIDGET_H#define MAINWIDGET_H#include <QWidget>class CToolTip;namespace Ui {class MainWidget;}class MainWidget : public QWidget{Q_OBJECTpublic:explicit MainWidget(QWidget *parent = 0);~MainWidget();private:Ui::MainWidget *ui;CToolTip *ctoolTip;};#endif // MAINWIDGET_Hmainwidget.cpp#include "mainwidget.h"#include "ui_mainwidget.h"#include "itemwidget.h"#include "ctooltip.h"#include <QListWidgetItem>CToolTip *g_toolTip;MainWidget::MainWidget(QWidget *parent) :QWidget(parent),ui(new Ui::MainWidget){// this->setWindowFlags(Qt::FramelessWindowHint |Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint);ui->setupUi(this);ctoolTip = new CToolTip();// 定义全局的ToolTip,方便使用g_toolTip = ctoolTip;// 本行代码主要针对ListWidgetItem右键点击时才生效的ui->listWidget->setMouseTracking(true);// 添加测试数据for (int i = 0; i < 10; i++) {ItemWidget *itemWidget = new ItemWidget(ui->listWidget);itemWidget->setText(QPixmap(QString(":/images/%1").arg(i+1)), QString("标题"), QString("写点什么呢: %1?").arg(i));QListWidgetItem *listItem = newQListWidgetItem(ui->listWidget);// 此处的size如果不设置,界面被压缩了看不出ItemWidget的效果,高度一定要设置listItem->setSizeHint(QSize(200, 40));ui->listWidget->setItemWidget(listItem, itemWidget);}}MainWidget::~MainWidget(){delete ui;}// 界面文件没什么,就一个listWidget,最后给大家上一个效果代码下载地址:/s/1eQvk2R4。

Qt实现桌面右下角消息弹窗提示

Qt实现桌面右下角消息弹窗提示

Qt实现桌⾯右下⾓消息弹窗提⽰ 简单的做了⼀个类似QQ消息提⽰的消息弹窗提⽰的⼩模块,便于在系统后台程序提⽰检测的信息,使⽤Qt开发,设计整体思路是做⼀个⽆框架的widget,⾃⼰实现标题栏和内容栏,添加了向上移出,⾃动消隐退出效果,窗体简单,模块结构便于以后进⾏扩展和移植,旨在显⽰⽂字信息,通过按钮操作与主程序进⾏通信,运⾏结果如图⼀、弹窗主体部分 class widget1 #include "widget.h"23 #include "titlewidget.h"45 #include <QVBoxLayout>67 #include "mypushbutton.h"89 #include <QLabel>1011 #include <QPainter>1213 #include <QBitmap>1415 #include <QDesktopWidget>1617 #include <QApplication>1819 #include <QTimer>2021 #include <QDesktopServices>22232425 Widget::Widget(QWidget *parent) :2627 QWidget(parent)2829 {3031 setWindowFlags(Qt::FramelessWindowHint|Qt::WindowStaysOnTopHint);3233 isEnter = false;3435 titleW=new titleWidget;3637 connect(titleW,SIGNAL(myClose()),this,SLOT(close()));38394041 content=new QLabel;4243 content->setWordWrap(true);4445 content->setAlignment(Qt::AlignTop);4647 content->setFixedSize(300,100);4849 btnLook=new myPushButton("look.png","查看");5051 connect(btnLook,SIGNAL(clicked()),this,SLOT(seeInfo()));52535455 QVBoxLayout*mainLayout=new QVBoxLayout;5657 mainLayout->setMargin(0);5859 mainLayout->addWidget(titleW);6061 mainLayout->addWidget(content);6263 content->setMargin(5);6465 mainLayout->addWidget(btnLook,0,Qt::AlignRight);6667 setLayout(mainLayout);68697071 setFixedSize(sizeHint().width(),sizeHint().height());75 timerShow=new QTimer(this);7677 connect(timerShow,SIGNAL(timeout()),this,SLOT(myMove())); 7879 timerStay=new QTimer(this);8081 connect(timerStay,SIGNAL(timeout()),this,SLOT(myStay())); 8283 timerClose=new QTimer(this);8485 connect(timerClose,SIGNAL(timeout()),this,SLOT(myClose())); 8687 }88899091 Widget::~Widget()9293 {9495 }96979899void Widget::setMsg(QString title, QString content, QString work) 100101 {102103 titleW->setTitleText(""+title);104105this->content->setText(""+content);106107 }108109110111void Widget::paintEvent(QPaintEvent *)112113 {114115 QBitmap bitmap(this->size());116117 bitmap.fill(Qt::white);118119 QPainter painter(this);120121 painter.setBrush(QBrush(QColor(250,240,230)));122123 painter.setPen(QPen(QBrush(QColor(255,222,173)),4));124125 painter.drawRoundedRect(bitmap.rect(),5,5);126127 setMask(bitmap);128129 }130131void Widget::showAsQQ()132133 {134135 QDesktopWidget *deskTop=QApplication::desktop();136137 deskRect=deskTop->availableGeometry();138139140141 normalPoint.setX(deskRect.width()-rect().width()-1);142143 normalPoint.setY(deskRect.height()-rect().height());144145 move(normalPoint.x(),deskRect.height()-1);146147 show();148149 timerShow->start(5);150151 }152153//平滑显⽰出来154155void Widget::myMove()159static int beginY=QApplication::desktop()->height(); 160161 beginY--;162163 move(normalPoint.x(),beginY);164165if(beginY<=normalPoint.y())166167 {168169 timerShow->stop();170171 timerStay->start(1000);172173 }174175 }176177//停留显⽰178179void Widget::myStay()180181 {182183static int timeCount=0;184185 timeCount++;186187if(timeCount>=9)188189 {190191 timerStay->stop();192193 timerClose->start(200);194195 }196197 }198199//⾃动关闭时实现淡出效果200201void Widget::myClose()202203 {204205static double tran=1.0;206207if(isEnter){208209 tran = 1.0;210211 setWindowOpacity(tran);212213return;214215 }216217 tran-=0.1;218219if(tran<=0.0)220221 {222223 timerClose->stop();224225 emit close();226227 }228229else230231 setWindowOpacity(tran);232233 }234235void Widget::seeInfo()236237 {238239243244245void Widget::enterEvent(QEvent *)246247 {248249 isEnter = true;250251 }252253void Widget::leaveEvent(QEvent *)254255 {256257 isEnter = false;258259 }⼆、标题部分与⾃定义按钮部分1//标题类 class titlewidget2 #include "titlewidget.h"3 #include <QLabel>4 #include <QToolButton>5 #include <QHBoxLayout>6 #include <QPainter>7 #include <QLinearGradient>8 #include <QIcon>910 titleWidget::titleWidget(QWidget *parent) :11 QWidget(parent)12 {13 titleText=new QLabel;14 btnClose = new QToolButton(this);15 btnClose->setObjectName(QString::fromUtf8("btnClose"));16 btnClose->setToolTip(tr("关闭"));17 btnClose->setStyleSheet(QString::fromUtf8("QWidget[objectName=\"btnClose\"]{\n" 18"border-width: 0px;\n"19"border-style: solid;\n"20"padding: 0px;\n"21"padding-left: 0px;\n"22"padding-right: 0px;\n"23"min-width: 16px;\n"24"max-width: 16px;\n"25"min-height: 16px;\n"26"max-height: 16px;\n"27"background-image: url(:/Resources/btn_close_normal.bmp);\n"28"}\n"29"\n"30"QWidget[objectName=\"btnClose\"]:hover{\n"31"background-image: url(:/Resources/btn_close_highlight.bmp);\n"32"}\n"33"\n"34"QWidget[objectName=\"btnClose\"]:pressed{\n"35"background-image: url(:/Resources/btn_close_down.bmp);\n"36"}\n"37""));38 connect(btnClose,SIGNAL(clicked()),this,SIGNAL(myClose()));39 QHBoxLayout *layout=new QHBoxLayout;40 layout->addWidget(titleText,0,Qt::AlignLeft);41 layout->addStretch();42 layout->addWidget(btnClose,0,Qt::AlignRight);43 layout->setMargin(0);44 setLayout(layout);45 setFixedHeight(20);46 }4748void titleWidget::paintEvent(QPaintEvent *)49 {50 QLinearGradient linear(rect().topLeft(),rect().bottomRight());51 linear.setColorAt(0,QColor(227,207,87));52 linear.setColorAt(0.5,QColor(245,222,179));53 linear.setColorAt(1,QColor(189,252,201));5455 QPainter painter(this);56 painter.setBrush(QBrush(linear));57 painter.setPen(Qt::NoPen);58 painter.drawRect(rect());59 }6063 titleText->setText(title);64 }65//按钮类:class mypushbutton66 #include "mypushbutton.h"67 #include <QPalette>68 #include <QPixmap>69 #include <QCursor>7071 myPushButton::myPushButton(QWidget *parent) :72 QPushButton(parent)73 {74 }75 myPushButton::myPushButton(QString iconStr,QString textStr, QWidget *parent):QPushButton(parent)76 {77 QPixmap pixmap(":/Resources/"+iconStr);78 setIcon(QIcon(pixmap));79 setIconSize(pixmap.size());80 setText(textStr);81 resize(pixmap.size());82 setBkPalette(0);//设置背景完全透明83 setFlat(true);84 setAutoFillBackground(true);85 }8687void myPushButton::setBkPalette(int transparency)//设置背景透明度88 {89 QPalette palette;90 palette.setBrush(QPalette::Button,QBrush(QColor(255,255,255,transparency)));91 setPalette(palette);92 }93void myPushButton::enterEvent(QEvent *)94 {95 setCursor(Qt::PointingHandCursor);96 }97void myPushButton::leaveEvent(QEvent *)98 {99 setCursor(Qt::CustomCursor);100 }101void myPushButton::mousePressEvent(QMouseEvent *e)102 {103104 }105void myPushButton::mouseReleaseEvent(QMouseEvent *e)106 {107108 emit clicked();109 }。

Android实现仿QQ登录可编辑下拉框

Android实现仿QQ登录可编辑下拉框

Android实现仿QQ登录可编辑下拉菜单在Android里,直接提供的Spinner控件虽然可以实现下拉菜单的效果,但其效果并不理想,很多时候我们需要类似手机QQ那样既可以在文本框中直接输入编辑文字,可以在下拉菜单中选中或者删除菜单选项,并且下拉菜单并不是以遮罩整个手机屏幕方式,而是以浮动在屏幕上的效果出现。

下面呢,就来实现一下这些效果。

最后效果:此次主要以EdiText、PopupWindow、ListView及Adapter来实现这种下拉效果。

具体实现步骤就不一步步详细介绍了,直接贴完整代码吧,注释比较详细,相信都能看得懂。

Activity代码:package com.zw.select;import java.util.ArrayList;import android.app.Activity;import android.graphics.drawable.BitmapDrawable;import android.os.Bundle;import android.os.Handler;import android.os.Handler.Callback;import android.os.Message;import android.view.View;import android.widget.Button;import android.widget.EditText;import android.widget.ImageView;import android.widget.LinearLayout;import youtParams;import android.widget.ListView;import android.widget.PopupWindow;//主界面Activitypublic class SelectActivity extends Activity implements Callback {//PopupWindow对象private PopupWindow selectPopupWindow= null;//自定义Adapterprivate OptionsAdapter optionsAdapter = null;//下拉框选项数据源private ArrayList<String> datas = new ArrayList<String>();;//下拉框依附组件private LinearLayout parent;//下拉框依附组件宽度,也将作为下拉框的宽度private int pwidth;//文本框private EditText et;//下拉箭头图片组件private ImageView image;//恢复数据源按钮private Button button;//展示所有下拉选项的ListViewprivate ListView listView = null;//用来处理选中或者删除下拉项消息private Handler handler;//是否初始化完成标志private boolean flag = false;@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(yout.select);}/*** 没有在onCreate方法中调用initWedget(),而是在onWindowFocusChanged方法中调用,* 是因为initWedget()中需要获取PopupWindow浮动下拉框依附的组件宽度,在onCreate方法中是无法获取到该宽度的*/@Overridepublic void onWindowFocusChanged(boolean hasFocus) {super.onWindowFocusChanged(hasFocus);while(!flag){initWedget();flag = true;}}/*** 初始化界面控件*/private void initWedget(){//初始化Handler,用来处理消息handler = new Handler(SelectActivity.this);//初始化界面组件parent = (LinearLayout)findViewById(R.id.parent);et = (EditText)findViewById(R.id.edittext);image = (ImageView)findViewById(R.id.btn_select);//获取下拉框依附的组件宽度int width = parent.getWidth();pwidth = width;//设置点击下拉箭头图片事件,点击弹出PopupWindow浮动下拉框image.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {if(flag){//显示PopupWindow窗口popupWindwShowing();}}});//初始化PopupWindowinitPopuWindow();button = (Button)findViewById(R.id.refresh);//设置点击事件,恢复下拉框列表数据,没有什么作用,纯粹是为了方便多看几次效果而设置button.setOnClickListener(new View.OnClickListener() { @Overridepublic void onClick(View v) {initDatas();optionsAdapter.notifyDataSetChanged();}});}/*** 初始化填充Adapter所用List数据*/private void initDatas(){datas.clear();datas.add("北京");datas.add("上海");datas.add("广州");datas.add("深圳");datas.add("重庆");datas.add("青岛");datas.add("石家庄");}/*** 初始化PopupWindow*/private void initPopuWindow(){i nitDatas();//PopupWindow浮动下拉框布局View loginwindow =(View)this.getLayoutInflater().inflate(yout.options, null);listView = (ListView) loginwindow.findViewById(R.id.list);//设置自定义AdapteroptionsAdapter = new OptionsAdapter(this, handler,datas);listView.setAdapter(optionsAdapter);selectPopupWindow = new PopupWindow(loginwindow,pwidth,LayoutParams.WRAP_CONTENT, true);selectPopupWindow.setOutsideTouchable(true);//这一句是为了实现弹出PopupWindow后,当点击屏幕其他部分及Back键时PopupWindow会消失,//没有这一句则效果不能出来,但并不会影响背景//本人能力极其有限,不明白其原因,还望高手、知情者指点一下selectPopupWindow.setBackgroundDrawable(new BitmapDrawable()); }/*** 显示PopupWindow窗口** @param popupwindow*/public void popupWindwShowing() {//将selectPopupWindow作为parent的下拉框显示,并指定selectPopupWindow 在Y方向上向上偏移3pix,//这是为了防止下拉框与文本框之间产生缝隙,影响界面美化//(是否会产生缝隙,及产生缝隙的大小,可能会根据机型、Android系统版本不同而异吧,不太清楚)selectPopupWindow.showAsDropDown(parent,0,-3);}/*** PopupWindow消失*/public void dismiss(){selectPopupWindow.dismiss();}/*** 处理Hander消息*/@Overridepublic boolean handleMessage(Message message) {Bundle data = message.getData();switch(message.what){case 1://选中下拉项,下拉框消失int selIndex = data.getInt("selIndex");et.setText(datas.get(selIndex));dismiss();break;case 2://移除下拉项数据int delIndex = data.getInt("delIndex");datas.remove(delIndex);//刷新下拉列表optionsAdapter.notifyDataSetChanged();break;}return false;}}自定义适配器Adapter代码:package com.zw.select;import java.util.ArrayList;import android.app.Activity;import android.os.Bundle;import android.os.Handler;import android.os.Message;import youtInflater;import android.view.View;import android.view.ViewGroup;import android.widget.BaseAdapter;import android.widget.ImageView;import android.widget.TextView;//自定义适配器Adapterpublic class OptionsAdapter extends BaseAdapter {private ArrayList<String> list = new ArrayList<String>();private Activity activity = null;private Handler handler;/*** 自定义构造方法* @param activity* @param handler* @param list*/public OptionsAdapter(Activity activity,Handlerhandler,ArrayList<String> list){t his.activity = activity;t his.handler = handler;t his.list = list;}@Overridepublic int getCount() {return list.size();}@Overridepublic Object getItem(int position) {return list.get(position);}@Overridepublic long getItemId(int position) {return position;}@Overridepublic View getView(final int position, View convertView, ViewGroup parent) {ViewHolder holder = null;if (convertView == null) {holder = new ViewHolder();//下拉项布局convertView =LayoutInflater.from(activity).inflate(yout.option_item, null);holder.textView = (TextView)convertView.findViewById(R.id.item_text);holder.imageView = (ImageView)convertView.findViewById(R.id.delImage);convertView.setTag(holder);} else {holder = (ViewHolder) convertView.getTag();}holder.textView.setText(list.get(position));//为下拉框选项文字部分设置事件,最终效果是点击将其文字填充到文本框holder.textView.setOnClickListener(new View.OnClickListener() { @Overridepublic void onClick(View v) {Message msg = new Message();Bundle data = new Bundle();//设置选中索引data.putInt("selIndex", position);msg.setData(data);msg.what = 1;//发出消息handler.sendMessage(msg);}});//为下拉框选项删除图标部分设置事件,最终效果是点击将该选项删除holder.imageView.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {Message msg = new Message();Bundle data = new Bundle();//设置删除索引data.putInt("delIndex", position);msg.setData(data);msg.what = 2;//发出消息handler.sendMessage(msg);}});return convertView;}}class ViewHolder {TextView textView;ImageView imageView;}主界面布局select.xml文件:<?xml version="1.0"encoding="utf-8"?><LinearLayoutxmlns:android="/apk/res/android"android:orientation="vertical"android:layout_width="fill_parent"android:layout_height="fill_parent"android:background="#EEEED1"><LinearLayout android:id="@+id/parent"android:layout_width="wrap_content"android:layout_height="wrap_content"android:orientation="horizontal"android:layout_marginTop="50dp" android:layout_marginLeft="30dp"><EditText android:id="@+id/edittext"android:layout_width="200dp" android:singleLine="true"android:layout_height="40dp"android:background="@drawable/bg1" android:paddingLeft="3dp"/><ImageView android:id="@+id/btn_select"android:layout_width="30dp" android:layout_height="40dp"android:src="@drawable/img1"android:scaleType="fitXY"/></LinearLayout><Button android:id="@+id/refresh"android:layout_width="wrap_content" android:layout_height="45dp"android:text="恢复"android:textColor="#000000"android:textSize="20sp"android:layout_marginTop="30dp"android:layout_marginLeft="30dp"/></LinearLayout>PopupWindow浮动下拉框布局options.xml文件:<?xml version="1.0"encoding="utf-8"?><LinearLayoutxmlns:android="/apk/res/android"android:orientation="vertical"android:layout_width="fill_parent"android:layout_height="wrap_content"android:gravity="center_horizontal"><ListView android:id="@+id/list"android:layout_width="fill_parent"android:layout_height="wrap_content"android:cacheColorHint="#00000000"></ListView></LinearLayout>下拉选项布局option_item.xml文件:<?xml version="1.0"encoding="utf-8"?><LinearLayoutxmlns:android="/apk/res/android"android:layout_width="fill_parent"android:layout_height="fill_parent"android:background="#235654"><RelativeLayoutandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:gravity="center_vertical"android:minHeight="40dp"><ImageView android:id="@+id/delImage"android:layout_width="20dp" android:layout_height="wrap_content"android:src="@drawable/del"android:textSize="18sp"android:layout_alignParentRight="true"android:layout_marginRight="10dp"/><TextView android:id="@+id/item_text"android:layout_height="wrap_content"android:layout_width="fill_parent"android:layout_toLeftOf="@id/delImage"android:paddingLeft="5dp"android:layout_alignParentLeft="true"></TextView></RelativeLayout></LinearLayout>到此代码及布局文件基本都贴完了。

《蓝梦教育集团即时通讯系统》(仿腾讯QQ)——信息主窗口类中的各个子面板和弹出式菜单程序类(第2部分)

《蓝梦教育集团即时通讯系统》(仿腾讯QQ)——信息主窗口类中的各个子面板和弹出式菜单程序类(第2部分)

J2EE课程设计实训教学示例项目《蓝梦教育集团即时通讯系统》(仿腾讯QQ)——完善客户端系统信息主窗口类中的各个子面板和弹出式菜单程序类(第2/2部分)1.1.1实现相关的弹出式菜单的功能1、FriendInfoTreeNodeSelfPopupMenu类(1)类名称为FriendInfoTreeNodeSelfPopupMenu,包名称为com.px1987.imsystem.client.frame.imsystemmainframe.tree,继承于ponent.SelfDefineJPopupMenu_ImageBar类(2)编程该类package com.px1987.imsystem.client.frame.imsystemmainframe.tree;import javax.swing.ImageIcon;import javax.swing.JCheckBoxMenuItem;import javax.swing.JMenuItem;import ponent.SelfDefineJCheckBoxMenuItem;import ponent.SelfDefineJMenuItem;import ponent.SelfDefineJPopupMenu_ImageBar;import com.px1987.imsystem.client.frame.IMSystemMainFrame;public class FriendInfoTreeNodeSelfPopupMenu extends SelfDefineJPopupMenu_ImageBar { private static final long serialVersionUID = -3719946677412611465L;private IMSystemMainFrame oneIMSystemMainFrame=null;public IMSystemMainFrame getOneIMSystemMainFrame() {return oneIMSystemMainFrame;}public void setOneIMSystemMainFrame(IMSystemMainFrame oneIMSystemMainFrame) { this.oneIMSystemMainFrame = oneIMSystemMainFrame;}private JMenuItem imSpaceMenuItem = null;private JMenuItem onePersonInfoMenuItem = null;private JMenuItem updateMyHeadImageMenuItem = null;private JCheckBoxMenuItem showMyHeadImageCheckBoxMenuItem = null;private JMenuItem netRecordMenuItem = null;private JMenuItem graftMenuItem =null;public FriendInfoTreeNodeSelfPopupMenu() {super();}public FriendInfoTreeNodeSelfPopupMenu(String label,IMSystemMainFrame oneIMSystemMainFrame) {super(label);this.oneIMSystemMainFrame=oneIMSystemMainFrame;createThisTreeNodeSelfPopupMenu();}public FriendInfoTreeNodeSelfPopupMenu(String label) {super(label);}public FriendInfoTreeNodeSelfPopupMenu(ImageIcon imageIcon) {super(imageIcon);}private void createThisTreeNodeSelfPopupMenu(){imSpaceMenuItem = new SelfDefineJMenuItem();imSpaceMenuItem.setText("IM 空间");imSpaceMenuItem.setIcon(newImageIcon(getClass().getResource("/images/treePopMenu/sefttree1.jpg")));this.add(imSpaceMenuItem);onePersonInfoMenuItem= new SelfDefineJMenuItem();onePersonInfoMenuItem.setText("个人资料");this.add(onePersonInfoMenuItem);updateMyHeadImageMenuItem = new SelfDefineJMenuItem();updateMyHeadImageMenuItem.setText("更改我的头像");this.add(updateMyHeadImageMenuItem);showMyHeadImageCheckBoxMenuItem = new SelfDefineJCheckBoxMenuItem();showMyHeadImageCheckBoxMenuItem.setSelected(true);showMyHeadImageCheckBoxMenuItem.setText("显示我的头像");this.add(showMyHeadImageCheckBoxMenuItem);netRecordMenuItem = new SelfDefineJMenuItem();netRecordMenuItem.setText("网络备完录");netRecordMenuItem.setIcon(newImageIcon(getClass().getResource("/images/treePopMenu/sefttree2.jpg")));this.add(netRecordMenuItem);graftMenuItem = new SelfDefineJMenuItem();graftMenuItem.setText("送礼许愿");graftMenuItem.setIcon(newImageIcon(getClass().getResource("/images/treePopMenu/sefttree3.jpg")));this.add(graftMenuItem);}}2、FriendInfoTreeNodePopupMenu类(1)类名称为FriendInfoTreeNodePopupMenu,包名称为com.px1987.imsystem.client.frame.imsystemmainframe.tree,继承于ponent.SelfDefineJPopupMenu_ImageBar类(2)编程该类package com.px1987.imsystem.client.frame.imsystemmainframe.tree;import javax.swing.ButtonGroup;import javax.swing.ImageIcon;import javax.swing.JCheckBoxMenuItem;import javax.swing.JMenu;import javax.swing.JMenuItem;import ponent.SelfDefineJCheckBoxMenuItem;import ponent.SelfDefineJMenu;import ponent.SelfDefineJMenuItem;import ponent.SelfDefineJPopupMenu_ImageBar;import com.px1987.imsystem.client.frame.IMSystemMainFrame;importcom.px1987.imsystem.client.frame.imsystemmainframe.treeevent.FriendInfoTreeNodePopupMe nu_ActionListenerEventHandler;import com.px1987.imsystem.client.util.IMSystemClientUtils;public class FriendInfoTreeNodePopupMenu extends SelfDefineJPopupMenu_ImageBar { private static final long serialVersionUID = 8215073581183947613L;private IMSystemMainFrame oneIMSystemMainFrame=null;private JMenu personHeadImageMenu = null;private JCheckBoxMenuItem bigHeadImageMenuItem = null;private JCheckBoxMenuItem smallHeadImageMenuItem =null;private JCheckBoxMenuItem standardHeadImageMenuItem = null;private JCheckBoxMenuItem showMyHeadImageMenuItem = null;private JMenu nameInfoShowMenu =null;private JCheckBoxMenuItem showAnnotationInfoMenuItem = null;private JCheckBoxMenuItem showLoveNameInfoMenuItem = null;private JMenu columnShowMenu = null;private JCheckBoxMenuItem singleShowMenuItem = null;private JCheckBoxMenuItem multiShowMenuItem = null;private JCheckBoxMenuItem showClearInfoMenuItem = null;private JCheckBoxMenuItem slideEffectMenuItem = null;private JMenu sortShowMenu = null;private JCheckBoxMenuItem sortByIDMenuItem = null;private JCheckBoxMenuItem sortByUpdateTimeMenuItem =null;private JCheckBoxMenuItem sortByNameMenuItem = null;private JMenuItem showOnLinePersonInfoMenuItem = null;private JCheckBoxMenuItem showNoKnownPersonGroupInfoMenuItem =null;private JCheckBoxMenuItem showBlockNameListMenuItem = null;private JMenuItem addNewGroupInfoMenuItem = null;private JMenuItem addNewFriendMenuItem = null;private JMenuItem renameMenuItem = null;private JMenuItem deleteThisGroupMenuItem = null;public FriendInfoTreeNodePopupMenu() {super();}public FriendInfoTreeNodePopupMenu(String label) {super(label);}public FriendInfoTreeNodePopupMenu(String label,IMSystemMainFrame oneIMSystemMainFrame) {super(label);this.oneIMSystemMainFrame=oneIMSystemMainFrame;createThisTreeNodePopupMenu();}public FriendInfoTreeNodePopupMenu(ImageIcon imageIcon) {super(imageIcon);}private void createThisTreeNodePopupMenu(){initThisTreeNodePopupMenu();createAllMenuAndMenuItemForThisPopup();}private void initThisTreeNodePopupMenu(){this.setBackground(IMSystemClientUtils.getNoSerializableVOInstance().getLoginFormBgColor());}private void createAllMenuAndMenuItemForThisPopup(){personHeadImageMenu = new SelfDefineJMenu();personHeadImageMenu.setText("头像显示方式");personHeadImageMenu.setIcon(new ImageIcon(getClass().getResource("/images/treePopMenu/headimage.jpg")));this.add(personHeadImageMenu);ButtonGroup oneButtonGroup=new ButtonGroup();bigHeadImageMenuItem = new SelfDefineJCheckBoxMenuItem();oneButtonGroup.add(bigHeadImageMenuItem);smallHeadImageMenuItem = new SelfDefineJCheckBoxMenuItem();oneButtonGroup.add(smallHeadImageMenuItem);standardHeadImageMenuItem = new SelfDefineJCheckBoxMenuItem();oneButtonGroup.add(standardHeadImageMenuItem);bigHeadImageMenuItem.setText("大头像");bigHeadImageMenuItem.addActionListener(newFriendInfoTreeNodePopupMenu_ActionListenerEventHandler(oneIMSystemMainFrame, "bigHeadImageMenuItem_onClick"));smallHeadImageMenuItem.setText("小头像");smallHeadImageMenuItem.addActionListener(newFriendInfoTreeNodePopupMenu_ActionListenerEventHandler(oneIMSystemMainFrame, "smallHeadImageMenuItem_onClick"));standardHeadImageMenuItem.setText("标准头像");standardHeadImageMenuItem.addActionListener(newFriendInfoTreeNodePopupMenu_ActionListenerEventHandler(oneIMSystemMainFrame, "standardHeadImageMenuItem_onClick"));showMyHeadImageMenuItem = new SelfDefineJCheckBoxMenuItem();showMyHeadImageMenuItem.setText("显示我的头像");showMyHeadImageMenuItem.setSelected(true);showMyHeadImageMenuItem.addActionListener(newFriendInfoTreeNodePopupMenu_ActionListenerEventHandler(oneIMSystemMainFrame, "showMyHeadImageMenuItem_onClick"));personHeadImageMenu.add(bigHeadImageMenuItem);personHeadImageMenu.add(smallHeadImageMenuItem);personHeadImageMenu.add(standardHeadImageMenuItem);personHeadImageMenu.addSeparator();personHeadImageMenu.add(showMyHeadImageMenuItem);nameInfoShowMenu = new SelfDefineJMenu();nameInfoShowMenu.setText("名称显示");this.add(nameInfoShowMenu);ButtonGroup twoButtonGroup=new ButtonGroup();showAnnotationInfoMenuItem = new SelfDefineJCheckBoxMenuItem();twoButtonGroup.add(showAnnotationInfoMenuItem);showLoveNameInfoMenuItem = new SelfDefineJCheckBoxMenuItem();twoButtonGroup.add(showLoveNameInfoMenuItem);showAnnotationInfoMenuItem.setText("显示备注");showAnnotationInfoMenuItem.setSelected(true);showAnnotationInfoMenuItem.addActionListener(newFriendInfoTreeNodePopupMenu_ActionListenerEventHandler(oneIMSystemMainFrame, "showAnnotationInfoMenuItem_onClick"));showLoveNameInfoMenuItem.setText("显示昵称");showLoveNameInfoMenuItem.addActionListener(newFriendInfoTreeNodePopupMenu_ActionListenerEventHandler(oneIMSystemMainFrame, "showLoveNameInfoMenuItem_onClick"));nameInfoShowMenu.add(showAnnotationInfoMenuItem);nameInfoShowMenu.add(showLoveNameInfoMenuItem);columnShowMenu = new SelfDefineJMenu();columnShowMenu.setText("列表显示");this.add(columnShowMenu);ButtonGroup threeButtonGroup = new ButtonGroup();singleShowMenuItem = new SelfDefineJCheckBoxMenuItem();threeButtonGroup.add(singleShowMenuItem);multiShowMenuItem = new SelfDefineJCheckBoxMenuItem();threeButtonGroup.add(multiShowMenuItem);singleShowMenuItem.setText("单列显示");singleShowMenuItem.setSelected(true);singleShowMenuItem.addActionListener(newFriendInfoTreeNodePopupMenu_ActionListenerEventHandler(oneIMSystemMainFrame, "singleShowMenuItem_onClick"));columnShowMenu.add(singleShowMenuItem);multiShowMenuItem.setText("多列平铺");multiShowMenuItem.addActionListener(newFriendInfoTreeNodePopupMenu_ActionListenerEventHandler(oneIMSystemMainFrame, "multiShowMenuItem_onClick"));columnShowMenu.add(multiShowMenuItem);columnShowMenu.addSeparator();showClearInfoMenuItem = new SelfDefineJCheckBoxMenuItem();showClearInfoMenuItem.setText("显示清爽资料");showClearInfoMenuItem.addActionListener(newFriendInfoTreeNodePopupMenu_ActionListenerEventHandler(oneIMSystemMainFrame, "ShowClearInfoMenuItem_onClick"));columnShowMenu.add(showClearInfoMenuItem);slideEffectMenuItem = new SelfDefineJCheckBoxMenuItem();slideEffectMenuItem.setText("滑动效果");slideEffectMenuItem.addActionListener(newFriendInfoTreeNodePopupMenu_ActionListenerEventHandler(oneIMSystemMainFrame, "slideEffectMenuItem_onClick"));columnShowMenu.addSeparator();columnShowMenu.add(slideEffectMenuItem);this.addSeparator();sortShowMenu = new SelfDefineJMenu();sortShowMenu.setText("排序显示");this.add(sortShowMenu);ButtonGroup fourButtonGroup = new ButtonGroup();sortByIDMenuItem = new SelfDefineJCheckBoxMenuItem();fourButtonGroup.add(sortByIDMenuItem);sortByUpdateTimeMenuItem = new SelfDefineJCheckBoxMenuItem();fourButtonGroup.add(sortByUpdateTimeMenuItem);sortByNameMenuItem = new SelfDefineJCheckBoxMenuItem();fourButtonGroup.add(sortByNameMenuItem);sortByIDMenuItem.setText("按身份标识排序");sortByUpdateTimeMenuItem.setText("按服务更新排序");sortByNameMenuItem.setText("按名称排序");sortShowMenu.add(sortByIDMenuItem);sortShowMenu.add(sortByUpdateTimeMenuItem);sortShowMenu.add(sortByNameMenuItem);this.addSeparator();showOnLinePersonInfoMenuItem = new SelfDefineJMenuItem();showOnLinePersonInfoMenuItem.setText("显示在线联系人");this.add(showOnLinePersonInfoMenuItem);this.addSeparator();showNoKnownPersonGroupInfoMenuItem = new SelfDefineJCheckBoxMenuItem();showNoKnownPersonGroupInfoMenuItem.setText("显示陌生人分组");showNoKnownPersonGroupInfoMenuItem.addActionListener(newFriendInfoTreeNodePopupMenu_ActionListenerEventHandler(oneIMSystemMainFrame, "showNoKnownPersonGroupInfoMenuItem_onClick"));this.add(showNoKnownPersonGroupInfoMenuItem);showBlockNameListMenuItem = new SelfDefineJCheckBoxMenuItem();showBlockNameListMenuItem.setText("显示黑名单");showBlockNameListMenuItem.addActionListener(newFriendInfoTreeNodePopupMenu_ActionListenerEventHandler(oneIMSystemMainFrame, "showBlockNameListMenuItem_onClick"));this.add(showBlockNameListMenuItem);this.addSeparator();addNewGroupInfoMenuItem = new SelfDefineJMenuItem();addNewGroupInfoMenuItem.setText("添加分组");addNewGroupInfoMenuItem.addActionListener(newFriendInfoTreeNodePopupMenu_ActionListenerEventHandler(oneIMSystemMainFrame, "addNewGroupInfoMenuItem_onClick"));this.add(addNewGroupInfoMenuItem);addNewFriendMenuItem = new SelfDefineJMenuItem();addNewFriendMenuItem.setText("添加联系人");addNewFriendMenuItem.setIcon(new ImageIcon(getClass().getResource("/images/treePopMenu/addFriend.jpg")));addNewFriendMenuItem.addActionListener(new FriendInfoTreeNodePopupMenu_ActionListenerEventHandler(oneIMSystemMainFrame, "addNewFriendMenuItem_onClick"));this.add(addNewFriendMenuItem);this.addSeparator();renameMenuItem = new SelfDefineJMenuItem();renameMenuItem.setText("重命名");renameMenuItem.addActionListener(newFriendInfoTreeNodePopupMenu_ActionListenerEventHandler(oneIMSystemMainFrame, "renameMenuItem_onClick"));deleteThisGroupMenuItem = new SelfDefineJMenuItem();deleteThisGroupMenuItem.setText("删除该组");deleteThisGroupMenuItem.setIcon(new ImageIcon(getClass().getResource("/images/treePopMenu/deleteGroup.jpg")));deleteThisGroupMenuItem.addActionListener(new FriendInfoTreeNodePopupMenu_ActionListenerEventHandler(oneIMSystemMainFrame, "deleteThisGroupMenuItem_onClick"));this.add(renameMenuItem);this.add(deleteThisGroupMenuItem);}public JMenuItem getDeleteThisGroupMenuItem() {return deleteThisGroupMenuItem;}public JMenuItem getRenameMenuItem() {return renameMenuItem;}public JMenuItem getAddNewGroupInfoMenuItem() {return addNewGroupInfoMenuItem;}}3、FriendInfoTreeNodePopupMenu_byClickOut类(1)类名称为FriendInfoTreeNodePopupMenu_byClickOut,包名称为com.px1987.imsystem.client.frame.imsystemmainframe.tree,继承于ponent.SelfDefineJPopupMenu_ImageBar类(2)编程该类package com.px1987.imsystem.client.frame.imsystemmainframe.tree;import javax.swing.ButtonGroup;import javax.swing.ImageIcon;import javax.swing.JCheckBoxMenuItem;import javax.swing.JMenu;import javax.swing.JMenuItem;import ponent.SelfDefineJCheckBoxMenuItem;import ponent.SelfDefineJMenu;import ponent.SelfDefineJMenuItem;import ponent.SelfDefineJPopupMenu_ImageBar;import com.px1987.imsystem.client.frame.IMSystemMainFrame;importcom.px1987.imsystem.client.frame.imsystemmainframe.event.IMSystemMainFrame_ActionList enerEventHandler;public class FriendInfoTreeNodePopupMenu_byClickOut extends SelfDefineJPopupMenu_ImageBar {private static final long serialVersionUID = -8871613980569893992L;private IMSystemMainFrame oneIMSystemMainFrame=null;private JMenu personHeadImageMenu_byClickOut = null;private JCheckBoxMenuItem bigHeadImageMenuItem_byClickOut = null;private JCheckBoxMenuItem smallHeadImageMenuItem_byClickOut = null;private JCheckBoxMenuItem standardHeadImageMenuItem_byClickOut = null;private JCheckBoxMenuItem showMyHeadImageMenuItem_byClickOut = null;private JMenu nameInfoShowMenu_byClickOut = null;private JCheckBoxMenuItem showAnnotationInfoMenuItem_byClickOut = null;private JCheckBoxMenuItem showLoveNameInfoMenuItem_byClickOut = null;private JMenu columnShowMenu_byClickOut = null;private JCheckBoxMenuItem singleShowMenuItem_byClickOut = null;private JCheckBoxMenuItem multiShowMenuItem_byClickOut =null;private JCheckBoxMenuItem ShowClearInfoMenuItem_byClickOut = null;private JCheckBoxMenuItem slideEffectMenuItem_byClickOut = null;private JMenu sortShowMenu_byClickOut = new SelfDefineJMenu();private JCheckBoxMenuItem sortByIDMenuItem_byClickOut = null;private JCheckBoxMenuItem sortByUpdateTimeMenuItem_byClickOut = null;private JCheckBoxMenuItem sortByNameMenuItem_byClickOut = null;private JMenuItem showOnLinePersonInfoMenuItem_byClickOut = null;private JCheckBoxMenuItem showNoKnownPersonGroupInfoMenuItem_byClickOut =null;private JCheckBoxMenuItem showBlockNameListMenuItem_byClickOut = null;public FriendInfoTreeNodePopupMenu_byClickOut() {super();}public FriendInfoTreeNodePopupMenu_byClickOut(String label) {super(label);}public FriendInfoTreeNodePopupMenu_byClickOut(String label,IMSystemMainFrame oneIMSystemMainFrame) {super(label);this.oneIMSystemMainFrame=oneIMSystemMainFrame;createThisTreeNodePopupMenu_byClickOut();}public FriendInfoTreeNodePopupMenu_byClickOut(ImageIcon imageIcon) { super(imageIcon);}private void createThisTreeNodePopupMenu_byClickOut(){personHeadImageMenu_byClickOut = new SelfDefineJMenu();personHeadImageMenu_byClickOut.setText("头像显示方式");personHeadImageMenu_byClickOut.setIcon(new ImageIcon(getClass().getResource("/images/treePopMenu/headimage.jpg")));this.add(personHeadImageMenu_byClickOut);ButtonGroup oneButtonGroup=new ButtonGroup();bigHeadImageMenuItem_byClickOut = new SelfDefineJCheckBoxMenuItem();oneButtonGroup.add(bigHeadImageMenuItem_byClickOut);smallHeadImageMenuItem_byClickOut = new SelfDefineJCheckBoxMenuItem();oneButtonGroup.add(smallHeadImageMenuItem_byClickOut);standardHeadImageMenuItem_byClickOut = new SelfDefineJCheckBoxMenuItem();oneButtonGroup.add(standardHeadImageMenuItem_byClickOut);bigHeadImageMenuItem_byClickOut.setText("大头像");bigHeadImageMenuItem_byClickOut.addActionListener(newIMSystemMainFrame_ActionListenerEventHandler(oneIMSystemMainFrame,"bigHeadImageMenuItem_onClick"));smallHeadImageMenuItem_byClickOut.setText("小头像");smallHeadImageMenuItem_byClickOut.addActionListener(newIMSystemMainFrame_ActionListenerEventHandler(oneIMSystemMainFrame,"smallHeadImageMenuItem_onClick"));standardHeadImageMenuItem_byClickOut.setText("标准头像");standardHeadImageMenuItem_byClickOut.addActionListener(newIMSystemMainFrame_ActionListenerEventHandler(oneIMSystemMainFrame,"standardHeadImageMenuItem_onClick"));showMyHeadImageMenuItem_byClickOut = new SelfDefineJCheckBoxMenuItem();showMyHeadImageMenuItem_byClickOut.setText("显示我的头像");showMyHeadImageMenuItem_byClickOut.setSelected(true);showMyHeadImageMenuItem_byClickOut.addActionListener(newIMSystemMainFrame_ActionListenerEventHandler(oneIMSystemMainFrame,"showMyHeadImageMenuItem_onClick"));personHeadImageMenu_byClickOut.add(bigHeadImageMenuItem_byClickOut);personHeadImageMenu_byClickOut.add(smallHeadImageMenuItem_byClickOut);personHeadImageMenu_byClickOut.add(standardHeadImageMenuItem_byClickOut);personHeadImageMenu_byClickOut.addSeparator();personHeadImageMenu_byClickOut.add(showMyHeadImageMenuItem_byClickOut);nameInfoShowMenu_byClickOut = new SelfDefineJMenu();nameInfoShowMenu_byClickOut.setText("名称显示");this.add(nameInfoShowMenu_byClickOut);ButtonGroup twoButtonGroup=new ButtonGroup();showAnnotationInfoMenuItem_byClickOut = new SelfDefineJCheckBoxMenuItem();showAnnotationInfoMenuItem_byClickOut.setText("显示备注");showAnnotationInfoMenuItem_byClickOut.setSelected(true);showAnnotationInfoMenuItem_byClickOut.addActionListener(newIMSystemMainFrame_ActionListenerEventHandler(oneIMSystemMainFrame,"showAnnotationInfoMenuItem_onClick"));twoButtonGroup.add(showAnnotationInfoMenuItem_byClickOut);showLoveNameInfoMenuItem_byClickOut = new SelfDefineJCheckBoxMenuItem();twoButtonGroup.add(showLoveNameInfoMenuItem_byClickOut);showLoveNameInfoMenuItem_byClickOut.setText("显示昵称");showLoveNameInfoMenuItem_byClickOut.addActionListener(newIMSystemMainFrame_ActionListenerEventHandler(oneIMSystemMainFrame,"showLoveNameInfoMenuItem_onClick"));nameInfoShowMenu_byClickOut.add(showAnnotationInfoMenuItem_byClickOut);nameInfoShowMenu_byClickOut.add(showLoveNameInfoMenuItem_byClickOut);columnShowMenu_byClickOut = new SelfDefineJMenu();columnShowMenu_byClickOut.setText("列表显示");this.add(columnShowMenu_byClickOut);ButtonGroup threeButtonGroup = new ButtonGroup();singleShowMenuItem_byClickOut = new SelfDefineJCheckBoxMenuItem();threeButtonGroup.add(singleShowMenuItem_byClickOut);multiShowMenuItem_byClickOut = new SelfDefineJCheckBoxMenuItem();threeButtonGroup.add(multiShowMenuItem_byClickOut);singleShowMenuItem_byClickOut.setText("单列显示");singleShowMenuItem_byClickOut.setSelected(true);singleShowMenuItem_byClickOut.addActionListener(newIMSystemMainFrame_ActionListenerEventHandler(oneIMSystemMainFrame,"singleShowMenuItem_onClick"));columnShowMenu_byClickOut.add(singleShowMenuItem_byClickOut);multiShowMenuItem_byClickOut.setText("多列平铺");multiShowMenuItem_byClickOut.addActionListener(newIMSystemMainFrame_ActionListenerEventHandler(oneIMSystemMainFrame,"multiShowMenuItem_onClick"));columnShowMenu_byClickOut.add(multiShowMenuItem_byClickOut);columnShowMenu_byClickOut.addSeparator();ShowClearInfoMenuItem_byClickOut = new SelfDefineJCheckBoxMenuItem();ShowClearInfoMenuItem_byClickOut.setText("显示清爽资料");ShowClearInfoMenuItem_byClickOut.addActionListener(newIMSystemMainFrame_ActionListenerEventHandler(oneIMSystemMainFrame,"ShowClearInfoMenuItem_onClick"));columnShowMenu_byClickOut.add(ShowClearInfoMenuItem_byClickOut);slideEffectMenuItem_byClickOut = new SelfDefineJCheckBoxMenuItem();slideEffectMenuItem_byClickOut.setText("滑动效果");slideEffectMenuItem_byClickOut.addActionListener(newIMSystemMainFrame_ActionListenerEventHandler(oneIMSystemMainFrame,"slideEffectMenuItem_onClick"));columnShowMenu_byClickOut.addSeparator();columnShowMenu_byClickOut.add(slideEffectMenuItem_byClickOut);this.addSeparator();sortShowMenu_byClickOut.setText("排序显示");this.add(sortShowMenu_byClickOut);ButtonGroup fourButtonGroup = new ButtonGroup();sortByIDMenuItem_byClickOut = new SelfDefineJCheckBoxMenuItem();fourButtonGroup.add(sortByIDMenuItem_byClickOut);sortByUpdateTimeMenuItem_byClickOut = new SelfDefineJCheckBoxMenuItem();fourButtonGroup.add(sortByUpdateTimeMenuItem_byClickOut);sortByNameMenuItem_byClickOut = new SelfDefineJCheckBoxMenuItem();fourButtonGroup.add(sortByNameMenuItem_byClickOut);sortByIDMenuItem_byClickOut.setText("按身份标识排序");sortByUpdateTimeMenuItem_byClickOut.setText("按服务更新排序");sortByNameMenuItem_byClickOut.setText("按名称排序");sortShowMenu_byClickOut.add(sortByIDMenuItem_byClickOut);sortShowMenu_byClickOut.add(sortByUpdateTimeMenuItem_byClickOut);sortShowMenu_byClickOut.add(sortByNameMenuItem_byClickOut);this.addSeparator();showOnLinePersonInfoMenuItem_byClickOut = new SelfDefineJMenuItem();showOnLinePersonInfoMenuItem_byClickOut.setText("显示在线联系人");this.add(showOnLinePersonInfoMenuItem_byClickOut);this.addSeparator();showNoKnownPersonGroupInfoMenuItem_byClickOut = new SelfDefineJCheckBoxMenuItem();showNoKnownPersonGroupInfoMenuItem_byClickOut.setText("显示陌生人分组");showNoKnownPersonGroupInfoMenuItem_byClickOut.addActionListener(newIMSystemMainFrame_ActionListenerEventHandler(oneIMSystemMainFrame,"showNoKnownPersonGroupInfoMenuItem_onClick"));this.add(showNoKnownPersonGroupInfoMenuItem_byClickOut);showBlockNameListMenuItem_byClickOut = new SelfDefineJCheckBoxMenuItem();showBlockNameListMenuItem_byClickOut.setText("显示黑名单");showBlockNameListMenuItem_byClickOut.addActionListener(newIMSystemMainFrame_ActionListenerEventHandler(oneIMSystemMainFrame,"showBlockNameListMenuItem_onClick"));this.add(showBlockNameListMenuItem_byClickOut);}}4、FriendInfoTreeNodeSendMessagePopupMenu类(1)类名称为FriendInfoTreeNodeSendMessagePopupMenu,包名称为com.px1987.imsystem.client.frame.imsystemmainframe.tree,继承于ponent.SelfDefineJPopupMenu_ImageBar类(2)编程该类package com.px1987.imsystem.client.frame.imsystemmainframe.tree;import javax.swing.ImageIcon;import javax.swing.JMenu;import javax.swing.JMenuItem;import ponent.SelfDefineJMenu;import ponent.SelfDefineJMenuItem;import ponent.SelfDefineJPopupMenu_ImageBar;import com.px1987.imsystem.client.frame.IMSystemMainFrame;importcom.px1987.imsystem.client.frame.imsystemmainframe.treeevent.TreeNodeSendMessagePopup Menu_ActionListenerEventHandler;public class FriendInfoTreeNodeSendMessagePopupMenu extends SelfDefineJPopupMenu_ImageBar {private static final long serialVersionUID = 2935447048505581114L;private IMSystemMainFrame oneIMSystemMainFrame=null;private JMenuItem sendIMMessageToSomeOneMenuItem = null;private JMenuItem sendMessageByMobileMenuItem = null;private JMenuItem sendMailMenuItem = null;private JMenuItem sendFilesMenuItem = null;private JMenuItem talkMethodOneMenuItem =null;private JMenuItem talkMethodTwoMenuItem = null;private JMenuItem someOneFriendMenuItem = null;private JMenuItem moveToBlackListMenuItem = null;private JMenuItem deleteSomeOneFriendMenuItem = null;private JMenuItem noticeSomeOneMenuItem = null;private JMenuItem updateNameMenuItem = null;private JMenuItem setupPrivateMenuItem = null;private JMenuItem messageRecordMenuItem = null;private JMenuItem viewInfoMenuItem =null;public FriendInfoTreeNodeSendMessagePopupMenu() {super();}public FriendInfoTreeNodeSendMessagePopupMenu(String label) {super(label);}public FriendInfoTreeNodeSendMessagePopupMenu(String label,IMSystemMainFrame oneIMSystemMainFrame) {super(label);this.oneIMSystemMainFrame=oneIMSystemMainFrame;createThisTreeNodeSendMessagePopupMenu();}public FriendInfoTreeNodeSendMessagePopupMenu(ImageIcon imageIcon) { super(imageIcon);}private void createThisTreeNodeSendMessagePopupMenu(){sendIMMessageToSomeOneMenuItem = new SelfDefineJMenuItem();sendIMMessageToSomeOneMenuItem.setIcon(new ImageIcon(getClass().getResource( "/images/chatFrameImage/popUpMenu/3.jpg")));sendIMMessageToSomeOneMenuItem.setText("发送即时消息");sendIMMessageToSomeOneMenuItem.addActionListener(newTreeNodeSendMessagePopupMenu_ActionListenerEventHandler(oneIMSystemMainFrame, "sendIMMessageToSomeOneMenuItem_onClick"));this.add(sendIMMessageToSomeOneMenuItem);sendMessageByMobileMenuItem = new SelfDefineJMenuItem();sendMessageByMobileMenuItem.setText("发送手机信息");sendMessageByMobileMenuItem.setIcon(new ImageIcon(getClass().getResource("/images/chatFrameImage/popUpMenu/4.jpg")));this.add(sendMessageByMobileMenuItem);sendMailMenuItem = new SelfDefineJMenuItem();sendMailMenuItem.setText("发送电子邮件");this.add(sendMailMenuItem);talkMethodOneMenuItem = new SelfDefineJMenuItem(); talkMethodOneMenuItem.setText("交谈方式一");JMenu talkByVideoMenu = new SelfDefineJMenu();talkByVideoMenu.setText("影音交谈");talkByVideoMenu.add(talkMethodOneMenuItem); talkMethodTwoMenuItem = new SelfDefineJMenuItem(); talkMethodTwoMenuItem.setText("交谈方式二");talkByVideoMenu.add(talkMethodTwoMenuItem);this.add(talkByVideoMenu);sendFilesMenuItem = new SelfDefineJMenuItem();sendFilesMenuItem.setText("发送文件");this.add(sendFilesMenuItem);this.addSeparator();someOneFriendMenuItem = new SelfDefineJMenuItem(); someOneFriendMenuItem.setText("朋友");JMenu removeSomeOneMenu = new SelfDefineJMenu(); removeSomeOneMenu.setText("移动联系人至"); removeSomeOneMenu.setIcon(new ImageIcon(getClass().getResource("/images/chatFrameImage/popUpMenu/5.jpg"))); removeSomeOneMenu.add(someOneFriendMenuItem);this.add(removeSomeOneMenu);moveToBlackListMenuItem = new SelfDefineJMenuItem(); moveToBlackListMenuItem.setText("移至黑名单");this.add(moveToBlackListMenuItem); deleteSomeOneFriendMenuItem = new SelfDefineJMenuItem(); deleteSomeOneFriendMenuItem.setText("删除好友"); deleteSomeOneFriendMenuItem.setIcon(new ImageIcon(getClass().getResource( "/images/chatFrameImage/popUpMenu/6.jpg")));。

仿QQ菜单控件说明

仿QQ菜单控件说明
语法:Object.CtlistBar1.AddListImage (nIndex,strText,ImageIndex) 或
Object.CtlistBar1.AddListItem (nIndex,strText,Object.CtlistBar1.ListImage(index))
例如:thisform.CtlistBar1.AddListImage (1,&#39;我的电脑&#39;,1) 或
Image1-6 Picture 设置预先在控件中加载的6幅图片。
ListBarStyle integer 设置控件纵向或是横向显示。
ListBackColor long 设置控件的背景颜色。
ListForeColor long 设置分组中项目文字的颜色。
ListScrollSpeed integer 设置项目滚动的速度。
ButtonSize integer 设置上下滚动按钮大小。
GradientFill boolean 设置控件背景是否显示渐变色。
GradColorFrom long 设置渐变色的起始颜色。
GradColorTo long 设置渐变色的结束颜色。
IconSize integer 设置图标显示模式是大图标或小图标。
该事件通常用来设置控件的外观。
(2)ItemClick 事件,单击项目窗口中的按钮触发此事件。例如:
LPARAMETERS nlist, nitem
DO CASE
Case nlist=1.and.nitem=3
……&amp;&amp;点击第一个项目窗口内第三个按钮执行的语句
Case nlist=2.and.nitem=2

悬浮窗的使用方法

悬浮窗的使用方法

悬浮窗的使用方法
悬浮窗是一种应用程序在主屏幕上方悬浮显示的功能。

它可以帮助用户在使用其他应用程序时,随时查看重要信息或快速启动某个应用程序,而不需要退出当前应用程序。

以下是悬浮窗的使用方法:
1. 打开需要显示悬浮窗的应用程序。

2. 在应用程序中,点击悬浮窗图标。

如果应用程序没有自带悬浮窗功能,则需要用悬浮窗应用程序。

3. 在悬浮窗中,可以查看消息、通知、快捷操作等信息。

可以通过悬浮窗中的操作按钮。

4. 如果需要关闭悬浮窗,可以点击悬浮窗中的关闭按钮或者在应用程序中点击悬浮窗图标,然后选择“退出悬浮窗”。

需要注意的是,悬浮窗可能会影响其他应用程序的使用效果,因此建议在必要时使用,避免影响正常使用。

此外,不同设备和操作系统版本的悬浮窗功能可能有所不同,具体使用方法可以参考设备和操作系统的相关说明。

《蓝梦教育集团即时通讯系统》(仿腾讯QQ)——构建出客户端登录主窗口有关的各个对话框程序类(第5部分)

《蓝梦教育集团即时通讯系统》(仿腾讯QQ)——构建出客户端登录主窗口有关的各个对话框程序类(第5部分)

J2EE课程设计实训教学示例项目《蓝梦教育集团即时通讯系统》(仿腾讯QQ)——构建出客户端登录主窗口有关的各个对话框程序类(第5部分)12、添加好友信息的对话框FindNewFriendAndGroupDialog的事件处理类(1)类名称为FindNewFriendAndGroupDialog_ActionListenerEventHandler,实现java.awt.event.ActionListener接口,包名称为com.px1987.imsystem.client.dialog.eventpackage com.px1987.imsystem.client.dialog.event;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import ng.reflect.InvocationTargetException;import ng.reflect.Method;import java.util.Iterator;import java.util.List;import com.px1987.imsystem.client.dialog.FindNewFriendAndGroupDialog;import com.px1987.imsystem.client.exception.IMSystemException;import erInfoBaseVO;public class FindNewFriendAndGroupDialog_ActionListenerEventHandler implements ActionListener {private FindNewFriendAndGroupDialog eventSourceContainer = null;private String eventHandlerMethodName = null;public FindNewFriendAndGroupDialog_ActionListenerEventHandler() {super();}publicFindNewFriendAndGroupDialog_ActionListenerEventHandler(FindNewFriendAndGroupDialog eventSourceContainer,String eventHandlerMethodName) {super();this.eventSourceContainer = eventSourceContainer;this.eventHandlerMethodName = eventHandlerMethodName;}@SuppressWarnings("unchecked")public void actionPerformed(ActionEvent actionEventObject) {Class currentEventHandlerClass = this.getClass();Method eventHandlerMmethod = null;try { //获得事件处理方法eventHandlerMmethod = currentEventHandlerClass.getMethod(this.eventHandlerMethodName, new Class[] {actionEventObject.getClass()});} catch (SecurityException exception) {exception.printStackTrace();System.out.println("出现了SecurityException异常错误,错误信息为:" +exception.getMessage());} catch (NoSuchMethodException exception) {exception.printStackTrace();System.out.println("出现了NoSuchMethodException异常错误,错误信息为:" +exception.getMessage());}try { //调用指定的事件处理方法eventHandlerMmethod.invoke(this, new Object[] {actionEventObject});} catch (InvocationTargetException exception) {exception.printStackTrace();System.out.println("出现了InvocationTargetException异常错误,错误信息为:" + exception.getMessage());} catch (IllegalArgumentException exception) {exception.printStackTrace();System.out.println("出现了IllegalArgumentException异常错误,错误信息为:" + exception.getMessage());} catch (IllegalAccessException exception) {exception.printStackTrace();System.out.println("出现了IllegalAccessException异常错误,错误信息为:" +exception.getMessage());}}public void cancelButton_onClick(ActionEvent e) {eventSourceContainer.dispose();}public void addFriendButton_onClick(ActionEvent e) {}public void closeButton_onClick(ActionEvent e) {eventSourceContainer.dispose();}public void previousButton_onClick(ActionEvent e) {//下面的代码是动态除掉原来的“查找结果”两个面板eventSourceContainer.getFindTabbedPane().remove(eventSourceContainer.getFindFriendResultP anel());eventSourceContainer.getContentPanel().remove(eventSourceContainer.getFindResultButtonPan el());//下面的代码是动态地添加“查找表单”的面板eventSourceContainer.getFindTabbedPane().add(eventSourceContainer.getFindFriendPanel(), "查找联系人", 0); //添加到第一个位置处eventSourceContainer.getFindTabbedPane().setSelectedComponent(eventSourceContainer.getFin dFriendPanel()); //选中该面板eventSourceContainer.getContentPanel().add(eventSourceContainer.getButtonPanel(), java.awt.BorderLayout.SOUTH);//动态更新和显示eventSourceContainer.invalidate();eventSourceContainer.repaint();eventSourceContainer.validate();}public void findButton_onClick(ActionEvent e) {String userID=eventSourceContainer.getUserIDTextField().getText(); //获得输入的帐号String userAliaoName=eventSourceContainer.getFriendUserNameTextField().getText(); //获得输入的昵称List<UserInfoBaseVO> allFriendInfoInList=null;try {allFriendInfoInList=eventSourceContainer.getOneHttpClientFindFriendInfoRequest().doReturnFriendInfo(userID, eventSourceContainer.getSearchUserInfoType(),userAliaoName);} catch (IMSystemException exception) {exception.printStackTrace();System.out.println("出现了OASystemException异常错误,错误信息为:" +exception.getMessage());}eventSourceContainer.findResultPanelInit();//下面的代码实现将allFriendInfoInList集合中的数据导入到二维数组中eventSourceContainer.getFindFriendResultPanel().setTableData(newObject[allFriendInfoInList.size()][3]);Iterator<UserInfoBaseVO> allItems=allFriendInfoInList.iterator();int index=0;while(allItems.hasNext()){UserInfoBaseVO oneFindFriendInfoVO=(UserInfoBaseVO)allItems.next(); eventSourceContainer.getFindFriendResultPanel().getTableData()[index][0]=oneFindFriendInfo VO.getUserIMCode();eventSourceContainer.getFindFriendResultPanel().getTableData()[index][1]=oneFindFriendInfo VO.getUserAliaoName();eventSourceContainer.getFindFriendResultPanel().getTableData()[index][2]=oneFindFriendInfo VO.getUserComeFrom();index++;}eventSourceContainer.getFindFriendResultPanel().createFindFriendResultJTable(); //创建出查询结果的表格//下面的代码是动态除掉原来的“查找表单”两个面板eventSourceContainer.getFindTabbedPane().remove(eventSourceContainer.getFindFriendPanel() );eventSourceContainer.getContentPanel().remove(eventSourceContainer.getButtonPanel());//下面的代码是动态地添加“查找结果”的面板eventSourceContainer.getFindTabbedPane().add(eventSourceContainer.getFindFriendResultPane l(), "查找联系人",0); //添加到第一个位置处eventSourceContainer.getFindTabbedPane().setSelectedComponent(eventSourceContainer.getFin dFriendResultPanel()); //选中该面板eventSourceContainer.getContentPanel().add(eventSourceContainer.getFindResultButtonPanel(),java.awt.BorderLayout.SOUTH);//动态更新和显示eventSourceContainer.invalidate();eventSourceContainer.repaint();eventSourceContainer.validate();}}(2)类名称为FindNewFriendAndGroupDialog_ItemListenerEventHandler,实现java.awt.event.ActionListener接口,包名称为com.px1987.imsystem.client.dialog.eventpackage com.px1987.imsystem.client.dialog.event;import java.awt.event.ItemEvent;import java.awt.event.ItemListener;import ng.reflect.InvocationTargetException;import ng.reflect.Method;import com.px1987.imsystem.client.constant.IMSystemClientAppConstant;import com.px1987.imsystem.client.dialog.FindNewFriendAndGroupDialog;public class FindNewFriendAndGroupDialog_ItemListenerEventHandler implements ItemListener {private FindNewFriendAndGroupDialog eventSourceContainer = null;private String eventHandlerMethodName = null;public FindNewFriendAndGroupDialog_ItemListenerEventHandler() {super();}publicFindNewFriendAndGroupDialog_ItemListenerEventHandler(FindNewFriendAndGroupDialogeventSourceContainer, String eventHandlerMethodName) { super();this.eventSourceContainer = eventSourceContainer;this.eventHandlerMethodName = eventHandlerMethodName;}@SuppressWarnings("unchecked")public void itemStateChanged(ItemEvent itemEventObject) {Class currentEventHandlerClass = this.getClass();Method eventHandlerMmethod = null;try { //获得事件处理方法eventHandlerMmethod = currentEventHandlerClass.getMethod(this.eventHandlerMethodName, new Class[] {itemEventObject.getClass()});} catch (SecurityException exception) {exception.printStackTrace();System.out.println("出现了SecurityException异常错误,错误信息为:" +exception.getMessage());} catch (NoSuchMethodException exception) {exception.printStackTrace();System.out.println("出现了NoSuchMethodException异常错误,错误信息为:"+ exception.getMessage());}try { //调用指定的事件处理方法eventHandlerMmethod.invoke(this, new Object[] {itemEventObject});} catch (InvocationTargetException exception) {exception.printStackTrace();System.out.println("出现了InvocationTargetException异常错误,错误信息为:" + exception.getMessage());} catch (IllegalArgumentException exception) {exception.printStackTrace();System.out.println("出现了IllegalArgumentException异常错误,错误信息为:" + exception.getMessage());} catch (IllegalAccessException exception) {exception.printStackTrace();System.out.println("出现了IllegalAccessException异常错误,错误信息为:" +exception.getMessage());}}public void findExactRadioButton_itemStateChanged(ItemEvent e) {if (eventSourceContainer.getFindExactRadioButton().isSelected()) {eventSourceContainer.setSearchUserInfoType(IMSystemClientAppConstant.SearchUserInfoType_findExactRadioButton);}}public void findByConditionRadioButton_itemStateChanged(ItemEvent e) {if (eventSourceContainer.getFindByConditionRadioButton().isSelected()) {eventSourceContainer.setSearchUserInfoType(IMSystemClientAppConstant.SearchUserInfoType_findByConditionRadioButton);}}}13、设置聊天信息主窗口内聊天信息文字的字体对话类(1)类名称为FontChooserDialog,实现java.awt.event.ActionListener接口,包名称为com.px1987.imsystem.client.dialog,继承于javax.swing.JDialog类(2)编程该类的代码package com.px1987.imsystem.client.dialog;import java.awt.GraphicsEnvironment;import javax.swing.JDialog;import javax.swing.JFrame;import javax.swing.ListModel;import java.awt.Font;import javax.swing.JPanel;import java.awt.Rectangle;import javax.swing.JScrollPane;import javax.swing.BorderFactory;import javax.swing.border.TitledBorder;import java.awt.Color;import javax.swing.JList;import javax.swing.JLabel;import java.awt.event.KeyAdapter;import java.awt.event.KeyEvent;import java.awt.event.WindowAdapter;import java.awt.event.WindowEvent;import javax.swing.JTextField;import javax.swing.border.BevelBorder;import javax.swing.border.SoftBevelBorder; import javax.swing.JButton;import javax.swing.SwingConstants;public class FontChooserDialog extends JDialog { private static final long serialVersionUID = 1L;/*** 界面设计需要* */private JPanel jPanel = null;private JScrollPane jScrollPane = null;private JPanel jPanel1 = null;private JLabel jLabel = null;private JLabel jLabel1 = null;private JLabel jLabel2 = null;private JTextField fontNameText = null;private JTextField fontItalicText = null;private JTextField fontSizeText = null;private JList fontNameList = null;private JList fontItalicList = null;private JList fontSizeList = null;private JPanel jPanel2 = null;private JButton okButton = null;private JButton regitButton = null;private JButton cancleButton = null;private JScrollPane jScrollPane1 = null;private JScrollPane jScrollPane2 = null;private JScrollPane jScrollPane3 = null;private static JLabel fontStyle = null;/*** 对话框内广告文字的默认字体变量* */private Font defaultFontInThisDialog = new Font("宋体", Font.PLAIN, 12);/*** 字体对话框示例标签的默认字体变量* */private Font fontExampleLabelDefaultFont = new Font("宋体", Font.PLAIN, 12); /*** 以防止事件重复调用或不必要的更改,定义两个boolean变量分别* 为:fontNameList和fontSizeList判断* 等于true则循环调用,false则不* */private boolean nameJuge = true;private boolean sizeJuge = true;public FontChooserDialog(){this(null);}public FontChooserDialog(JFrame jframe){this(jframe,true);}public FontChooserDialog(JFrame jframe,boolean boo){ this(jframe,boo,null);}public FontChooserDialog(JFrame jframe,boolean boo,Font font){ super(jframe,boo);initialize();initializeFont(font);this.setLocationRelativeTo(jframe);}private void initialize() {this.setContentPane(getJPanel());this.setFont(defaultFontInThisDialog);this.setBounds(new Rectangle(0, 0, 430, 335));this.setTitle("字体选择对话框");this.addWindowListener(new WindowAdapter(){public void windowClosing(WindowEvent e) {closeWindow();}});}private JPanel getJPanel() {if (jPanel == null) {jPanel = new JPanel();jPanel.setLayout(null);jPanel.setFont(new Font("Dialog", Font.PLAIN, 12));jPanel.add(getJPanel1(), null);jPanel.add(getJPanel2(), null);jPanel.add(getOkButton(), null);jPanel.add(getRegitButton(), null);jPanel.add(getCancleButton(), null);}return jPanel;}private JScrollPane getJScrollPane() {if (jScrollPane == null) {fontStyle = new JLabel();fontStyle.setText("你好!天生我才必有用!Hello World!");fontStyle.setFont(defaultFontInThisDialog);fontStyle.setHorizontalAlignment(SwingConstants.CENTER);fontStyle.setHorizontalTextPosition(SwingConstants.CENTER);jScrollPane = new JScrollPane();jScrollPane.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));jScrollPane.setViewportView(fontStyle);jScrollPane.setBounds(new Rectangle(5, 20, 400, 60));}return jScrollPane;}private JPanel getJPanel1() {if (jPanel1 == null) {jLabel2 = new JLabel();jLabel2.setBounds(new Rectangle(285, 5, 120, 15));jLabel2.setFont(defaultFontInThisDialog);jLabel2.setText("大小:");jLabel1 = new JLabel();jLabel1.setBounds(new Rectangle(160, 5, 120, 15));jLabel1.setFont(defaultFontInThisDialog);jLabel1.setText("字型:");jLabel = new JLabel();jLabel.setBounds(new Rectangle(5, 5, 150, 15));jLabel.setDisplayedMnemonic(KeyEvent.VK_UNDEFINED);jLabel.setFont(defaultFontInThisDialog);jLabel.setText("字体:");jPanel1 = new JPanel();jPanel1.setLayout(null);jPanel1.setBounds(new Rectangle(5, 5, 410, 175));jPanel1.setBorder(new SoftBevelBorder(SoftBevelBorder.LOWERED));jPanel1.add(jLabel, null);jPanel1.add(jLabel1, null);jPanel1.add(jLabel2, null);jPanel1.add(getFontNameText(), null);jPanel1.add(getFontItalicText(), null);jPanel1.add(getFontSizeText(), null);jPanel1.add(getJScrollPane1(), null);jPanel1.add(getJScrollPane2(), null);jPanel1.add(getJScrollPane3(), null);}return jPanel1;}private JTextField getFontNameText() {if (fontNameText == null) {fontNameText = new JTextField();fontNameText.setBounds(new Rectangle(5, 25, 150, 20));fontNameText.setFont(defaultFontInThisDialog);fontNameText.addKeyListener(new KeyAdapter(){public void keyTyped(KeyEvent e) {String oldText = fontNameText.getText();String newText = "";if("".equals(fontNameText.getSelectedText()) && null == fontNameText.getSelectedText()){newText = fontNameText.getText()+e.getKeyChar();}else{newText = oldText.substring(0,fontNameText.getSelectionStart())+e.getKeyChar()+oldText.substring(fontN ameText.getSelectionEnd());}nameJuge = false;fontNameList.setSelectedValue(getLateIndex(fontNameList,newText),true);nameJuge = true;}});}return fontNameText;}private JTextField getFontItalicText() {if (fontItalicText == null) {fontItalicText = new JTextField();fontItalicText.setBounds(new Rectangle(160, 25, 120, 20));fontItalicText.setFont(defaultFontInThisDialog);fontItalicText.setEnabled(false);}return fontItalicText;}private JTextField getFontSizeText() {if (fontSizeText == null) {fontSizeText = new JTextField();fontSizeText.setBounds(new Rectangle(285, 25, 120, 20));fontSizeText.setFont(defaultFontInThisDialog);fontSizeText.setColumns(4);fontSizeText.addKeyListener(new KeyAdapter(){public void keyTyped(KeyEvent e) {String oldText = fontSizeText.getText();String newText = "";if("".equals(fontSizeText.getSelectedText()) && null == fontSizeText.getSelectedText()){newText = fontSizeText.getText()+e.getKeyChar();}else{newText = oldText.substring(0,fontSizeText.getSelectionStart())+e.getKeyChar()+oldText.substring(fontSize Text.getSelectionEnd());}sizeJuge = false;fontSizeList.setSelectedValue(getLateIndex(fontSizeList,newText),true);if(newText.matches("(\\d)+")){fontStyle.setFont(newFont(fontStyle.getFont().getFontName(),fontStyle.getFont().getStyle(),Integer.parseInt(newText)) );}sizeJuge = true;}});}return fontSizeText;}private JList getFontNameList() {if (fontNameList == null) {fontNameList = new JList(GraphicsEnvironment.getLocalGraphicsEnvironment() .getAvailableFontFamilyNames());fontNameList.setFont(defaultFontInThisDialog);fontNameList.addListSelectionListener(new javax.swing.event.ListSelectionListener() {public void valueChanged(javax.swing.event.ListSelectionEvent e) {if(nameJuge){fontNameText.setText(fontNameList.getSelectedValue().toString());}fontStyle.setFont(newFont(fontNameList.getSelectedValue().toString(),fontStyle.getFont().getStyle(),fontStyle.getFont ().getSize()));}});}return fontNameList;}private JList getFontItalicList() {if (fontItalicList == null) {fontItalicList = new JList(new String[]{"Plain", "Bold", "Italic","Bold Italic"});fontItalicList.setFont(defaultFontInThisDialog);fontItalicList.addListSelectionListener(new javax.swing.event.ListSelectionListener() {public void valueChanged(javax.swing.event.ListSelectionEvent e) {fontItalicText.setText(fontItalicList.getSelectedValue().toString());fontStyle.setFont(newFont(fontStyle.getFont().getFontName(),fontItalicList.getSelectedIndex(),fontStyle.getFont().get Size()));}});}return fontItalicList;}private JList getFontSizeList() {if (fontSizeList == null) {fontSizeList = new JList(new String[]{"3", "4", "5", "6", "7", "8", "9", "10","11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "22","24", "27", "30", "34", "39", "45", "51", "60"});fontSizeList.setFont(defaultFontInThisDialog);fontSizeList.addListSelectionListener(new javax.swing.event.ListSelectionListener() {public void valueChanged(javax.swing.event.ListSelectionEvent e) {if(sizeJuge){fontSizeText.setText(fontSizeList.getSelectedValue().toString());}fontStyle.setFont(newFont(fontStyle.getFont().getFontName(),fontStyle.getFont().getStyle(),Integer.parseInt(fontSizeL ist.getSelectedValue().toString())));}});}return fontSizeList;}private JPanel getJPanel2() {if (jPanel2 == null) {jPanel2 = new JPanel();jPanel2.setLayout(null);jPanel2.setBounds(new Rectangle(3, 180, 414, 90));jPanel2.setBorder(BorderFactory.createTitledBorder(null, "效果预览",TitledBorder.DEFAULT_JUSTIFICATION,TitledBorder.DEFAULT_POSITION,defaultFontInThisDialog,new Color(51, 51, 51)));jPanel2.add(getJScrollPane(), null);}return jPanel2;}private JButton getOkButton() {if (okButton == null) {okButton = new JButton();okButton.setBounds(new Rectangle(215, 275, 60, 20));okButton.setFont(defaultFontInThisDialog);okButton.setText("确定");okButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) {closeWindow();}});}return okButton;}private JButton getRegitButton() {if (regitButton == null) {regitButton = new JButton();regitButton.setBounds(new Rectangle(285, 275, 60, 20));regitButton.setFont(defaultFontInThisDialog);regitButton.setText("重置");regitButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) {initializeFont(null);}});}return regitButton;}private JButton getCancleButton() {if (cancleButton == null) {cancleButton = new JButton();cancleButton.setBounds(new Rectangle(355, 275, 60, 20));cancleButton.setFont(defaultFontInThisDialog);cancleButton.setText("取消");cancleButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) {closeWindow();}});}return cancleButton;}private JScrollPane getJScrollPane1() {if (jScrollPane1 == null) {jScrollPane1 = new JScrollPane();jScrollPane1.setBounds(new Rectangle(5, 50, 150, 120));jScrollPane1.setViewportView(getFontNameList());}return jScrollPane1;}private JScrollPane getJScrollPane2() {if (jScrollPane2 == null) {jScrollPane2 = new JScrollPane();jScrollPane2.setBounds(new Rectangle(160, 50, 120, 120));jScrollPane2.setViewportView(getFontItalicList());}return jScrollPane2;}private JScrollPane getJScrollPane3() {if (jScrollPane3 == null) {jScrollPane3 = new JScrollPane();jScrollPane3.setBounds(new Rectangle(285, 50, 120, 120));jScrollPane3.setViewportView(getFontSizeList());}return jScrollPane3;}/*** 默认的字体初始化方法* */private void initializeFont(Font font){if(font!=null){fontExampleLabelDefaultFont = font;fontStyle.setFont(fontExampleLabelDefaultFont);}fontStyle.setFont(fontExampleLabelDefaultFont);fontNameList.setSelectedValue(fontExampleLabelDefaultFont.getFontName(), true);fontSizeList.setSelectedValue(newInteger(fontExampleLabelDefaultFont.getSize()).toString(), true);fontItalicList.setSelectedIndex(fontExampleLabelDefaultFont.getStyle());}/*** 判断里给定的值最近的索引* */private Object getLateIndex(JList jlist,String str){ListModel list = jlist.getModel();if(str.matches("(\\d)+")){for(int i = list.getSize()-1;i>=0;i--){if(Integer.parseInt(list.getElementAt(i).toString())<=Integer.parseInt(str)){return list.getElementAt(i);}}}else {for(int i = list.getSize()-2;i>=0;i--){if(pareToIgnoreCase(list.getElementAt(i).toString())==0){return list.getElementAt(i);}else if(pareToIgnoreCase(list.getElementAt(i).toString())>0){return list.getElementAt(i+1);}}}return list.getElementAt(0);}/*** 窗体关闭方法!* */private void closeWindow(){this.setVisible(false);}public Font getUserSelectFontInThisDialog(){return fontStyle.getFont();}}。

Android创建悬浮窗的完整步骤

Android创建悬浮窗的完整步骤

Android创建悬浮窗的完整步骤在Android中想要创建悬浮窗分为三步1.申请权限2.使⽤服务启动悬浮窗3.设置悬浮窗参数并添加进WindowManager下⾯话不多说了,来⼀起看看详细的实现过程申请权限⾸先需要申请悬浮窗权限,在清单⽂件中 manifest 下添加<!-- 低版本悬浮窗所需权限 --><uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>在Activity中动态申请权限public class MainActivity extends Activity {/** 悬浮窗权限标识码 */public static final int CODE_WINDOW = 0;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);// 申请悬浮窗权限if (Build.VERSION.SDK_INT >= 23) {if (!Settings.canDrawOverlays(this)) {Toast.makeText(this, "请打开此应⽤悬浮窗权限-Shendi", Toast.LENGTH_SHORT).show();startActivityForResult(new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + getPackageName())), CODE_WINDOW); }}// 关闭当前activity,这样只显⽰悬浮窗finish();}// 权限申请成功后的回调@Overrideprotected void onActivityResult(int requestCode, int resultCode, Intent data) {switch (requestCode) {// 不给权限就退出case Permission.CODE_WINDOW:if (resultCode != Activity.RESULT_OK) System.exit(0);break;default:Toast.makeText(this, "未知权限回调: " + requestCode, Toast.LENGTH_SHORT).show();}}}使⽤服务启动悬浮窗对于悬浮窗的操作主要使⽤ WindowManager创建⼀个服务,并在清单⽂件中注册public class TestService extends Service {@Overridepublic int onStartCommand(Intent intent, int flags, int startId) {return super.onStartCommand(intent, flags, startId);}@Overridepublic IBinder onBind(Intent intent) {return null;}}在清单⽂件的Application中注册服务<service android:name=".TestService" />在Activity中启动服务Intent intent = new Intent(this, TestService.class);startService(intent);接下来需要创建悬浮窗的界⾯,这⾥⽅便演⽰直接使⽤代码创建也可以使⽤inflate函数将xml⽂件变view对象View.inflate(context, yout.main_activity, null);在服务的onStartCommand函数中内容如下@Overridepublic int onStartCommand(Intent intent, int flags, int startId) {Button btn = new Button(this);btn.setText("hello,world");return super.onStartCommand(intent, flags, startId);}设置悬浮窗参数并添加进WindowManager这⾥直接上代码,看注释@Overridepublic int onStartCommand(Intent intent, int flags, int startId) {Button btn = new Button(this);btn.setText("hello,world");// 获取WindowManagerWindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE); // 创建布局参数youtParams params = new youtParams(); /** 设置参数 */params.type = Build.VERSION.SDK_INT >= Build.VERSION_CODES.O ?youtParams.TYPE_APPLICATION_OVERLAY :youtParams.TYPE_PHONE;params.format = PixelFormat.RGBA_8888;// 设置窗⼝的⾏为准则params.flags = youtParams.FLAG_NOT_FOCUSABLE;//设置透明度params.alpha = 1.0f;//设置内部视图对齐⽅式,这边位置为左边靠上params.gravity = Gravity.LEFT | Gravity.TOP;//窗⼝的左上⾓坐标params.x = 0;params.y = 0;//设置窗⼝的宽⾼,这⾥为⾃动params.width = youtParams.WRAP_CONTENT;params.height = youtParams.WRAP_CONTENT;// 添加进WindowManagerwm.addView(btn, params);return super.onStartCommand(intent, flags, startId);}完整代码如下TestActivitypackage shendi.app.game.robot;import android.app.Activity;import android.content.Intent;import .Uri;import android.os.Build;import android.os.Bundle;import android.provider.Settings;import android.widget.Toast;public class TestActivity extends Activity {/** 悬浮窗权限标识码 */public static final int CODE_WINDOW = 0;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);// 申请悬浮窗权限if (Build.VERSION.SDK_INT >= 23) {if (!Settings.canDrawOverlays(this)) {Toast.makeText(this, "请打开此应⽤悬浮窗权限-Shendi", Toast.LENGTH_SHORT).show();startActivityForResult(new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + getPackageName())), CODE_WINDOW); }}Intent intent = new Intent(this, TestService.class);startService(intent);// 关闭当前activity,这样只显⽰悬浮窗finish();}// 权限申请成功后的回调@Overrideprotected void onActivityResult(int requestCode, int resultCode, Intent data) {switch (requestCode) {// 不给权限就退出case Permission.CODE_WINDOW:if (resultCode != Activity.RESULT_OK) System.exit(0);break;default:Toast.makeText(this, "未知权限回调: " + requestCode, Toast.LENGTH_SHORT).show();}}}TestServicepackage shendi.app.game.robot;import android.app.Service;import android.content.Intent;import android.graphics.PixelFormat;import android.os.Build;import android.os.IBinder;import android.view.Gravity;import android.view.WindowManager;import android.widget.Button;public class TestService extends Service {@Overridepublic int onStartCommand(Intent intent, int flags, int startId) {Button btn = new Button(this);btn.setText("hello,world");// 获取WindowManagerWindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);// 创建布局参数youtParams params = new youtParams();/** 设置参数 */params.type = Build.VERSION.SDK_INT >= Build.VERSION_CODES.O ?youtParams.TYPE_APPLICATION_OVERLAY :youtParams.TYPE_PHONE;params.format = PixelFormat.RGBA_8888;// 设置窗⼝的⾏为准则params.flags = youtParams.FLAG_NOT_FOCUSABLE;//设置透明度params.alpha = 1.0f;//设置内部视图对齐⽅式,这边位置为左边靠上params.gravity = Gravity.LEFT | Gravity.TOP;//窗⼝的左上⾓坐标params.x = 0;params.y = 0;//设置窗⼝的宽⾼,这⾥为⾃动params.width = youtParams.WRAP_CONTENT;params.height = youtParams.WRAP_CONTENT;// 添加进WindowManagerwm.addView(btn, params);return super.onStartCommand(intent, flags, startId);}@Overridepublic IBinder onBind(Intent intent) {return null;}}运⾏ app,可以在屏幕左上⾓看到 hello,world的按钮悬浮拖动效果给悬浮组件添加触碰事件可以实现拖动效果,按钮组件不适⽤这⾥给出简单的实现代码⽚段private int upX, upY;// 视图移动处理view.setOnTouchListener(new View.OnTouchListener() {@Overridepublic boolean onTouch(View v, MotionEvent event) {switch (event.getActionMasked()) {case MotionEvent.ACTION_DOWN:upX = (int) event.getRawX();upY = (int) event.getRawY();break;case MotionEvent.ACTION_MOVE:// 与上⼀次位置相差不到5则不移动if (event.getRawX() - upX > 5 || event.getRawY() - upY > 5) {params.x = (int) event.getRawX();params.y = (int) event.getRawY();wm.updateViewLayout(view, params);}break;case MotionEvent.ACTION_UP:// 相差不到5则代表点击if (event.getRawX() - upX < 5 && event.getRawY() - upY < 5) {// TODO}break;}return false;}});移除悬浮窗可以在 onDestry 函数中进⾏移除@Overridepublic void onDestroy() {wm.removeView(view);super.onDestroy();}总结到此这篇关于Android创建悬浮窗的⽂章就介绍到这了,更多相关Android悬浮窗内容请搜索以前的⽂章或继续浏览下⾯的相关⽂章希望⼤家以后多多⽀持!。

仿QQ聊天软件MyQQ源代码教学北大青鸟完整版

仿QQ聊天软件MyQQ源代码教学北大青鸟完整版
制作具体软件时开发步骤的具体实施方法瀑布模型瀑布模型瀑布模型线性顺序模型将每个阶段都清楚定义了起止点产生明确的交付成果阶段之间通过文档进行沟通每个阶段都必需完成全部规定的任务文档后才能够进每个阶段都必需完成全部规定的任务文档后才能够进入下一个阶段设计可行性研究与计划需求分析可行性研究报告需求说明书开发测试维护设计文档程序测试报告可行性研究与计划阶段确定项目目的了解系统中客户的期望确定系统的规模论证项目可行性技术可行性经济可行性操作可行性社会可行性需求分析阶段需求是产品的根源需求工作的优劣对产品影响最大获取需求客户同行专家已经存在的同类软件产品行业标准规则行业标准规则internet相关资料可能遇到的问题用户说不清楚需求误解需求分析需求功能需求记录在客户需求说明书中需求分析阶段文档介绍产品功能性需求需求说明书产品介绍产品应当遵循的标准和规范其他需求产品非功能性需求需求分析阶段设计阶段目的
课时 2 2 4
4
4
4 4
软件开发流程
比尔盖子是一名建筑工人
起初只干一些比较简单的 建筑工作 凭个人技术和经验,不需要特 别设计,可以顺利完成
如同编写早期比较小的程序
软件开发流程
新任务:建造一间非常美 丽而完整的房间 工作变得复杂许多
像不断发展的软件,功能 越来越多,越来越复杂
软件开发流程
软件复杂性
阶段项目 MyQQ
阶段项目简介
任务:MyQQ 聊天工具 系统结构:C/S,通过数据库交换聊天消息 小组形式完成 学时:24学时
项目实施和课程安排
课程进度 第一次课 第二次课 第三次课 第四次课 第五次课 第六次课
描述 项目讲解 项目准备阶段 任务讲解 第一次集中编码 任务讲解 第二次集中编码 任务讲解 第三次集中编码 任务讲解 第四次集中编码 总结和答辩

C# 模仿QQ列表

C# 模仿QQ列表

作者QQ(599194993)方法:编写的自定义用户控件。

然后添加到容器的集合。

主界面:编辑中的主界面:编辑中的自定义用户控件:源码(vs2010编译成功):主界面源码:using System;using System.Collections.Generic;using ponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;namespace WindowsFormsApplication9{public partial class Form1 : Form{public Form1(){InitializeComponent();}public UserControl1 u;int i = 0;private void button1_Click(object sender, EventArgs e) {i++;u = new UserControl1();bel1.Text = "QQ好友";bel2.Text = i + i.ToString(); = i.ToString();u.Click+=new EventHandler(u_Click);Random rand = new Random();switch (rand.Next(1, 14)){case 1:u.panel1.BackgroundImage = WindowsFormsApplication9.Properties.Resources._1;break;case 2:u.panel1.BackgroundImage = WindowsFormsApplication9.Properties.Resources._2;break;case 3:u.panel1.BackgroundImage = WindowsFormsApplication9.Properties.Resources._3;break;case 4:u.panel1.BackgroundImage = WindowsFormsApplication9.Properties.Resources._4;break;case 6:u.panel1.BackgroundImage = WindowsFormsApplication9.Properties.Resources._6;break;case 7:u.panel1.BackgroundImage = WindowsFormsApplication9.Properties.Resources._7;break;case 8:u.panel1.BackgroundImage =WindowsFormsApplication9.Properties.Resources._8;break;case 9:u.panel1.BackgroundImage =WindowsFormsApplication9.Properties.Resources._9;break;case 10:u.panel1.BackgroundImage =WindowsFormsApplication9.Properties.Resources._10;break;case 11:u.panel1.BackgroundImage =WindowsFormsApplication9.Properties.Resources._11;break;case 12:u.panel1.BackgroundImage =WindowsFormsApplication9.Properties.Resources._12;break;case 13:u.panel1.BackgroundImage =WindowsFormsApplication9.Properties.Resources._13;break;case 14:u.panel1.BackgroundImage =WindowsFormsApplication9.Properties.Resources._14;break;}flowLayoutPanel1.Controls.Add(u);flowLayoutPanel1.Height = flowLayoutPanel1.Height + (u.Height + 3);if (flowLayoutPanel1.Height >= Height){vScrollBar1.Enabled = true;vScrollBar1.Maximum = (flowLayoutPanel1.Height - Height) + u.Height;}else{vScrollBar1.Enabled = false;}}private void u_Click(object sender, EventArgs e)UserControl u = (UserControl)sender;Text = ;// flowLayoutPanel1.Controls.Remove(u);}private void Form1_Load(object sender, EventArgs e){flowLayoutPanel1.Height = 0;}private void vScrollBar1_Scroll(object sender, ScrollEventArgs e){flowLayoutPanel1.Top = -vScrollBar1.Value;button1.Text = flowLayoutPanel1.Height + "," + flowLayoutPanel1.Top;Text =vScrollBar1.Value.ToString()+","+(flowLayoutPanel1.Height-Height).ToString();}private void button2_Click(object sender, EventArgs e){}}}自定义用户控件源码:using System;using System.Collections.Generic;using ponentModel;using System.Drawing;using System.Data;using System.Linq;using System.Text;using System.Windows.Forms;namespace WindowsFormsApplication9{public partial class UserControl1 : UserControl{public UserControl1(){InitializeComponent();}private void UserControl1_KeyDown(object sender, KeyEventArgs e){private void UserControl1_MouseDown(object sender, MouseEventArgs e) {}private void UserControl1_MouseLeave(object sender, EventArgs e){//193,224,248BackColor = Color.FromName("灰色");}private void UserControl1_MouseMove(object sender, MouseEventArgs e) {BackColor = panel4.BackColor;}private void UserControl1_Load(object sender, EventArgs e){panel4.Visible = false;}private void panel1_Paint(object sender, PaintEventArgs e){}}}。

WPF自定义TreeView控件样式,仿QQ联系人列表

WPF自定义TreeView控件样式,仿QQ联系人列表

WPF⾃定义TreeView控件样式,仿QQ联系⼈列表⼀、前⾔TreeView控件在项⽬中使⽤⽐较频繁,普通的TreeView并不能满⾜我们的需求。

因此我们需要滴对TreeView进⾏改造。

下⾯的内容将介绍仿QQ联系⼈TreeView样式及TreeView数据绑定⽅法。

⼆、TreeView仿QQ联系⼈列表准确的说不是仿QQ联系⼈列表,这个TreeView样式作为组织架构来使⽤更好。

废话不多说,先看效果:2.1、基本思路像这种联系⼈列表⼀般涉及到多层级数据,⽽且有很多数据是需要动态更新的,如果通过⼿动⼀条条增加数据反⽽更复杂,⽽且不⽅便。

因此为了绑定数据⽅便我们使⽤分层模板HierarchicalDataTemplate。

分层模板中存在两种样式,⼀种是分组样式,⼀种是⼈员样式。

不管是分组还是⼈员绑定的都是对象,这样我们在对象中添加⼀个属性来辨别是否为分组-IsGrouping。

默认的TreeView控件四周会有边距,因此需要设置下TreeView的样式。

另外⿏标经过和⿏标选中的背景⾊需要变化,因此还需要设置TreeViewItem的样式。

根据思路,我们需要设置三个样式,TreeView样式,TreeViewItem样式,HierarchicalDataTemplate分层模板样式。

另外为了⾃动计算下⼀级的边距,我们需要添加⼀个转换器IndentConverter。

还需要⼀个转换器需要将布尔类型的IsGrouping转换为Visibility,还需要⼀个转换器来对Visibility取反。

这样三个样式,三个转换器。

就可以实现我们上⾯的效果,另外还可以进⾏动态数据绑定。

2.2、样式代码HierarchicalDataTemplate分层模板样式代码<HierarchicalDataTemplate x:Key="ItemNode" ItemsSource="{Binding Children,Mode=TwoWay}"><Grid Background="Transparent"><Grid.Resources><convert:BoolToVisible x:Key="boolToVisible"/><convert:VisibleToReverse x:Key="visibleToReverse"/></Grid.Resources><Grid MinHeight="30" x:Name="userinfo" Background="Transparent" Margin="-5 0 0 0" Visibility="{Binding Visibility,ElementName=groupinginfo,Converter={StaticResource visibleToReverse}}"><Grid Height="50" x:Name="grid"><Border Background="#62acf9" Width="40" Height="40" CornerRadius="4" HorizontalAlignment="Left" Margin="0 0 0 0"><TextBlock Text="{Binding SurName}" FontSize="23" Foreground="White" VerticalAlignment="Center" HorizontalAlignment="Center"/></Border><TextBlock Text="{Binding Name}" Margin="50 7 0 0" FontSize="13"/><TextBlock Text="{Binding Info}" Foreground="#808080" Margin="50 30 0 0"/><TextBlock Text="{Binding Count,StringFormat={}{0}⼈}" Foreground="#808080" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="0 0 5 0"/></Grid></Grid><StackPanel MinHeight="25" x:Name="groupinginfo" Orientation="Horizontal" Background="Transparent" HorizontalAlignment="Left" Visibility="{Binding IsGrouping,Converter={StaticResource boolToVisible}} <TextBlock Text="{Binding DisplayName}" Margin="3 0" VerticalAlignment="Center" HorizontalAlignment="Left"/></StackPanel></Grid></HierarchicalDataTemplate>TreeViewItem样式代码<Style x:Key="DefaultTreeViewItem" TargetType="{x:Type TreeViewItem}"><Setter Property="MinHeight" Value="25"/><Setter Property="Background" Value="Transparent"/><Setter Property="SnapsToDevicePixels" Value="True"/><Setter Property="Margin" Value="0"/><Setter Property="Template"><Setter.Value><ControlTemplate TargetType="{x:Type TreeViewItem}"><ControlTemplate.Resources><convert:IndentConverter x:Key="indentConverter"/></ControlTemplate.Resources><Grid Background="Transparent"><Grid.RowDefinitions><RowDefinition/><RowDefinition/></Grid.RowDefinitions><Border Name="itemBackground" Background="{TemplateBinding Background}"BorderBrush="{TemplateBinding BorderBrush}"BorderThickness="{TemplateBinding BorderThickness}"Padding="{TemplateBinding Padding}"><Grid Background="Transparent"><Grid x:Name="ItemRoot" Margin="{Binding Converter={StaticResource indentConverter},RelativeSource={RelativeSource TemplatedParent}}" Background="Transparent"><Grid.ColumnDefinitions><ColumnDefinition Width="16"/><ColumnDefinition Width="*"/></Grid.ColumnDefinitions><ToggleButton x:Name="Expander" HorizontalAlignment="Left" ClickMode="Press" IsChecked="{Binding IsExpanded, RelativeSource={RelativeSource TemplatedParent}}"><ToggleButton.Style><Style TargetType="{x:Type ToggleButton}"><Setter Property="Focusable" Value="False"/><Setter Property="Width" Value="16"/><Setter Property="Height" Value="16"/><Setter Property="Template"><Setter.Value><ControlTemplate TargetType="{x:Type ToggleButton}"><Border Background="Transparent" Height="16" Padding="5" Width="16"><Path x:Name="ExpandPath" Data="M0,0 L0,6 L6,0 z" Fill="#66645e" Stroke="#66645e"><Path.RenderTransform><RotateTransform Angle="135" CenterY="3" CenterX="3"/></Path.RenderTransform></Path></Border><ControlTemplate.Triggers><Trigger Property="IsChecked" Value="True"><Setter Property="RenderTransform" TargetName="ExpandPath"><Setter.Value><RotateTransform Angle="180" CenterY="3" CenterX="3"/></Setter.Value></Setter><Setter Property="Fill" TargetName="ExpandPath" Value="#66645e"/><Setter Property="Stroke" TargetName="ExpandPath" Value="#66645e"/></Trigger><Trigger Property="IsMouseOver" Value="True"><Setter Property="Stroke" TargetName="ExpandPath" Value="#66645e"/><Setter Property="Fill" TargetName="ExpandPath" Value="#66645e"/></Trigger><MultiTrigger><MultiTrigger.Conditions><Condition Property="IsMouseOver" Value="True"/><Condition Property="IsChecked" Value="True"/></MultiTrigger.Conditions><Setter Property="Stroke" TargetName="ExpandPath" Value="#66645e"/><Setter Property="Fill" TargetName="ExpandPath" Value="#66645e"/></MultiTrigger></ControlTemplate.Triggers></ControlTemplate></Setter.Value></Setter></Style></ToggleButton.Style></ToggleButton><ContentPresenter Grid.Column="1" x:Name="PART_Header" ContentSource="Header"HorizontalAlignment="Stretch"></ContentPresenter></Grid></Grid></Border><ItemsPresenter x:Name="ItemsHost" Grid.Row="1"/></Grid><ControlTemplate.Triggers><DataTrigger Binding="{Binding IsGrouping}" Value="false"><Setter Property="Visibility" TargetName="Expander" Value="Hidden"/></DataTrigger><Trigger Property="HasItems" Value="False"><Setter Property="Visibility" TargetName="Expander" Value="Collapsed"/></Trigger><Trigger Property="IsExpanded" Value="False"><Setter Property="Visibility" TargetName="ItemsHost" Value="Collapsed"/></Trigger><Trigger Property="IsSelected" Value="True"><Setter Property="Background" TargetName="itemBackground" Value="#FAE388"/></Trigger><MultiTrigger><MultiTrigger.Conditions><Condition Property="IsFocused" Value="False"/><Condition SourceName="itemBackground" Property="IsMouseOver" Value="true"/></MultiTrigger.Conditions><Setter Property="Background" Value=" #fceeb9" TargetName="itemBackground"/></MultiTrigger><Trigger Property="IsEnabled" Value="False"><Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/></Trigger></ControlTemplate.Triggers></ControlTemplate></Setter></Style>TreeView样式代码<Style x:Key="DefaultTreeView" TargetType="{x:Type TreeView}"><Setter Property="ScrollViewer.CanContentScroll" Value="True"/><Setter Property="VirtualizingStackPanel.IsVirtualizing" Value="True"></Setter><Setter Property="VirtualizingStackPanel.VirtualizationMode" Value="Recycling"/><Setter Property="ScrollViewer.IsDeferredScrollingEnabled" Value="False"/><Setter Property="ItemContainerStyle" Value="{StaticResource DefaultTreeViewItem}"></Setter><Setter Property="Padding" Value="0"/><Setter Property="ItemsPanel"><Setter.Value><ItemsPanelTemplate><VirtualizingStackPanel IsItemsHost="True" Margin="0"/></ItemsPanelTemplate></Setter.Value></Setter></Style>2.3、转换器代码public class IndentConverter : IValueConverter{public object Convert(object value, Type targetType, object parameter, CultureInfo culture){double colunwidth = 10;double left = 0.0;UIElement element = value as TreeViewItem;while (element.GetType() != typeof(TreeView)){element = (UIElement)VisualTreeHelper.GetParent(element);if (element.GetType() == typeof(TreeViewItem))left += colunwidth;}return new Thickness(left, 0, 0, 0);}public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture){throw new NotImplementedException();}}public class BoolToVisible : IValueConverter{public object Convert(object value, Type targetType, object parameter, CultureInfo culture){if ((bool)value)return Visibility.Visible;elsereturn Visibility.Collapsed;}public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture){throw new NotImplementedException();}}public class VisibleToReverse : IValueConverter{public object Convert(object value, Type targetType, object parameter, CultureInfo culture){if ((Visibility)value == Visibility.Visible)return Visibility.Collapsed;elsereturn Visibility.Visible;}public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture){throw new NotImplementedException();}}2.4、引⽤⽰例<TreeView x:Name="TreeViewOrg" BorderThickness="1" BorderBrush="#BBB" Background="Transparent" Width="280" Height="500" Margin="10" ItemTemplate="{StaticResource ItemNode}" Style="{StaticResource </TreeView>2.5、初始化数据源及绑定对象public MainWindow(){InitializeComponent();OrgList = new ObservableCollection<OrgModel>(){{IsGrouping=true,DisplayName="单位名称(3/7)",Children=new ObservableCollection<OrgModel>(){new OrgModel(){IsGrouping=true,DisplayName="未分组联系⼈(2/4)",Children=new ObservableCollection<OrgModel>() {new OrgModel(){IsGrouping=false,SurName="刘",Name="刘棒",Info="我要⾛向天空!",Count=3}}}},}};TreeViewOrg.ItemsSource = OrgList;}public ObservableCollection<OrgModel> OrgList { get; set; }public class OrgModel{public bool IsGrouping { get; set; }public ObservableCollection<OrgModel> Children { get; set; }public string DisplayName { get; set; }public string SurName { get; set; }public string Name { get; set; }public string Info { get; set; }public int Count { get; set; }}所有代码已经上传到github:。

课程设计项目《蓝梦教育集团即时通讯系统》(仿腾讯QQ)——完善客户端聊天信息主窗口程序类(第1部分)

课程设计项目《蓝梦教育集团即时通讯系统》(仿腾讯QQ)——完善客户端聊天信息主窗口程序类(第1部分)

J2EE课程设计实训教学示例项目《蓝梦教育集团即时通讯系统》(仿腾讯QQ)——完善客户端聊天信息主窗口程序类(第2部分)1.1.1熟悉了解JTextPane类1、JEditorPane和JTextPane类JEditorPane可以显示HTML和RTF文档,而且它还将激活另一种事件,即HyperlinkEvent。

当鼠标进入、离开或点击一个超链接时,就会激活此事件的子类型事件。

而JTextPane是JEditorPane的子类,它无所不能,可以在同一个组件中显示多种字体和多种样式,还提供对光标(插入记号)、加亮、嵌入图像和其它高级特性的支持。

2、在JTextPane中常用到属性类SimpleAttributeSet和StyleConstant(1)SimpleAttributeSet类属性的变化原本是利用AttributeSet接口来处理的,但是这个接口中包含了太多的方法,若是我们直接实现AttributeSet接口那就需要实作此接口中的所有的方法,这对编写程序来说并不是一个很理想的做法。

而java另外提供了SimpleAttributeSet类,实现了AttributeSet接口。

因此,只要我们直接使用SimpleAttributeSet类就能具备AttributeSet接口的所有功能,而不用一个个的编写AttributeSet中的方法。

(2)StyleConstant类StyleConstant类则是提供AttributeSet类许多常用的属性键值(Attribute Key)和方法来设置或取得JTextPane内容的状态。

在StyleConstant类中包含了许多的常用的属性设置,包括本文与边界空白区段设置、文字字体/大小/类型设置、背景颜色设置等。

SimpleAttributeSet属性集需要利用StyleConstants类中的静态方法来处理。

例如,要创建一组指定红色的属性,可采用如下做法:SimpleAttributeSet redstyle = new SimpleAttributeSet();StyleConstants.setForeground(redstyle, Color.red);为了向文档中增加一些红色的文本,只需将文本和属性传递给文档的insertString()方法,如下所示:document.insertString(6,"Some red text", redstyle):insertString的第一个实参是文本的偏移量。

仿qq软件课课程设计

仿qq软件课课程设计

仿qq软件课课程设计一、教学目标本课程的学习目标包括知识目标、技能目标和情感态度价值观目标。

知识目标要求学生掌握QQ软件的基本功能,如即时通讯、文件传输、语音视频通话等。

技能目标要求学生能够熟练操作QQ软件,进行信息的发送和接收、文件的传输和共享、语音视频通话的建立和结束等。

情感态度价值观目标要求学生树立正确的网络交往观念,认识到网络交流的工具性,注重个人信息的保护,遵守网络道德规范,促进良好的网络环境的建设。

二、教学内容本课程的教学内容主要包括QQ软件的基本功能和使用方法。

首先,介绍QQ软件的下载和安装方法,以及账号的注册和登录过程。

然后,详细讲解QQ软件的界面结构和功能模块,如消息、联系人、群聊、文件传输等。

接着,通过实际操作演示,引导学生掌握QQ软件的使用方法,如发送和接收消息、发起语音视频通话、传输文件等。

最后,结合实例,介绍QQ软件的高级功能和技巧,如自定义QQ界面、设置消息提醒、使用QQ群功能等。

三、教学方法为了激发学生的学习兴趣和主动性,本课程将采用多种教学方法。

首先,通过讲授法,向学生传授QQ软件的基本知识和使用方法。

其次,利用讨论法,学生进行小组讨论,分享彼此的操作经验和技巧。

然后,采用案例分析法,分析实际案例,让学生了解QQ软件在实际生活中的应用和价值。

最后,运用实验法,让学生亲自动手操作QQ软件,进行实践操作和练习。

四、教学资源为了支持教学内容和教学方法的实施,丰富学生的学习体验,我们将选择和准备适当的教学资源。

教材方面,我们将使用《计算机应用基础》教材,该书详细介绍了QQ软件的使用方法和技巧。

参考书方面,我们将推荐《QQ使用技巧手册》等书籍,供学生课后阅读和参考。

多媒体资料方面,我们将制作PPT演示文稿,以图文并茂的形式展示QQ软件的操作过程和功能特点。

实验设备方面,我们将准备计算机实验室,确保每个学生都能有机会亲自操作QQ软件。

五、教学评估本课程的教学评估方式包括平时表现、作业和考试三个部分,以保证评估的客观性和公正性。

【IT专家】【Android】仿QQ功能点击通知栏返回应用,非启动一个新Activity

【IT专家】【Android】仿QQ功能点击通知栏返回应用,非启动一个新Activity

本文由我司收集整编,推荐下载,如有疑问,请与我司联系【Android】仿QQ功能点击通知栏返回应用,非启动一个新Activity 2015/11/21 0 我也要实现一个像QQ一样的功能,点击通知栏上正在后台运行的通知,返回应用的需求: 整得我够惨啊,众说纷纭,可没一个可以实现的: 网上整理的: 方法一:利用activity的加载方式launchMode来区分,(这里可能需要补充一下activity的4种启动模式了)示例代码如下: 在Mainfest 里设置Activity flags android:launchMode= singleTop Intent intent = new Intent(this, MainActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);这样就可以实现!!可是让我失望啊,没法实现,还是新创建了activity为什么???是否可以尝试一下“singleTask”模式呢。

 方法二:不用launchMode直接利用Intent的Flags特性来玩,示例代码如下:mIntent.setFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED|Intent.FLAG_ ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY);还是不行的。

 方法三: Intent mIntent = new Intent(Intent.ACTION_MAIN);mIntent.addCategory(Intent.CATEGORY_LAUNCHER); mIntent.setComponent(new ComponentName(context.getPackageName(), DevicesListActivity.class.getCanonicalName()));mIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_RES ET_TASK_IF_NEEDED); 设置actin为action_main 设置category为launcher。

悬浮窗的设计方法有哪些

悬浮窗的设计方法有哪些

悬浮窗的设计方法有哪些
悬浮窗的设计方法主要有以下几种:
1. 系统级悬浮窗:通过系统级权限,在屏幕上添加一个独立的悬浮窗口。

这种方法可以实现全局悬浮窗效果,但需要获取系统权限,因此设计时需要考虑用户隐私和安全问题。

2. 应用级悬浮窗:在应用内部使用WindowManager等类来实现悬浮窗效果。

这种方法只能在应用内部显示悬浮窗,并且没有全局权限,但相对比较安全,不需要获取系统权限。

3. 悬浮球:将悬浮窗设计成一个小球,用户可以通过点击或拖拽来展开或收起悬浮菜单。

这种设计方法比较常见,适用于一些快速操作的场景,如音乐播放器、快速导航等。

4. 悬浮工具栏:类似于悬浮球,但是以水平或垂直的方式显示多个按钮或功能项,用户可以通过点击或滑动来使用相关功能。

这种设计方法适用于功能较多的应用,如聊天工具、多媒体应用等。

5. 触发边缘悬浮窗:当用户靠近屏幕边缘时,自动显示悬浮窗口,用户可以通过点击或拖拽来使用相关功能。

这种设计方法比较智能化,可以根据用户的触发行为进行相应的操作,提供更好的用户体验。

综上所述,悬浮窗的设计方法可以根据具体的应用场景和用户需求来选择合适的方法。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

干货,仿qq列表,手把手实现分类悬浮提示
新来的产品提了一个需求,让应用中的一个列表按照分类显示,并且能提示当前是在哪个分类,度娘了一番,参考了前辈们的博客,实现了如下图的效果:
这种效果的实现这里是采用自定义ExpandableListView,给它设置一个指示
布局,在滑动过程中监听当前是否应该悬浮显示分类来实现的。

今天抽时间,整理了下代码,记录一下使用过程,以便有类似的需求的时候可以快速搞定。

废话不多说,我们直接看代码和使用方法。

一项目结构
上边儿三个类分别是我们的自定义ExpandableListView,主界面,以及ExpandableListView使用的Adapter。

下边儿几个xml文件分别是主界面布局,指示器布局,ExpandableListView子项布局,ExpandableListView 组布局。

二实现代码
1.在xml中声明自定义ExpandableListView
<.expandablelistviewdemo.CustomExpandListview//这里不唯一,看你具体把Cust omExpandListview放在哪里android:id="@+id/listView"android:layout_width="match_parent "android:layout_height="match_parent"></.expandablelistviewdemo.CustomExpand Listview>
2.声明数据源相关(这里为了演示,数据全是String类型,看具体需求可改变) private String[] parentSource = {"分类1", "分类2", "分类3", "分类4", "分类5"}; private ArrayList<String> parent = new ArrayList<>();
private Map<String, ArrayList<String>> datas = new HashMap<>();
3.初始化演示数据
//种类for(int i = 0; i < parentSource.length; i++) {
parent.add(parentSource[i]);
}//给每个种类添加模拟数据for(int i = 0; i < parent.size(); i++) {
String str = parent.get(i);
ArrayList<String> temp = new ArrayList<>(); for(int j = 0; j <20; j++) { temp.add(""+ j);
}
datas.put(str, temp);
}
4.初始化Adapter以及使用
myAdapter = new MyAdapter(this, parent, datas, listview);
listview.setAdapter(myAdapter);
在初始化adapter的时候,可以看到我们在构造方法中传入了上下文对象,种类,数据,以及我们的CustomExpandListview对象,所以在CustomExpandListview 中我们要添加相应的构造方法。

5.设置悬浮提示布局
listview.setHeaderView(getLayoutInflater().inflate(yout.indictor_layout, listview, false));
6.其他
默认全部展开
for(int i= 0; i< parent.size(); i++) {
listview.expandGroup(i);
}
item点击事件
listview.setOnChildClickListener(new ExpandableListView.OnChildClickListener() { @Ov erride publicboolean onChildClick(ExpandableListView expandableListView, View view, int i, int i1, long l) {
Toast.makeText(MainActivity.this, "点击了第"+ (i + 1) + " 类的第"+ i1 + "项", Toast.LENGTH_SHORT).show();
returntrue;
}
} );。

相关文档
最新文档