📄 whiteboardframe.java
字号:
package mywb;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.net.*;
import java.util.*;
import javax.swing.*;
public class WhiteBoardFrame extends JFrame {
private String serIp = null;
private String serPort =null;
private String myName = null;
public boolean active = false ;
private BorderLayout borderLayout1 = new BorderLayout();
private BorderLayout borderLayout2 = new BorderLayout();
private BorderLayout borderLayout3 = new BorderLayout();
private BorderLayout borderLayout4 = new BorderLayout();
private BorderLayout borderLayout5 = new BorderLayout();
private BorderLayout borderLayout6 = new BorderLayout();
private BorderLayout borderLayout7 = new BorderLayout();
private BorderLayout borderLayout8 = new BorderLayout();
private BorderLayout borderLayout9 = new BorderLayout();
private BorderLayout borderLayout10 = new BorderLayout();
private BorderLayout borderLayout11 = new BorderLayout();
private BorderLayout borderLayout12 = new BorderLayout();
private BorderLayout borderLayout13 = new BorderLayout();
private BorderLayout borderLayout14 = new BorderLayout();
private BorderLayout borderLayout15 = new BorderLayout();
private GridLayout gridLayout1 = new GridLayout();
private GridLayout gridLayout2 = new GridLayout();
private GridLayout gridLayout3 = new GridLayout();
private GridLayout gridLayout4 = new GridLayout();
private JPanel jPanel1 = new JPanel();
private JPanel jPanel2 = new JPanel();
private JPanel jPanel3 = new JPanel();
private JPanel jPanel4 = new JPanel();
private JPanel jPanel5 = new JPanel();
private JPanel jPanel6 = new JPanel();
private JPanel jPanel7 = new JPanel();
private JPanel jPanel8 = new JPanel();
private JPanel jPanel9 = new JPanel();
private JPanel selPane = new JPanel();
private JPanel ranLinePane = new JPanel();
private JPanel frectPanel = new JPanel();
private JPanel rrecPanel = new JPanel();
private JPanel fovalPanel = new JPanel();
private JPanel ovalPanel = new JPanel();
private JPanel frecPanel = new JPanel();
private JPanel recPanel = new JPanel();
private JPanel linePanel = new JPanel();
private JPanel grayColorPanel = new JPanel();
private JPanel blueColorPanel = new JPanel();
private JPanel cyanColorPanel = new JPanel();
private JPanel magentaColorPanel = new JPanel();
private JPanel greenColorPanel = new JPanel();
private JPanel orangeColorPanel = new JPanel();
private JPanel redColorPanel = new JPanel();
private JPanel blackColorPanel = new JPanel();
private JButton selBut = new JButton();
private JButton lineBut = new JButton();
private JButton recBut = new JButton();
private JButton frecBut = new JButton();
private JButton ovalBut = new JButton();
private JButton fovalBut = new JButton();
private JButton rrecBut = new JButton();
private JButton frrecBut = new JButton();
private JButton rlineBut = new JButton();
private JLabel jLabel2 = new JLabel();
private JLabel jLabel3 = new JLabel();
private JLabel jLabel4 = new JLabel();
private JLabel jLabel5 = new JLabel();
private JLabel jLabel6 = new JLabel();
private JLabel jLabel7 = new JLabel();
private String path = "./images/line.gif";
private ImageIcon lineimage = new ImageIcon(getClass().getResource(path));
private String path1 = "./images/rline.gif";
private ImageIcon rlinimage = new ImageIcon(getClass().getResource(path1));
private String path2 = "./images/rect.gif";
private ImageIcon rectimage = new ImageIcon(getClass().getResource(path2));
private String path3 = "./images/rrect.gif";
private ImageIcon rrectimage = new ImageIcon(getClass().getResource(path3));
private String path4 = "./images/oval.gif";
private ImageIcon ovalimage = new ImageIcon(getClass().getResource(path4));
private String path5 = "./images/foval.gif";
private ImageIcon fovalimage = new ImageIcon(getClass().getResource(path5));
private String path6 = "./images/frect.gif";
private ImageIcon frectimage = new ImageIcon(getClass().getResource(path6));
private String path8 = "./images/frrect.gif";
private ImageIcon frrectimage = new ImageIcon(getClass().getResource(path8));
private String path9 = "./images/select.gif";
private ImageIcon selectimage = new ImageIcon(getClass().getResource(path9));
//Get a parameter value
static PrintStream ps=null; //定义打印流
public Socket clientSocket = null;
static String message = null;
public static int i;
//whiteboard
public int colorindex;
public Color color = null;
public int currentTool =0;
public int x0, y0, x1, y1, width, height;
public int xold, yold, wold, hold;
public Class cl;
public Element element = null;
public Vector elements = new Vector();
public WhiteBoardPanel whiteBoard = null;
public static String name = "";
//构造函数
public WhiteBoardFrame(String serIp,String serPort,String name) {
this.serIp = serIp;
this.serPort =serPort;
this.myName = name;
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (ClassNotFoundException e1) {
e1.printStackTrace();
} catch (InstantiationException e1) {
e1.printStackTrace();
} catch (IllegalAccessException e1) {
e1.printStackTrace();
} catch (UnsupportedLookAndFeelException e1) {
e1.printStackTrace();
}
init();
}
// 初始化
public void init() {
try {
jbInit();
} catch (Exception e) {
e.printStackTrace();
return;
}
color = Color.gray;
//whiteboard
try{
int port = Integer.parseInt(serPort);
clientSocket = new Socket(serIp,port);
whiteBoard = new WhiteBoardPanel(clientSocket);
whiteBoard.setBackground(Color.white);
whiteBoard.setType(currentTool);
jPanel2.add(whiteBoard,BorderLayout.CENTER);
whiteBoard.setColor(color);
status(currentTool,0);
}catch(Exception ex){
ex.printStackTrace();
System.out.println("failed to connect to wbServer");
}
}
//模块初始化
private void jbInit() throws Exception {
this.setLayout(borderLayout1);
jPanel1.setLayout(borderLayout2);
jPanel3.setLayout(borderLayout4);
jPanel1.setBackground(Color.white);
jPanel1.setPreferredSize(new Dimension(80, 300));
jPanel3.setBorder(BorderFactory.createEtchedBorder());
jPanel3.setPreferredSize(new Dimension(80, 300));
jPanel3.addMouseListener(new java.awt.event.MouseAdapter() {
});
jPanel4.setLayout(borderLayout6);
jPanel5.setLayout(gridLayout2);
gridLayout2.setHgap(2);
gridLayout2.setVgap(2);
jPanel6.setBorder(BorderFactory.createEtchedBorder());
jPanel6.setPreferredSize(new Dimension(10, 200));
jPanel6.setLayout(borderLayout5);
jPanel7.setPreferredSize(new Dimension(10, 20));
jPanel7.setLayout(gridLayout3);
jLabel2.setForeground(SystemColor.desktop);
jLabel2.setPreferredSize(new Dimension(20, 18));
jLabel2.setText("工具");
jLabel4.setForeground(SystemColor.desktop);
jLabel4.setText("");
jLabel6.setForeground(SystemColor.desktop);
jLabel6.setText("颜色");
jPanel9.setLayout(gridLayout1);
jPanel8.setLayout(gridLayout4);
gridLayout4.setColumns(2);
gridLayout4.setHgap(1);
gridLayout4.setRows(0);
gridLayout4.setVgap(1);
gridLayout1.setColumns(2);
gridLayout1.setHgap(1);
gridLayout1.setRows(0);
gridLayout1.setVgap(1);
selPane.setBorder(BorderFactory.createLineBorder(Color.black));
selPane.setToolTipText("");
selPane.setLayout(borderLayout7);
selBut.addMouseListener(new java.awt.event.MouseAdapter() {
public void mousePressed(MouseEvent e) {
select_mousePressed(e);
}
});
frectPanel.setBorder(BorderFactory.createLineBorder(Color.black));
frectPanel.setLayout(borderLayout14);
frrecBut.addMouseListener(new java.awt.event.MouseAdapter() {
public void mousePressed(MouseEvent e) {
frrect_mousePressed(e);
}
});
ranLinePane.setBorder(BorderFactory.createLineBorder(Color.black));
ranLinePane.setLayout(borderLayout15);
rlineBut.addMouseListener(new java.awt.event.MouseAdapter() {
public void mousePressed(MouseEvent e) {
rline_mousePressed(e);
}
});
rrecPanel.setBorder(BorderFactory.createLineBorder(Color.black));
rrecPanel.setLayout(borderLayout13);
rrecBut.addMouseListener(new java.awt.event.MouseAdapter() {
public void mousePressed(MouseEvent e) {
rrect_mousePressed(e);
}
});
ovalPanel.setBorder(BorderFactory.createLineBorder(Color.black));
ovalPanel.setLayout(borderLayout11);
ovalBut.addMouseListener(new java.awt.event.MouseAdapter() {
public void mousePressed(MouseEvent e) {
oval_mousePressed(e);
}
});
fovalPanel.setBorder(BorderFactory.createLineBorder(Color.black));
fovalPanel.setLayout(borderLayout12);
fovalBut.addMouseListener(new java.awt.event.MouseAdapter() {
public void mousePressed(MouseEvent e) {
foval_mousePressed(e);
}
});
recPanel.setBorder(BorderFactory.createLineBorder(Color.black));
recPanel.setLayout(borderLayout9);
recBut.addMouseListener(new java.awt.event.MouseAdapter() {
public void mousePressed(MouseEvent e) {
rect_mousePressed(e);
}
});
frecPanel.setBorder(BorderFactory.createLineBorder(Color.black));
frecPanel.setLayout(borderLayout10);
frecBut.addMouseListener(new java.awt.event.MouseAdapter() {
public void mousePressed(MouseEvent e) {
frect_mousePressed(e);
}
});
linePanel.setBorder(BorderFactory.createLineBorder(Color.black));
linePanel.setLayout(borderLayout8);
lineBut.addMouseListener(new java.awt.event.MouseAdapter() {
public void mousePressed(MouseEvent e) {
line_mousePressed(e);
}
});
blueColorPanel.setBackground(Color.blue);
blueColorPanel.setBorder(BorderFactory.createLineBorder(Color.black));
blueColorPanel.addMouseListener(new java.awt.event.MouseAdapter() {
public void mousePressed(MouseEvent e) {
blue_mousePressed(e);
}
});
grayColorPanel.setBackground(Color.gray);
grayColorPanel.setBorder(BorderFactory.createLineBorder(Color.black));
grayColorPanel.addMouseListener(new java.awt.event.MouseAdapter() {
public void mousePressed(MouseEvent e) {
gray_mousePressed(e);
}
});
cyanColorPanel.setBackground(Color.cyan);
cyanColorPanel.setBorder(BorderFactory.createLineBorder(Color.black));
cyanColorPanel.addMouseListener(new java.awt.event.MouseAdapter() {
public void mousePressed(MouseEvent e) {
cyan_mousePressed(e);
}
});
magentaColorPanel.setBackground(Color.magenta);
magentaColorPanel.setBorder(BorderFactory.createLineBorder(Color.black));
magentaColorPanel.addMouseListener(new java.awt.event.MouseAdapter() {
public void mousePressed(MouseEvent e) {
magenta_mousePressed(e);
}
});
greenColorPanel.setBackground(Color.green);
greenColorPanel.setBorder(BorderFactory.createLineBorder(Color.black));
greenColorPanel.addMouseListener(new java.awt.event.MouseAdapter() {
public void mousePressed(MouseEvent e) {
green_mousePressed(e);
}
});
orangeColorPanel.setBackground(Color.orange);
orangeColorPanel.setBorder(BorderFactory.createLineBorder(Color.black));
orangeColorPanel.addMouseListener(new java.awt.event.MouseAdapter() {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -