package chat;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import com.borland.jbcl.layout.*;
import javax.swing.border.*;
import java.lang.Exception;
import java.net.*;
import java.io.*;
import java.util.Date;
import javax.swing.event.*;
/**
* <p>Title: 使用JAVA制作的局域网聊天程序</p>
* <p>Description: 我们的JAVA作业</p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company: </p>
* @author RoadAhead
* @version 1.0
*/
public class mainform extends JFrame
{
private JPanel contentPane;
static JPanel jPanel1 = new JPanel();
private JPanel jPanel2 = new JPanel();
private JButton but_online = new JButton();
private BorderLayout borderLayout2 = new BorderLayout();
private JMenuBar jMenuBar1 = new JMenuBar();
static JSplitPane jsp8 = new JSplitPane();
private JPanel jPanel5 = new JPanel();
private JButton but_exit = new JButton();
private JMenu jMenu1 = new JMenu();
private JButton but_offline = new JButton();
private JButton but_about = new JButton();
private JPanel pan_state = new JPanel();
static JTextPane ed_input = new JTextPane();
private PaneLayout paneLayout1 = new PaneLayout();
private TitledBorder titledBorder1;
private TitledBorder titledBorder2;
static Label lab_uname = new Label();
static JLabel lab_uimage = new JLabel();
private JLabel jLabel2 = new JLabel();
private JLabel lab_info = new JLabel();
static final int PORT=5001;
static String curuserip="";
static String curusername="";
static String curusericon="";
static String myname="";
static String myicon="";
static String myip;
static String onstartset="";
static String filename="chatset.amy";
static String winstate="0";
static int maxStrCount=10000;
static int onlinestate=2;//是否在线 1: 在线 2:断线 3: 离线
static String onofflinetime=""; //当离线时的回答
private JButton but_setup = new JButton();
static String[][] userlist;//用户列表
static JButton[] but_userlist; //用户图象按钮
private JScrollPane jsp = new JScrollPane();
static JPanel pan_userlist = new JPanel();
private TitledBorder titledBorder3;
private PaneLayout paneLayout2 = new PaneLayout();
static JLabel lab_my = new JLabel();
private TitledBorder titledBorder4;
newthread mythread=new newthread();
static DatagramPacket sendpacket,receivepacket;
static DatagramSocket sendsocket,receivesocket;
private JScrollPane jScrollPane1 = new JScrollPane();
static JTextArea ed_show = new JTextArea();
private JCheckBox cbo_bc = new JCheckBox();
private JScrollPane jScrollPane2 = new JScrollPane();
JOptionPane pane = new JOptionPane();
Date nowtime=new Date();
private JPopupMenu pop_menu = new JPopupMenu();
private JMenuItem jMenuItem1 = new JMenuItem();
private JMenuItem jMenuItem2 = new JMenuItem();
private JButton but_pause = new JButton();
private BoxLayout2 boxLayout21 = new BoxLayout2();
private Label label1 = new Label();
private Label label2 = new Label();
private BorderLayout borderLayout1 = new BorderLayout();
VerticalFlowLayout verticalFlowLayout1 = new VerticalFlowLayout();
//Construct the frame
public mainform()
{
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try
{
jbInit();
}
catch(Exception e)
{
e.printStackTrace();
}
}
//Component initialization
private void jbInit() throws Exception
{
try{
sendsocket=new DatagramSocket();
receivesocket=new DatagramSocket(5001);
}
catch(SocketException se){
se.printStackTrace();
}
mainform.userlist=new String[1][5];
but_userlist=new JButton [1];
//setIconImage(Toolkit.getDefaultToolkit().createImage(mainform.class.getResource("[Your Icon]")));
contentPane = (JPanel) this.getContentPane();
titledBorder1 = new TitledBorder("");
titledBorder2 = new TitledBorder("");
titledBorder3 = new TitledBorder("");
titledBorder4 = new TitledBorder("");
contentPane.setLayout(borderLayout1);
this.setSize(new Dimension(523, 356));
this.setTitle("我们的聊天程序 Alt+Enter 发送消息");
this.addWindowListener(new java.awt.event.WindowAdapter()
{
public void windowOpened(WindowEvent e)
{
this_windowOpened(e);
}
public void windowActivated(WindowEvent e)
{
}
});
jPanel1.setBackground(Color.white);
jPanel1.setLayout(borderLayout2);
jPanel2.setBackground(Color.white);
jPanel2.setBorder(titledBorder4);
jPanel2.setToolTipText("");
jPanel2.setLayout(paneLayout2);
but_online.setBackground(Color.white);
but_online.setFont(new java.awt.Font("Serif", 0, 12));
but_online.setBorder(null);
but_online.setHorizontalTextPosition(SwingConstants.CENTER);
but_online.setText("在线");
but_online.setVerticalAlignment(SwingConstants.BOTTOM);
but_online.setVerticalTextPosition(SwingConstants.BOTTOM);
but_online.addMouseListener(new java.awt.event.MouseAdapter()
{
public void mouseExited(MouseEvent e)
{
but_online_mouseExited(e);
}
});
but_online.addMouseMotionListener(new java.awt.event.MouseMotionAdapter()
{
public void mouseMoved(MouseEvent e)
{
but_online_mouseMoved(e);
}
});
but_online.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(ActionEvent e)
{
but_online_actionPerformed(e);
}
});
jsp8.setBorder(null);
jsp8.setContinuousLayout(true);
jsp8.setDividerSize(2);
jsp8.setLeftComponent(pan_userlist);
but_exit.setBackground(Color.white);
but_exit.setFont(new java.awt.Font("Serif", 0, 12));
but_exit.setBorder(null);
but_exit.setHorizontalTextPosition(SwingConstants.CENTER);
but_exit.setText("退出");
but_exit.setVerticalAlignment(SwingConstants.BOTTOM);
but_exit.setVerticalTextPosition(SwingConstants.BOTTOM);
but_exit.addMouseMotionListener(new java.awt.event.MouseMotionAdapter()
{
public void mouseMoved(MouseEvent e)
{
but_exit_mouseMoved(e);
}
});
but_exit.addMouseListener(new java.awt.event.MouseAdapter()
{
public void mousePressed(MouseEvent e)
{
but_exit_mousePressed(e);
}
public void mouseExited(MouseEvent e)
{
but_exit_mouseExited(e);
}
});
but_exit.addKeyListener(new java.awt.event.KeyAdapter()
{
public void keyTyped(KeyEvent e)
{
but_exit_keyTyped(e);
}
});
jMenu1.setText("文件");
but_offline.setBackground(Color.white);
but_offline.setFont(new java.awt.Font("Serif", 0, 12));
but_offline.setBorder(null);
but_offline.setHorizontalTextPosition(SwingConstants.CENTER);
but_offline.setText("断线");
but_offline.setVerticalAlignment(SwingConstants.BOTTOM);
but_offline.setVerticalTextPosition(SwingConstants.BOTTOM);
but_offline.addMouseListener(new java.awt.event.MouseAdapter()
{
public void mouseExited(MouseEvent e)
{
but_offline_mouseExited(e);
}
});
but_offline.addMouseMotionListener(new java.awt.event.MouseMotionAdapter()
{
public void mouseMoved(MouseEvent e)
{
but_offline_mouseMoved(e);
}
});
but_offline.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(ActionEvent e)
{
but_offline_actionPerformed(e);
}
});
but_about.setBackground(Color.white);
but_about.setFont(new java.awt.Font("Serif", 0, 12));
but_about.setBorder(null);
but_about.setHorizontalTextPosition(SwingConstants.CENTER);
but_about.setText("关于这个程序");
but_about.setVerticalAlignment(SwingConstants.BOTTOM);
but_about.setVerticalTextPosition(SwingConstants.BOTTOM);
but_about.addMouseListener(new java.awt.event.MouseAdapter()
{
public void mouseExited(MouseEvent e)
{
but_about_mouseExited(e);
}
});
but_about.addMouse