?? maingui.java
字號(hào):
}
});
menuItem_3.setText("啟動(dòng)服務(wù)");
menu_5.add(menuItem_3);
final JMenuItem menuItem_4 = new JMenuItem();
menuItem_4.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent e) {
int i=JOptionPane.showConfirmDialog(frame,"停止服務(wù)后再啟動(dòng)服務(wù)需重新登錄,確定要停止服務(wù)?","提示",JOptionPane.YES_OPTION,JOptionPane.INFORMATION_MESSAGE,null);
if(i==0)
{
try {
if(serverSocket!=null)serverSocket.close();
t.interrupt();//中斷服務(wù)線程
MainGUI.label.setText("處于停止服務(wù)中..");
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
textArea.append("系統(tǒng)提示:"+" 聊天服務(wù)器"+" 已經(jīng)停止\n");
}
}
});
menuItem_4.setText("停止服務(wù)");
menu_5.add(menuItem_4);
final JMenu menu_8 = new JMenu();
menu_8.setText("查看");
menuBar.add(menu_8);
final JMenuItem menuItem_18 = new JMenuItem();
menuItem_18.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent e) {
new ShowAllUserInfoGUI().showGUI();
}
});
menuItem_18.setText("所有用戶信息");
menu_8.add(menuItem_18);
final JMenuItem menuItem_19 = new JMenuItem();
menuItem_19.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent e) {
new ShowMasterAllInfo().showGUI();
}
});
menuItem_19.setText("所有普通管理員");
menu_8.add(menuItem_19);
final JMenu menu_9 = new JMenu();
menu_9.setText("關(guān)于");
menuBar.add(menu_9);
final JMenuItem menuItem_1 = new JMenuItem();
menuItem_1.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent e) {
new ShowAnent().showGUI();
}
});
menuItem_1.setText("程序");
menu_9.add(menuItem_1);
time = new JLabel();
time.setText("當(dāng)前日期為:");
time.setBounds(331, 405, 128, 26);
frame.getContentPane().add(time);
happylabel = new JLabel();
happylabel.setBounds(10, 411, 277, 15);
happylabel.setText(" "+name+" 歡迎使用企業(yè)即時(shí)通 ...");
frame.getContentPane().add(happylabel);
final JPanel panel = new JPanel();
panel.setLayout(null);
panel.setBounds(0, -2, 461, 37);
frame.getContentPane().add(panel);
final JToolBar toolBar_1 = new JToolBar();
toolBar_1.setBounds(0, 5, 535, 33);
panel.add(toolBar_1);
final JButton button = new JButton();
button.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent e) {
if(serverSocket == null)
{
try
{
serverSocket = new ServerSocket(MainGUI.SOCKET);
MainGUI.label.setText("當(dāng)前在線人數(shù)為: 0");
textArea.append("系統(tǒng)提示:"+" 聊天服務(wù)器"+" 正在啟動(dòng)......\n");
textArea.append("系統(tǒng)提示:"+" 聊天服務(wù)器"+" 啟動(dòng)完成......\n");
}
catch(IOException ex)
{
textArea.append("系統(tǒng)提示:"+" 聊天服務(wù)器"+" 啟動(dòng)失??!\n");
}
}
else
{
textArea.append("系統(tǒng)提示:"+" 聊天服務(wù)器"+" 已經(jīng)啟動(dòng)\n");
}
//啟動(dòng)監(jiān)聽客戶端連接線程
t.start();
}
});
button.addMouseListener(new MouseAdapter() {
public void mouseEntered(final MouseEvent e) {
button.setIcon(SwingResourceManager.getIcon(MainGUI.class, "/edu/sccp/chat/image/F1.png"));
}
public void mouseExited(final MouseEvent e) {
button.setIcon(SwingResourceManager.getIcon(MainGUI.class, "/edu/sccp/chat/image/F2.png"));
}
});
button.setToolTipText("啟動(dòng)服務(wù)");
button.setIcon(SwingResourceManager.getIcon(MainGUI.class, "/edu/sccp/chat/image/F2.png"));
toolBar_1.add(button);
final JButton button_1 = new JButton();
button_1.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent e) {
int i=JOptionPane.showConfirmDialog(frame,"停止服務(wù)后再啟動(dòng)服務(wù)需重新登錄,確定要停止服務(wù)?","注意",JOptionPane.YES_OPTION,JOptionPane.INFORMATION_MESSAGE,null);
if(i==0)
{
try{
if(serverSocket!=null)serverSocket.close();
t.interrupt();//中斷服務(wù)線程
MainGUI.label.setText("處于停止服務(wù)中..");
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
textArea.append("系統(tǒng)提示:"+" 聊天服務(wù)器"+" 已經(jīng)停止\n");
}
}
});
button_1.addMouseListener(new MouseAdapter() {
public void mouseEntered(final MouseEvent e) {
button_1.setIcon(SwingResourceManager.getIcon(MainGUI.class, "/edu/sccp/chat/image/F3.png"));
}
public void mouseExited(final MouseEvent e) {
button_1.setIcon(SwingResourceManager.getIcon(MainGUI.class, "/edu/sccp/chat/image/F4.png"));
}
});
button_1.setToolTipText("停止服務(wù)");
button_1.setIcon(SwingResourceManager.getIcon(MainGUI.class, "/edu/sccp/chat/image/F4.png"));
toolBar_1.add(button_1);
final JButton button_4 = new JButton();
button_4.setToolTipText("查看服務(wù)器設(shè)置");
button_4.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent e) {
new Intercalate().showGUI();
}
});
toolBar_1.add(button_4);
button_4.setIcon(SwingResourceManager.getIcon(MainGUI.class, "/edu/sccp/chat/image/S1.png"));
toolBar_1.addSeparator();
final JButton button_2 = new JButton();
button_2.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent e) {
new ShowAnent().showGUI();
}
});
button_2.addMouseListener(new MouseAdapter() {
public void mouseEntered(final MouseEvent e) {
button_2.setIcon(SwingResourceManager.getIcon(MainGUI.class, "/edu/sccp/chat/image/G1.png"));
}
public void mouseExited(final MouseEvent e) {
button_2.setIcon(SwingResourceManager.getIcon(MainGUI.class, "/edu/sccp/chat/image/G2.png"));
}
});
button_2.setToolTipText("關(guān)于程序");
button_2.setIcon(SwingResourceManager.getIcon(MainGUI.class, "/edu/sccp/chat/image/G2.png"));
toolBar_1.add(button_2);
final JButton button_3 = new JButton();
button_3.setIcon(SwingResourceManager.getIcon(MainGUI.class, "/edu/sccp/chat/image/zhuxiao.png"));
button_3.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent e) {
int i=JOptionPane.showConfirmDialog(frame,"確定要退出?","提示",JOptionPane.YES_OPTION,JOptionPane.INFORMATION_MESSAGE,null);
if(i==0)
{
try {
if(serverSocket!=null)serverSocket.close();
t.interrupt();//中斷服務(wù)線程
} catch (IOException e1) {
// TODO Auto-generated catch block
}
System.exit(0);
}
}
});
button_3.setToolTipText("退出");
toolBar_1.add(button_3);
toolBar_1.addSeparator();
label = new JLabel();
toolBar_1.add(label);
label.setText("處于停止服務(wù)中..");
final JScrollPane scrollPane = new JScrollPane();
scrollPane.setBorder(BorderFactory.createTitledBorder("系統(tǒng)信息"));
scrollPane.setBounds(0, 41, 451, 293);
frame.getContentPane().add(scrollPane);
textArea = new JTextArea();
textArea.setEditable(false);
textArea.setLineWrap(true);
scrollPane.setViewportView(textArea);
final JButton button_5 = new JButton();
button_5.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent e) {
String str= sendtextArea.getText();
Vector vc=new Vector();
vc.add("系統(tǒng)信息");
vc.add(str);
Set keys =MainGUI.soceketMap.keySet();
Iterator key_iter = keys.iterator();
while(key_iter.hasNext()){//發(fā)給其他在線用戶
ObjectOutputStream tempoos = (ObjectOutputStream)MainGUI.soceketMap.get(key_iter.next());
try {
tempoos.writeObject(vc);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
sendtextArea.setText("");
}
});
button_5.setText("發(fā)送");
button_5.setBounds(360, 374, 73, 25);
frame.getContentPane().add(button_5);
final JScrollPane scrollPane_2 = new JScrollPane();
scrollPane_2.setBounds(0, 341, 354, 60);
frame.getContentPane().add(scrollPane_2);
scrollPane_2.setBorder(BorderFactory.createTitledBorder("發(fā)送系統(tǒng)消息"));
sendtextArea = new JTextArea();
sendtextArea.setLineWrap(true);
scrollPane_2.setViewportView(sendtextArea);
new Time().start();
}
public void showGUI()
{
frame.setResizable(false);
frame.setSize(467,490);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
class Time extends Thread
{
SimpleDateFormat sim=new SimpleDateFormat("hh:mm:ss");
public void run()
{
while(true)
{ int a=((int)(Math.random()*1000)+255)%255;
int b=((int)(Math.random()*1000)+255)%255;
int c=((int)(Math.random()*1000)+255)%255;
time.setForeground(new Color(a,b,c));
String str=sim.format(new Date(System.currentTimeMillis()));
time.setText("當(dāng)前時(shí)間為:"+str);
try {
sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
new MainGUI("20080001","001","5566").showGUI();
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -