📄 0029.htm
字号:
belongRoom=false;<br>
paused=false;<br>
roomGroup.join(roomID,this);<br>
belongRoom=true;<br>
this.roomID=roomID;<br>
message_TextArea.appendText("\nChannel"+ID+"("+<br>
name+"):new room("+message+")");<br>
<br>
}catch(TooManyRoomsException e){<br>
}<br>
}catch(IOException e){<br>
throw new PleaseCloseSocketException();<br>
}catch(NoSuchRoomException e){}<br>
}// method 'server_answer_new' ended<br>
<br>
private void server_answer_quit() throws<br>
PleaseCloseSocketException {<br>
<br>
String message=null;<br>
<br>
try{<br>
try{<br>
roomGroup.quit(roomID,this);<br>
used=false;<br>
logged=false;<br>
belongRoom=false;<br>
roomID=0;<br>
name=null;<br>
message_TextArea.appendText("\nChannel"+ID+"("+<br>
name+"):quited");<br>
<br>
}catch(NoSuchRoomException e){<br>
io_out.writeUTF("fail");<br>
}<br>
<br>
}catch(IOException e){<br>
throw new PleaseCloseSocketException();<br>
}<br>
<br>
}// method 'server_answer_quit' ended<br>
<br>
<br>
}// class 'user' ended<br>
<br>
/*<br>
A basic extension of the java.awt.Dialog class<br>
*/<br>
<br>
//class 5:QuitDialg,服务器退出对话框<br>
public class QuitDialog extends Dialog {<br>
void yesButton_Clicked(Event event) {<br>
<br>
getParent().handleEvent(new Event(this,<br>
Event.WINDOW_DESTROY, null));<br>
}<br>
<br>
void noButton_Clicked(Event event) {<br>
//{{CONNECTION<br>
// Clicked from noButton Hide the Dialog<br>
hide();<br>
//}}<br>
}<br>
<br>
public QuitDialog(Frame parent, boolean modal) {<br>
<br>
super(parent, modal);<br>
//setIconImage(icon);<br>
<br>
//{{INIT_CONTROLS<br>
setLayout(null);<br>
addNotify();<br>
resize(insets().left + insets().right + 337,<br>
insets().top + insets().bottom + 135);<br>
yesButton = new java.awt.Button(" Yes ");<br>
yesButton.reshape(insets().left + 72,<br>
insets().top + 84,79,22);<br>
yesButton.setFont(new Font("Dialog", Font.BOLD, 12));<br>
add(yesButton);<br>
noButton = new java.awt.Button(" No ");<br>
noButton.reshape(insets().left + 180,<br>
insets().top + 84,79,22);<br>
noButton.setFont(new Font("Dialog", Font.BOLD, 12));<br>
add(noButton);<br>
label1 = new java.awt.Label("Do you really want to quit?");<br>
label1.reshape(insets().left + 84,insets().top + 36,180,23);<br>
add(label1);<br>
setTitle("Chat&WhiteBoard Server 1.0 - Quit");<br>
setResizable(false);<br>
//}}<br>
}<br>
<br>
public QuitDialog(Frame parent, String title, boolean modal) {<br>
this(parent, modal);<br>
setTitle(title);<br>
}<br>
<br>
public synchronized void show() {<br>
Rectangle bounds = getParent().bounds();<br>
Rectangle abounds = bounds();<br>
<br>
move(bounds.x + (bounds.width - abounds.width)/ 2,<br>
bounds.y + (bounds.height - abounds.height)/2);<br>
<br>
super.show();<br>
}<br>
<br>
public boolean handleEvent(Event event) {<br>
if(event.id == Event.WINDOW_DESTROY) {<br>
hide();<br>
return true;<br>
}<br>
if (event.target == noButton && event.id <br>
== Event.ACTION_EVENT) {<br>
noButton_Clicked(event);<br>
}<br>
if (event.target == yesButton && event.id<br>
== Event.ACTION_EVENT) {<br>
yesButton_Clicked(event);<br>
}<br>
return super.handleEvent(event);<br>
}<br>
<br>
//{{DECLARE_CONTROLS<br>
java.awt.Button yesButton;<br>
java.awt.Button noButton;<br>
java.awt.Label label1;<br>
//}}<br>
}<br>
/*<br>
A basic extension of the java.awt.Dialog class<br>
*/<br>
<br>
//class 6:"AboutDialog",服务器"关于"对话框<br>
public class AboutDialog extends Dialog {<br>
void okButton_Clicked(Event event) {<br>
//{{CONNECTION<br>
// Clicked from okButton Hide the Dialog<br>
hide();<br>
//}}<br>
}<br>
<br>
public AboutDialog(Frame parent, boolean modal) {<br>
<br>
super(parent, modal);<br>
//setIconImage(icon);<br>
//{{INIT_CONTROLS<br>
setLayout(null);<br>
addNotify();<br>
resize(insets().left + insets().right + 249,<br>
insets().top + insets().bottom + 170);<br>
label1 = new java.awt.Label("Chat&WhiteBoard<br>
Server 1.0",Label.CENTER);<br>
label1.reshape(insets().left + 36,<br>
insets().top + 12,166,21);<br>
add(label1);<br>
label2 = new java.awt.Label("清华大学汽车工程系",Label.CENTER);<br>
label2.reshape(insets().left + 36,insets().top + 36,168,24);<br>
add(label2);<br>
okButton = new java.awt.Button("OK");<br>
okButton.reshape(insets().left + 96,insets().top + 132,66,27);<br>
add(okButton);<br>
label3 = new java.awt.Label("学生科学技术协会制作",Label.CENTER);<br>
label3.reshape(insets().left + 36,insets().top + 60,168,24);<br>
add(label3);<br>
label4 = new java.awt.Label("(c)版权所有",Label.CENTER);<br>
label4.reshape(insets().left + 24,insets().top + 84,192,24);<br>
add(label4);<br>
label5 = new java.awt.Label("1998年8月",Label.CENTER);<br>
label5.reshape(insets().left + 72,insets().top + 108,96,24);<br>
add(label5);<br>
setTitle("About");<br>
setResizable(false);<br>
//}}<br>
}<br>
<br>
public AboutDialog(Frame parent, String title, boolean modal) {<br>
this(parent, modal);<br>
setTitle(title);<br>
}<br>
<br>
public synchronized void show() {<br>
Rectangle bounds = getParent().bounds();<br>
Rectangle abounds = bounds();<br>
<br>
move(bounds.x + (bounds.width - abounds.width)/ 2,<br>
bounds.y + (bounds.height - abounds.height)/2);<br>
<br>
super.show();<br>
}<br>
<br>
public boolean handleEvent(Event event) {<br>
if(event.id == Event.WINDOW_DESTROY) {<br>
hide();<br>
return true;<br>
}<br>
if (event.target == okButton && event.id == Event.ACTION_EVENT) {<br>
okButton_Clicked(event);<br>
}<br>
return super.handleEvent(event);<br>
}<br>
<br>
//{{DECLARE_CONTROLS<br>
java.awt.Label label1;<br>
java.awt.Label label2;<br>
java.awt.Button okButton;<br>
java.awt.Label label3;<br>
java.awt.Label label4;<br>
java.awt.Label label5;<br>
//}}<br>
}<br>
/*<br>
A basic extension of the java.applet.Applet class<br>
*/<br>
<br>
//class 7:ChatApplet,电子白板客户端Applet核心类 <br>
public class ChatApplet extends Applet implements Runnable {<br>
<br>
volatile boolean logged=false;<br>
volatile boolean belongRoom=false;<br>
volatile boolean paused=false;<br>
volatile boolean roomDataValid=false;<br>
URL url=null;<br>
int port=0;<br>
Socket s=null;<br>
Color currentColor=null;<br>
int x0=0,y0=0,x1=0,y1=0;<br>
String userName=null;<br>
String roomName=null;<br>
int roomID=0;<br>
Rooms rooms=null;<br>
Thread thread=null;<br>
DataInputStream io_in=null;<br>
DataOutputStream io_out=null;<br>
DataOutputStream piped_out=null;<br>
SendDrawData sender=null;<br>
int logo_x=0,logo_y=0,logo_width=0,logo_height=0;<br>
<br>
public void start() {<br>
if (thread==null) {<br>
thread=new Thread(this);<br>
thread.start();<br>
}<br>
}<br>
// method 'start' ended<br>
<br>
public void stop() {<br>
if (thread!=null) {<br>
quitButton_Clicked(new Event(this,0,null));<br>
message_TextArea.setText("");<br>
thread.stop();<br>
thread=null;<br>
}<br>
}<br>
//method 'stop' ended<br>
<br>
public void destroy() {<br>
try{<br>
commandCenter("ask_quit",new
DataBag("none","none",0,0,0,0,0));<br>
if (sender!=null) {<br>
sender.quit();<br>
sender=null;<br>
}<br>
socketClose();<br>
}catch(Exception e){<br>
System.out.println(e);<br>
}<br>
}<br>
//method 'destroy' close<br>
<br>
public void socketClose() {<br>
try{<br>
piped_out.flush();<br>
piped_out.close();<br>
piped_out=null;<br>
}catch(IOException e){<br>
System.out.println(e);<br>
}<br>
try{<br>
io_in.close();<br>
io_in=null;<br>
}catch(Exception e){}<br>
try{<br>
io_out.flush();<br>
io_out.close();<br>
io_out=null;<br>
}catch(Exception e){}<br>
try{<br>
s.close();<br>
s=null;<br>
}catch(Exception e){}<br>
}<br>
//method 'socketClose' ended<br>
<br>
public void commandCenter(String command,<br>
DataBag data) throws PleaseCloseSocketException {<br>
if (command.equals("ask_refresh")) client_ask_refresh();<br>
else if (command.equals("refresh")) client_answer_refresh();<br>
else if (command.equals("ask_log")) client_ask_log();<br>
else if (command.equals("ask_join")) client_ask_join();<br>
else if (command.equals("ask_pause")) client_ask_pause();<br>
else if (command.equals("ask_continue")) client_ask_continue();<br>
else if (command.equals("ask_new")) client_ask_newRoom();<br>
else if (command.equals("ask_quit")) client_ask_quit();<br>
else if (command.equals("ask_text")) client_ask_text(data);<br>
else if (command.equals("text")) client_answer_text();<br>
else if (command.equals("draw")) client_answer_draw();<br>
<br>
}// method commandCenter ended<br>
<br>
private void client_answer_text() throws PleaseCloseSocketException{<br>
<br>
String message=null;<br>
String name=null;<br>
DataBag data=null;<br>
<br>
try{<br>
name=io_in.readUTF();<br>
message=io_in.readUTF();<br>
data=new DataBag(name,message,0,0,0,0,0);<br>
printChat_Area(data);<br>
<br>
}catch(IOException e){<br>
message_TextArea.appendText("抱歉,无法正确接受句子");<br>
throw new PleaseCloseSocketException();<br>
<br>
}<br>
}//method 'client_answer_text' ended<br>
<br>
private void client_answer_draw() <br>
throws PleaseCloseSocketException {<br>
<br>
DataBag data=null;<br>
int color=0,x0=0,y0=0,x1=0,y1=0;<br>
<br>
try{<br>
color=io_in.readInt();<br>
x0=io_in.readShort();<br>
y0=io_in.readShort();<br>
x1=io_in.readShort();<br>
y1=io_in.readShort();<br>
<br>
data=new DataBag("none","none",color,x0,y0,x1,y1);<br>
drawBoard_Canvas(data);<br>
<br>
}catch(IOException e){<br>
message_TextArea.appendText("抱歉,无法正确接受图形");<br>
throw new PleaseCloseSocketException();<br>
<br>
}<br>
}//mwthod 'client_answer_draw' ended<br>
<br>
private void client_ask_text(DataBag data)<br>
throws PleaseCloseSocketException {<br>
<br>
String message=null;<br>
<br>
try{<br>
synchronized(sender){<br>
io_out.writeUTF("text");<br>
io_out.writeUTF(data.message);<br>
}<br>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -