?? eboardserver.java
字號(hào):
package whiteboard;
import java.rmi.*;
import java.lang.*;
import javax.swing.*;
import java.awt.*;
import javax.swing.table.*;
import java.awt.event.*;
//import java.rmi.server.UnicastRemoteObject;
public class eboardServer extends JFrame
{
eboardServant board1;
static MyDefaultTableModel model;
static MyDefaultTableModel addmodel;
public eboardServer(String hostname)
{
super("Management console");
model = new MyDefaultTableModel();
model.setFlag(0);
addmodel = new MyDefaultTableModel();
addmodel.setFlag(1);
JTable table = new JTable(model);
JTable addtable = new JTable(addmodel);
model.addColumn("ID");
addmodel.addColumn("ID");
model.addColumn("name");
addmodel.addColumn("name");
model.addColumn("delete client");
addmodel.addColumn("add client");
table.setPreferredScrollableViewportSize(new Dimension(500, 70));
JPanel panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
//Create the scroll pane and add the table to it.
JScrollPane scrollPane = new JScrollPane(table);
JScrollPane addscrollPane = new JScrollPane(addtable);
panel.add(scrollPane);
panel.add(addscrollPane);
//Add the scroll pane to this window.
getContentPane().add(panel);
//getContentPane().add(scrollPane, BorderLayout.WEST);
System.setSecurityManager(new RMISecurityManager());
System.out.println("Main OK");
try{
board1 = new eboardServant();
System.out.println("After create");
Naming.rebind("rmi://"+hostname+"/WhiteBoard", board1);
System.out.println("eboard server ready");
}catch(Exception e) {
System.out.println("eboard server main " + e.getMessage());
}
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
board1.notifyallwarning("Server has left");
System.out.println("Exit");
System.exit(0);
}
});
}
public void maxReached()
{
JDialog dialog = new JDialog(this, "Warning ");
//Add contents to it.
JLabel label = new JLabel("Max number of client is connected.Can not add more");
label.setHorizontalAlignment(JLabel.CENTER);
Container contentPane = dialog.getContentPane();
contentPane.add(label, BorderLayout.CENTER);
//Show it.
dialog.setSize(new Dimension(400, 150));
dialog.setLocationRelativeTo(this);
dialog.setVisible(true);
}
class MyDefaultTableModel extends DefaultTableModel {
// flag = 0 => delete
// flag = 1 => add
int flag;
public void setFlag(int flag) {
this.flag =flag;
}
public Class getColumnClass(int c) {
return getValueAt(0, c).getClass();
}
public boolean isCellEditable(int row, int col)
{
if (col < 2)
{
return false;
}
else
{
return true;
}
}
public void setValueAt(Object value, int row, int col) {
// int id = ((Integer) addmodel.getValueAt( row,0)).intValue();
// String name = (String) addmodel.getValueAt(row,1);
//this.removeRow(row);
if( this.flag == 1) {
if (model.getRowCount() > 5)
{
maxReached();
return;
}
int id = ((Integer) addmodel.getValueAt( row,0)).intValue();
String name = (String) addmodel.getValueAt(row,1);
model.addRow(new Object[]{id,name, new Boolean(false)});
for(int i=0;i<board1.customerList.size();i++)
{
if(((parcel)(board1.customerList.elementAt(i))).tag==id) {
System.out.println("index="+i+"id"+id);
System.out.println("status =" + ((parcel) (board1.customerList.elementAt(i))).connectStatus);
((parcel) (board1.customerList.elementAt(i))).setConnectStatus(true);
System.out.println("status =" + ((parcel) (board1.customerList.elementAt(i))).connectStatus);
try
{
board1.notifyit(i);
board1.notifyitwarning(i,"You have been connected");
}
catch (Exception e){
;
}
this.removeRow(row);
}
}
}
if( this.flag == 0) {
if(row !=0) {
int id = ((Integer) model.getValueAt( row,0)).intValue();
String name = (String) model.getValueAt(row,1);
addmodel.addRow(new Object[]{id,name, new Boolean(false)});
for(int i=0;i<board1.customerList.size();i++)
{
if(((parcel)(board1.customerList.elementAt(i))).tag==id) {
((parcel) (board1.customerList.elementAt(i))).setConnectStatus(false);
this.removeRow(row);
}
}
}
}
}
}
public static void main(String args[])
{
/*
System.setSecurityManager(new RMISecurityManager());
System.out.println("Main OK");
try{
eboard board1 = new eboardServant();
System.out.println("After create");
Naming.rebind("rmi://"+args[0]+"/WhiteBoard", board1);
System.out.println("eboard server ready");
}catch(Exception e) {
System.out.println("eboard server main " + e.getMessage());
}
*/
eboardServer serverframe = new eboardServer(args[0]);
serverframe.pack();
serverframe.setVisible(true);
WhiteboardFrame newPad=new WhiteboardFrame(args[0],"SERVER");
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -