- N +

java編寫簡單聊天界面(java聊天室代碼)

大家好,關于java編寫簡單聊天界面很多朋友都還不太明白,今天小編就來為大家分享關于java聊天室代碼的知識,希望對各位有所幫助!

如何自學編程,并編寫一個APP

自學編程本身就是一個非常難的挑戰,更何況自己制作一個APP!自學需要兩個能力,1是要有很強的邏輯理解能力,2就是設計能力!邏輯能力在學習過程中非常重要,邏輯不好起碼一個循環語句都夠你學很久,設計能力主要表現在設計程序方面,你學會了一門語言實際上只是個開始,會了跟會用是兩回事,會用更用得好又是兩回事!兩者都是非常難的,特別是現在面向過程的語言,由于不像面向過程語言是接近硬件底層的語言,所以面向對象語言本身并不難,難的是面向對象的思維,它不是像C這種面向過程語言,主要針對的是算法,講究的是這件事怎么做!面向對象語言一般都有提供現成的API,很多經常要實現的事情已經幫你做好了,你直接調用就行,更注重的是對象思維,就是誰做了這件事!所以喜歡編程的建議去一些培訓機構學習,有很好的學習氣氛和老師指導同學之間的交流,兩三個月內設計一款簡單的APP是絕對沒有問題的!自學不是不可行,而是對一般沒有天分的人來說實在太難!

dm是什么聊天軟件

dM是基于Java核心的高性能聊天程序,可同時支持ICQ和MSN,能方便的導入好友列表和以前的聊天記錄。你是不是覺得MSN還不夠完善?這個體積有些大的東西可以幫你實現在普通MSN上實現不了的功能!

你甚至能知道什么時候,誰從他/她的名單上刪除了你;對方是否關掉了聊天窗口也會清楚地提示給你。最令人驚喜的是,這個軟件可以同時支持多個MSN帳戶(TAB),并且互不影響。

用java寫一個很簡單的聊天程序,應學習哪些知識

用java寫一個很簡單的聊天程序,這是我經常推薦新手學習的一個案例

這個案例可以說是學習java的一個里程碑,從入門到初級的里程碑.

完成一個聊天程序主要用到的知識為socket,另外還會有用thread線程,如果使用圖形界面會用到awt,swing等。

整個聊天程序涉及java的3大核心包lang,util,io包。另外還有net包

對于剛學java來童鞋來說,除開數據庫,其他的知識點基本都用到了。

總結來說:你必須會socket,集合、線程、以及簡單的面向對象知識。

剛入門java,有什么網站可以有題讓我練習呢

本人計算機科學與技術專業,從事java有4年了。分享下自己的學習網站吧。

1.牛客網

主要服務于國內廣大程序員。產品規模很大,包括了it題庫、在線編程練習、線上課程、社區、筆試服務、還有競賽。用戶基本覆蓋全國高校百萬的程序員學習者。在國內互聯網公司有良好的口碑,為國內眾多的互聯網公司提供了校園招聘,競賽等服務。具備基本每個領域的筆試算法題,值得收藏。

2.利扣leetcode

這個網站有國際版和國內版,平常我們進國內版的就行了啊,當然英文好的也可以使用國際版,這里非常建議大家使用國際版,交流的技術存在差異,但是題目基本一致,不需要擔心。

地址:leetcode-cn.com

利扣被國內外程序員稱為刷題神器。甚至有人說,你如果掌握了百分之80左右,各互聯網公司提供的算法崗位你只要對比下誰的工資高就好了。

它基本覆蓋了全互聯網公司的算法題目,還有數據庫等技術,并且提供了交流平臺,國內過各種大神將自己的解答想法分享出來,有些巧妙的解答確實會令人拍案叫絕。普遍都是國外人,但是國內人也特別多,當然是國際版才是這樣的。

如果單單是學習練習java編程的,這兩個網站可以滿足了,關鍵就是提升你的編程思維能力。

要學習java核心技術還是建議購買java相關書籍或者在網上課堂學習。

網站app制作如何植入聊天機器人的客服系統

1,首先自己下載工具,搭建一個Android開發環境,去百度一下(安卓開發環境搭建),有詳細步驟。

2,百度搜索“圖靈機器人”,去注冊一個賬號,獲取apikey,用來調用圖靈機器人的數據。

2

把APIkey復制下來放在一個記事本,之后要在代碼中用的。

3

先新建一個Android工程,我的工程名為:Person,源代碼在com.shenbin.person包下,MainActivity是Android的activity。

還包括HttpDate類,HttpGetDateListener類,ListDate類,TextAdapter類

//MainActivity代碼:

/*下面的代碼修改

httpDate=(HttpDate)newHttpDate("http://www.tuling123.com/openapi/api?key=********&info="+droph,this).execute();

把********替換成自己的APIkey

*/

packagecom.shenbin.person;

importjava.text.SimpleDateFormat;importjava.util.ArrayList;importjava.util.Date;importjava.util.List;

importorg.json.JSONException;importorg.json.JSONObject;

importandroid.os.Bundle;importandroid.app.Activity;importandroid.view.View;importandroid.view.View.OnClickListener;importandroid.widget.Button;importandroid.widget.EditText;importandroid.widget.ListView;

publicclassMainActivityextendsActivityimplementsHttpGetDateListener,OnClickListener{//實現接口

privateHttpDatehttpDate;privateList<ListDate>lists;privateListViewlv;privateEditTextgetText;privateButtonsend_btn;privateStringcontent_str;privateTextAdapteradapter;privateString[]welcome_array;privatedoublecurrentTime,oldTime=0;@OverrideprotectedvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);initView();//httpDate=(HttpDate)newHttpDate("http://www.tuling123.com/openapi/api?key=5692c0d167fc5a180d092efaab578617&info=你好",//this).execute();}

privatevoidinitView(){lv=(ListView)findViewById(R.id.lv);getText=(EditText)findViewById(R.id.sendText);send_btn=(Button)findViewById(R.id.send_btn);//send_btn.setOnClickListener((android.view.View.OnClickListener)this);send_btn.setOnClickListener(this);lists=newArrayList<ListDate>();adapter=newTextAdapter(lists,this);lv.setAdapter(adapter);ListDatelistDate=null;listDate=newListDate(getRandomWelcomeTips(),listDate.RECEIVER,getTime());lists.add(listDate);

}privateStringgetRandomWelcomeTips(){Stringwelcome_tip=null;welcome_array=this.getResources().getStringArray(R.array.welcome_tips);//獲得string。xml的歡迎語intindex=(int)(Math.random()*(welcome_array.length-1));welcome_tip=welcome_array[index];returnwelcome_tip;}@OverridepublicvoidgetDateUrl(Stringdate){//TODO自動生成的方法存根//System.out.println(date);parseText(date);}publicvoidparseText(Stringstr){try{JSONObjectjb=newJSONObject(str);//System.out.println(jb.getString("code"));//System.out.println(jb.getString("text"));ListDatelistDate=null;listDate=newListDate(jb.getString("text"),listDate.RECEIVER,getTime());lists.add(listDate);adapter.notifyDataSetChanged();}catch(JSONExceptione){//TODO自動生成的catch塊e.printStackTrace();}}

@OverridepublicvoidonClick(Viewv){getTime();content_str=getText.getText().toString();getText.setText("");Stringdropk=content_str.replace("","");Stringdroph=dropk.replace("\n","");ListDatelistDate;listDate=newListDate(content_str,ListDate.SEND,getTime());lists.add(listDate);//如果太多了,就移除一些if(lists.size()>30){for(inti=0;i<lists.size();i++){lists.remove(i);}}adapter.notifyDataSetChanged();httpDate=(HttpDate)newHttpDate("http://www.tuling123.com/openapi/api?key=********&info="+droph,this).execute();

}privateStringgetTime(){currentTime=System.currentTimeMillis();SimpleDateFormatformat=newSimpleDateFormat("yyyy年MM月dd日HH:mm:ss");DatecurDate=newDate();Stringstr=format.format(curDate);if(currentTime-oldTime>5*60*1000){oldTime=currentTime;returnstr;}else{return"";}}

}

//HttpDate類代碼

packagecom.shenbin.person;

importjava.io.BufferedReader;importjava.io.InputStream;importjava.io.InputStreamReader;

importorg.apache.http.HttpEntity;importorg.apache.http.HttpResponse;importorg.apache.http.client.HttpClient;importorg.apache.http.client.methods.HttpGet;importorg.apache.http.impl.client.DefaultHttpClient;importandroid.os.AsyncTask;

publicclassHttpDateextendsAsyncTask<String,Void,String>{privateHttpClientmHttpClient;//客戶端privateHttpGetmHttpGet;//請求方式為getprivateStringurl;//請求的地址privateHttpResponsemHttpResponse;//請求返還privateHttpEntitymHttpEntity;//創建實體privateInputStreamin;privateHttpGetDateListenerlistener;//獲得接口

publicHttpDate(Stringurl,HttpGetDateListenerlistener){this.url=url;this.listener=listener;}@OverrideprotectedStringdoInBackground(String...arg0){//TODO自動生成的方法存根try{mHttpClient=newDefaultHttpClient();//實例化客戶端mHttpGet=newHttpGet(url);mHttpResponse=mHttpClient.execute(mHttpGet);mHttpEntity=mHttpResponse.getEntity();in=mHttpEntity.getContent();BufferedReaderbr=newBufferedReader(newInputStreamReader(in));Stringline=null;//獲取數據StringBuffersb=newStringBuffer();while((line=br.readLine())!=null){sb.append(line);}returnsb.toString();}catch(Exceptione){//TODO:handleexception}returnnull;}@OverrideprotectedvoidonPostExecute(Stringresult){//TODO自動生成的方法存根listener.getDateUrl(result);super.onPostExecute(result);}

}

//HttpGetDateListener類代碼

//接口

packagecom.shenbin.person;

publicinterfaceHttpGetDateListener{

voidgetDateUrl(Stringdate);}

//ListDate類代碼

packagecom.shenbin.person;

importandroid.R.integer;

publicclassListDate{privateStringcontent;publicstaticfinalintSEND=1;publicstaticfinalintRECEIVER=2;privateintflag;privateStringtime;publicListDate(Stringcontent,intflag,Stringtime){//TODO自動生成的構造函數存根setContent(content);setFlag(flag);setTime(time);}publicvoidsetContent(Stringcontent){this.content=content;}

publicStringgetContent(){returncontent;}

publicintgetFlag(){returnflag;}

publicvoidsetFlag(intflag){this.flag=flag;}

publicStringgetTime(){returntime;}

publicvoidsetTime(Stringtime){this.time=time;}

}

//TextAdapter類代碼

packagecom.shenbin.person;

importjava.net.ContentHandler;importjava.util.List;

importjavax.security.auth.PrivateCredentialPermission;

importandroid.R.layout;importandroid.content.Context;importandroid.view.LayoutInflater;importandroid.view.View;importandroid.view.ViewGroup;importandroid.webkit.WebView.FindListener;importandroid.widget.BaseAdapter;importandroid.widget.RelativeLayout;importandroid.widget.TextView;

publicclassTextAdapterextendsBaseAdapter{privateList<ListDate>lists;privateContextnContext;privateRelativeLayoutlayout;publicTextAdapter(List<ListDate>lists,ContextnContext){this.lists=lists;this.nContext=nContext;}

@OverridepublicintgetCount(){//TODO自動生成的方法存根returnlists.size();}

@OverridepublicObjectgetItem(intpesition){returnlists.get(pesition);}

@OverridepubliclonggetItemId(intpesition){//TODO自動生成的方法存根returnpesition;}

@OverridepublicViewgetView(intpesition,ViewconverView,ViewGroupparent){LayoutInflaterinflater=LayoutInflater.from(nContext);if(lists.get(pesition).getFlag()==ListDate.RECEIVER){layout=(RelativeLayout)inflater.inflate(R.layout.leftitem,null);}if(lists.get(pesition).getFlag()==ListDate.SEND){layout=(RelativeLayout)inflater.inflate(R.layout.rightitem,null);}TextViewtv=(TextView)layout.findViewById(R.id.tv);tv.setText(lists.get(pesition).getContent());TextViewtime=(TextView)layout.findViewById(R.id.time);time.setText(lists.get(pesition).getTime());returnlayout;}

}

activity_main.xml的代碼:

<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"android:layout_width="fill_parent"android:layout_height="fill_parent"android:orientation="vertical"android:paddingBottom="@dimen/activity_vertical_margin"android:paddingLeft="@dimen/activity_horizontal_margin"android:paddingRight="@dimen/activity_horizontal_margin"android:paddingTop="@dimen/activity_vertical_margin"tools:context=".MainActivity">

<ListViewandroid:id="@+id/lv"android:layout_width="fill_parent"android:layout_height="0dp"android:layout_weight="1"android:divider="@null"android:listSelector="@android:color/transparent"android:transcriptMode="alwaysScroll"></ListView><LinearLayoutandroid:layout_width="fill_parent"android:layout_height="wrap_content"android:orientation="horizontal"><EditTextandroid:id="@+id/sendText"android:layout_width="0dp"android:layout_height="wrap_content"android:layout_weight="1"/><Buttonandroid:id="@+id/send_btn"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/send"/></LinearLayout>

</LinearLayout>

leftitem.xml代碼

<?xmlversion="1.0"encoding="utf-8"?><RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"><TextViewandroid:id="@+id/time"android:layout_width="fill_parent"android:gravity="center_horizontal"android:layout_height="wrap_content"/><ImageViewandroid:layout_below="@id/time"android:id="@+id/iv"android:layout_width="70dp"android:layout_height="70dp"android:padding="10dp"android:src="@drawable/c"/><TextViewandroid:layout_below="@id/time"android:layout_toRightOf="@id/iv"android:layout_width="wrap_content"android:layout_height="wrap_content"android:id="@+id/tv"android:gravity="center"android:background="@drawable/d"/>

</RelativeLayout>

rightitem.xml代碼

<?xmlversion="1.0"encoding="utf-8"?><RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"><TextViewandroid:id="@+id/time"android:layout_width="fill_parent"android:gravity="center_horizontal"android:layout_height="wrap_content"/><ImageViewandroid:layout_below="@id/time"android:layout_alignParentRight="true"android:id="@+id/iv"android:layout_width="70dp"android:layout_height="70dp"android:padding="10dp"android:src="@drawable/b"/><TextViewandroid:layout_below="@id/time"android:layout_toLeftOf="@id/iv"android:layout_width="wrap_content"android:layout_height="wrap_content"android:id="@+id/tv"android:gravity="center"android:background="@drawable/d"/>

</RelativeLayout>

values文件下的strings.xml代碼

<?xmlversion="1.0"encoding="utf-8"?><resources>

<stringname="app_name">小兵機器人</string><stringname="action_settings">Settings</string><stringname="hello_world">小兵聊天機器人</string><stringname="send">發送</string><string-arrayname="welcome_tips"><item>主人,奴婢在此等候多時了</item><item>主人,近來可好</item><item>歡迎歸來,我親愛的主人</item><item>主人,我好想你啊</item><item>主人,你越來越靚啦</item><item>我是小兵機器人,很高興陪你聊天</item><item>我就是聰明,可愛的小兵機器人</item><item>hello,美女(帥鍋)</item><item>你是我的小呀小蘋果</item><item>開心的話,可以找我聊天,不開心更要找我聊天啦</item></string-array>

</resources>

AndroidManifest.xml的代碼

添加的代碼為加黑的粗體。

<?xmlversion="1.0"encoding="utf-8"?><manifestxmlns:android="http://schemas.android.com/apk/res/android"package="com.shenbin.person"android:versionCode="1"android:versionName="1.0">

<uses-sdkandroid:minSdkVersion="8"android:targetSdkVersion="18"/><uses-permissionandroid:name="android.permission.INTERNET"/>

<applicationandroid:allowBackup="true"android:icon="@drawable/ic_launcher"android:label="@string/app_name"android:theme="@style/AppTheme"><activityandroid:name="com.shenbin.person.MainActivity"android:label="@string/app_name"><intent-filter><actionandroid:name="android.intent.action.MAIN"/>

<categoryandroid:name="android.intent.category.LAUNCHER"/></intent-filter></activity>

END,本文到此結束,如果可以幫助到大家,還望關注本站哦!

返回列表
上一篇:
下一篇: