⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 用java编制internet电子白板软件.mht

📁 用JAVA编制Internet电子白板软件
💻 MHT
📖 第 1 页 / 共 5 页
字号:
<P><FONT color=3D#0000ff=20
size=3D2>=A1=A1=A1=A1=B1=BE=CE=C4=BD=E1=BA=CF=B1=CA=D5=DF=B5=C4=B1=E0=B3=CC=
=BE=AD=D1=E9=B3=F5=B2=BD=BD=E9=C9=DC=C1=CB=BB=F9=D3=DA=E4=AF=C0=C0=C6=F7=BA=
=CDJAVA=B5=C4=B5=E7=D7=D3=B0=D7=B0=E5=C8=ED=BC=FE=B5=C4=B3=CC=D0=F2=C9=E8=
=BC=C6=B9=FD=B3=CC=A3=AC=CF=A3=CD=FB=D5=E2=D0=A9=C4=DA=C8=DD=C4=DC=B9=BB=B6=
=D4=B9=E3=B4=F3=C8=ED=BC=FE=BF=AA=B7=A2=C8=CB=D4=B1=D3=D0=CB=F9=B0=EF=D6=FA=
=A1=A3=BB=B6=D3=AD=B4=F3=BC=D2=D3=EB=B1=CA=D5=DF=C1=AA=CF=B5(lfl@cenpok.n=
et)=A3=AC=BE=CD=B5=E7=D7=D3=B0=D7=B0=E5=B5=C4=D2=BB=D0=A9=CE=CA=CC=E2=BD=F8=
=D0=D0=C7=D0=B4=E8=BA=CD=BD=BB=C1=F7=A1=A3</FONT></P>
<H3 align=3Dcenter><FONT color=3D#0000ff =
size=3D2>=B8=BD=C2=BC=C4=DA=C8=DD=A3=BA</FONT></H3>
<OL>
  <LI><FONT color=3D#0000ff =
size=3D2>=B1=BE=B5=E7=D7=D3=B0=D7=B0=E5=CF=B5=CD=B3=B5=C4=CD=EA=D5=FB=D4=B4=
=B3=CC=D0=F2=A1=A3=D2=D1=B2=E2=CA=D4=CD=A8=B9=FD=A3=AC=BF=C9=D2=D4=D6=B1=BD=
=D3=B1=E0=D2=EB=D4=CB=D0=D0=A1=A3<BR></FONT>
  <LI><FONT color=3D#0000ff =
size=3D2>=C7=B6=C8=EBApplet=B5=C4=D6=F7=D2=B3=CA=BE=B7=B6=A1=A3=C7=EB=D7=A2=
=D2=E2=D6=F7=D2=B3=D6=D0Applet=B5=C4=B2=CE=CA=FD=C9=E8=D6=C3=A1=A3<BR></F=
ONT>
  <LI><FONT color=3D#0000ff =
size=3D2>=B1=BE=B5=E7=D7=D3=B0=D7=B0=E5=BF=CD=BB=A7=B6=CBApplet=B5=C4=D3=C3=
=BB=A7=BD=E7=C3=E6=BC=B0=B2=D9=D7=F7=B7=BD=B7=A8=BC=F2=BD=E9=A1=A3</FONT>=
 </LI></OL>
<H3 align=3Dcenter><FONT color=3D#0000ff =
size=3D2>=B8=BD=C2=BC1=A3=BA=D4=B4=B3=CC=D0=F2=A3=BA</FONT></H3>
<P><FONT color=3D#800000>import java.net.*;<BR>import =
java.io.*;<BR>import=20
java.awt.*;<BR>import java.util.*;<BR>import java.applet.*;<BR><BR>// =
class=20
1:server main class=A3=AC=B7=FE=CE=F1=C6=F7=C6=F4=B6=AF=C0=E0<BR>public =
class ChatServer extends Frame=20
{<BR><BR>final static int DEFAULT_USERCOUNT=3D30;<BR>final static int=20
DEFAULT_PORT=3D10000;<BR>final static String =
ICON_FILE=3D"icon.gif";<BR>int=20
num_Line=3D0;<BR>User[] users=3Dnull;<BR>ServerSocket =
ss=3Dnull;<BR>RoomGroup=20
roomGroup=3Dnull;<BR>int port=3DDEFAULT_PORT;<BR>Image=20
icon=3Dnull;<BR><BR>java.awt.TextArea message_TextArea;<BR>java.awt.List =

users_List;<BR>java.awt.Choice room_Choice;<BR>java.awt.Label=20
message_Label;<BR>java.awt.Label room_Label;<BR>java.awt.Label=20
userList_Label;<BR>java.awt.Button clean_Button;<BR><BR>java.awt.MenuBar =

mainMenuBar;<BR>java.awt.Menu menu1;<BR>java.awt.Menu menu3;<BR><BR>void =

initServer(int port) throws IOException {<BR>users=3Dnew=20
User[ChatServer.DEFAULT_USERCOUNT];<BR>roomGroup=3Dnew=20
RoomGroup(ChatServer.DEFAULT_USERCOUNT,room_Choice,<BR>this);<BR>try{<BR>=
ss=3Dnew=20
ServerSocket(port,5);<BR>message_TextArea.appendText("\nserver socket =
init=20
successed");<BR><BR>}catch(Exception=20
e){<BR>System.out.println(e);<BR>message_TextArea.appendText("\nserver =
socket=20
init error"+e);<BR>}<BR>for(int i=3D0;i&lt; users.length;i++) =
{<BR>users[i]=3Dnew=20
User(this,i);<BR>}<BR>roomGroup.setUsers(users);<BR>show();<BR>go();<BR>m=
essage_TextArea.appendText("\nserver=20
started");<BR><BR>}<BR><BR>ChatServer(int port) throws IOException=20
{<BR><BR>icon=3DgetToolkit().getImage(ICON_FILE);<BR>MediaTracker =
tracker =3D new=20
MediaTracker(this);<BR>tracker.addImage(icon,0);<BR>try{<BR>tracker.waitF=
orAll();<BR>}catch(Exception=20
e){<BR>System.out.println(e);<BR>}<BR>//{{INIT_CONTROLS<BR>setLayout(null=
);<BR>addNotify();<BR>resize(insets().left=20
+ insets().right + 544,<BR>insets().top + insets().bottom + =
355);<BR>//$$=20
openFileDialog1.move(36,276);<BR>setTitle("Chat &amp; WhiteBoard Server=20
1.0");<BR>setIconImage(icon);<BR>//}}<BR><BR>message_TextArea =3D new=20
java.awt.TextArea();<BR>message_TextArea.reshape(insets().left +=20
12,<BR>insets().top + =
36,396,240);<BR>add(message_TextArea);<BR>users_List =3D new=20
java.awt.List(5,false);<BR>add(users_List);<BR>users_List.reshape(insets(=
).left=20
+ 432,<BR>insets().top + 144,76,110);<BR>room_Choice =3D new=20
java.awt.Choice();<BR>add(room_Choice);<BR>room_Choice.reshape(insets().l=
eft +=20
420,<BR>insets().top + 60,100,1);<BR>message_Label =3D new=20
java.awt.Label("message");<BR>message_Label.reshape(insets().left +=20
36,<BR>insets().top + 12,100,24);<BR>add(message_Label);<BR>room_Label =
=3D new=20
java.awt.Label("Chat room");<BR>room_Label.reshape(insets().left +=20
420,<BR>insets().top + 14,100,24);<BR>add(room_Label);<BR>userList_Label =
=3D new=20
java.awt.Label("user List");<BR>userList_Label.reshape(insets().left +=20
420,<BR>insets().top + =
108,100,28);<BR>add(userList_Label);<BR>clean_Button =3D=20
new java.awt.Button("clean");<BR>clean_Button.reshape(insets().left +=20
180,<BR>insets().top +=20
12,60,24);<BR>add(clean_Button);<BR><BR><BR>//{{INIT_MENUS<BR>mainMenuBar=
 =3D new=20
java.awt.MenuBar();<BR><BR>menu1 =3D new=20
java.awt.Menu("File");<BR>menu1.add("Restart");<BR>menu1.add("Exit");<BR>=
mainMenuBar.add(menu1);<BR><BR><BR>menu3=20
=3D new=20
java.awt.Menu("Help");<BR>mainMenuBar.setHelpMenu(menu3);<BR>menu3.add("A=
bout");<BR>mainMenuBar.add(menu3);<BR>setMenuBar(mainMenuBar);<BR>//$$=20
mainMenuBar.move(4,277);<BR><BR><BR>this.port=3Dport;<BR>initServer(port)=
;<BR><BR><BR>}//=20
constructor 1 ended<BR><BR>ChatServer() throws=20
IOException{<BR>this(ChatServer.DEFAULT_PORT);<BR>}// contructor 2=20
ended<BR><BR>void cleanButton_Clicked(Event event)=20
{<BR><BR><BR>//{{CONNECTION<BR>// Hide the=20
Frame<BR>message_TextArea.setText("");<BR>//}}<BR>}<BR>void =
About_Action(Event=20
event) {<BR>//{{CONNECTION<BR>// Action from About Create and show as=20
modal<BR>(new AboutDialog(this, true)).show();<BR>//}}<BR>}<BR><BR>void=20
Exit_Action(Event event) {<BR>//{{CONNECTION<BR>// Action from Exit =
Create and=20
show as modal<BR>(new QuitDialog(this, =
true)).show();<BR>//}}<BR>}<BR><BR>void=20
Restart_Action(Event e)=20
{<BR>try{<BR>quit();<BR>initServer(port);<BR>}catch(Exception=20
e1){<BR>message_TextArea.appendText("\ninit server=20
error");<BR>}<BR>}<BR><BR>public synchronized void show() {<BR>move(50,=20
50);<BR><BR>super.show();<BR>}<BR><BR>void roomChoice_Action(Event e)=20
{<BR><BR>String roomName=3Dnull;<BR>int=20
roomID=3D0;<BR><BR>users_List.clear();<BR>roomName=3Droom_Choice.getSelec=
tedItem();<BR>roomID=3DroomGroup.getRoomID(roomName);<BR>for(int=20
i=3D0;i&lt; users.length;i++) {<BR>if=20
((users[i].logged)&amp;&amp;(users[i].belongRoom)<BR>&amp;&amp;(users[i].=
roomID=3D=3DroomID))=20
{<BR>users_List.addItem(users[i].name);<BR>}<BR>}<BR>}<BR><BR><BR>public =
boolean=20
handleEvent(Event event) {<BR>if (event.id =3D=3D Event.WINDOW_DESTROY)=20
{<BR>quit();<BR>hide(); // hide the Frame<BR>dispose(); // free the =
system=20
resources<BR>System.exit(0); // close the application<BR>return =
true;<BR>}<BR>if=20
(event.target =3D=3D room_Choice &amp;&amp; event.id =3D=3D =
<BR>Event.ACTION_EVENT)=20
{<BR>roomChoice_Action(event);<BR>return true;<BR>}<BR>if (event.target =
=3D=3D=20
clean_Button &amp;&amp; event.id <BR>=3D=3D Event.ACTION_EVENT)=20
{<BR>cleanButton_Clicked(event);<BR>return true;<BR>}<BR><BR>return=20
super.handleEvent(event);<BR>}<BR><BR>public boolean action(Event event, =
Object=20
arg) {<BR>if (event.target instanceof MenuItem) {<BR>String label =3D =
(String)=20
arg;<BR>if (label.equalsIgnoreCase("About")) =
{<BR>About_Action(event);<BR>return=20
true;<BR>} else<BR>if (label.equalsIgnoreCase("Exit"))=20
{<BR>Exit_Action(event);<BR>return true;<BR>} else<BR>if=20
(label.equalsIgnoreCase("Restart")) =
{<BR>Restart_Action(event);<BR>return=20
true;<BR>}<BR>}<BR>return super.action(event, arg);<BR>}<BR><BR>public =
static=20
void main(String args[]) {<BR><BR>try{<BR>ChatServer chatServer=3Dnew=20
ChatServer();<BR>}catch(Exception=20
e){<BR>System.out.println(e);<BR>}<BR>}<BR><BR><BR>public void go() =
{<BR>for(int=20
i=3D0;i&lt; users.length;i++) {<BR>users[i].start();<BR>}<BR>}// method =
'go'=20
ended<BR><BR>public void quit() {<BR>for(int i=3D0;i&lt; =
users.length;i++) {<BR>if=20
(users[i]!=3Dnull)=20
users[i].destroy();<BR>}<BR>try{<BR>ss.close();<BR>ss=3Dnull;<BR>room_Cho=
ice.removeAll();<BR>users_List.clear();<BR>message_TextArea.appendText("\=
nserver=20
socket closed");<BR><BR>}catch(IOException=20
e){<BR>System.out.println(e);<BR>}<BR>}// method 'quit' ended<BR><BR>} =
// class=20
'ChatServer' ended<BR><BR><BR>//class =
2:RoomGroup=A3=AC=B7=FE=CE=F1=C6=F7=D3=C3=B5=C4=BD=BB=CC=B8=CA=D2=CA=FD=BE=
=DD=C0=E0<BR>class RoomGroup=20
{<BR><BR>Room[] rooms=3Dnull;<BR>final static String=20
DEFAULT_ROOM_SUBJECT=3D"=C4=AC=C8=CF";<BR>final static int =
DEFAULT_ROOM_ID=3D0;<BR>Choice=20
room_Choice=3Dnull;<BR>List users_List=3Dnull;<BR>User[] =
users=3Dnull;<BR>ChatServer=20
chatServer=3Dnull;<BR><BR>RoomGroup(int roomCount,Choice=20
room_Choice,<BR>ChatServer chatServer)=20
{<BR>this.chatServer=3DchatServer;<BR>this.room_Choice=3Droom_Choice;<BR>=
this.users=3Dusers;<BR>this.users_List=3Dusers_List;<BR>rooms=3Dnew=20
Room[roomCount];<BR>try{<BR>newRoom(DEFAULT_ROOM_SUBJECT);<BR>}catch(Exce=
ption=20
e){<BR>System.out.println(e);<BR>}<BR>}// contructor 1 ended<BR><BR>void =

setUsers(User[] users) {<BR>this.users=3Dusers;<BR>}<BR><BR>void =
refreshList()=20
{<BR>chatServer.handleEvent(new Event(this, Event.ACTION_EVENT,=20
null));<BR>}<BR><BR>public int getRoomID(String roomName){<BR>for(int =
i=3D0;i&lt;=20
rooms.length;i++) {<BR>if=20
((rooms[i]!=3Dnull)&amp;&amp;(rooms[i].getRoomName().equals(roomName)))=20
{<BR>return i;<BR>}<BR>}<BR>return 0;<BR><BR>}// method 'getRoomID'=20
ended<BR><BR>public int newRoom(String subject) throws =
TooManyRoomsException=20
{<BR>int i=3D0;<BR>while((i&lt; =
rooms.length)&amp;&amp;(rooms[i]!=3Dnull))=20
{<BR>i++;<BR>}<BR>if (i&lt; rooms.length) {<BR>rooms[i]=3Dnew=20
Room(subject,i);<BR>room_Choice.addItem(subject);<BR>room_Choice.repaint(=
);<BR>return=20
i;<BR>}else {<BR>throw new TooManyRoomsException();<BR>}<BR>} // method=20
'newRoom' ended<BR><BR>public void join(int roomID,User user) throws=20
NoSuchRoomException=20
{<BR>try{<BR>rooms[roomID].join(user);<BR>room_Choice.select(getRoomName(=
roomID));<BR>refreshList();<BR>}catch(ArrayIndexOutOfBoundsException=20
e){<BR>throw new NoSuchRoomException();<BR>}catch(NullPointerException =
e)=20
{<BR>throw new NoSuchRoomException();<BR>}<BR>} // method 'join'=20
ended<BR><BR>public void quit(int roomID,User user) throws =
NoSuchRoomException=20
{<BR>try{<BR>try{<BR>rooms[roomID].quit(user);<BR>room_Choice.select(getR=
oomName(roomID));<BR>refreshList();<BR><BR>}catch(NotMemberException=20
e){<BR>}finally{<BR>if=20
((rooms[roomID].getUserCount()=3D=3D0)&amp;&amp;<BR>(roomID!=3DDEFAULT_RO=
OM_ID))=20
{<BR>room_Choice.remove(rooms[roomID].getRoomName());<BR>rooms[roomID]=3D=
null;<BR>}<BR>}<BR>}catch(ArrayIndexOutOfBoundsException=20
e){<BR>throw new NoSuchRoomException();<BR>}catch(NullPointerException =
e)=20
{<BR>throw new NoSuchRoomException();<BR>}<BR>} // method 'quit'=20
ended<BR><BR>public String[] getUsersName(int roomID) <BR>throws=20
NoSuchRoomException {<BR>try{<BR>if (rooms[roomID]!=3Dnull)<BR>return=20
rooms[roomID].getUsersName();<BR>else return=20
null;<BR>}catch(ArrayIndexOutOfBoundsException e) {<BR>throw new=20
NoSuchRoomException();<BR>}<BR>} // method 'getUsersName' =
ended<BR><BR>public=20
int getUserCount(int roomID) throws NoSuchRoomException =
{<BR>try{<BR>return=20
rooms[roomID].getUserCount();<BR>}catch(ArrayIndexOutOfBoundsException =
e)=20
{<BR>throw new NoSuchRoomException();<BR>}catch(NullPointerException e)=20
{<BR>throw new NoSuchRoomException();<BR>}<BR>} // method 'getUserCount' =

ended<BR><BR>public String getRoomName(int roomID) throws =
NoSuchRoomException=20
{<BR>try{<BR>return=20
rooms[roomID].getRoomName();<BR>}catch(ArrayIndexOutOfBoundsException e) =

{<BR>throw new NoSuchRoomException();<BR>}catch(NullPointerException e)=20
{<BR>throw new NoSuchRoomException();<BR>}<BR>} // method 'getRoomName'=20
ended<BR><BR>public boolean isActive(int roomID) throws =
NoSuchRoomException=20
{<BR>try{<BR>if (rooms[roomID]!=3Dnull)<BR>return true;<BR>else return=20
false;<BR>}catch(ArrayIndexOutOfBoundsException e) {<BR>throw new=20
NoSuchRoomException();<BR>}<BR>}//method 'isActive' ended<BR><BR>public =

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -