📄 bandchatgui.java
字号:
package edu.sccp.chat.frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import com.swtdesigner.SwingResourceManager;
import edu.sccp.chat.action.ToServerProcess;
import edu.sccp.chat.jarClass.JarAllege;
import edu.sccp.chat.tools.FileStream;
public class BandChatGUI {
public static JTextArea receive;
private JTextArea send;
/**
* @param args
*/
JFrame frame;
String namestr;
String deptstr;
SimpleDateFormat sim=new SimpleDateFormat("yyyy年MM月dd日");
SimpleDateFormat sim1=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
public BandChatGUI(String name,String dept)
{
namestr=name;
deptstr=dept;
JarAllege.bai();
initGUI();
}
private void initGUI()
{
frame=new JFrame("群聊");
frame.setIconImage(SwingResourceManager.getImage(BandChatGUI.class, "/edu/sccp/chat/image/icon.png"));
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(final WindowEvent e) {
MainGUI.qun.remove("1");
frame.dispose();
}
});
frame.getContentPane().setLayout(null);
final JScrollPane scrollPane = new JScrollPane();
scrollPane.setBorder(BorderFactory.createTitledBorder("聊天内容"));
scrollPane.setBounds(10, 0, 298, 224);
frame.getContentPane().add(scrollPane);
receive = new JTextArea();
receive.setEditable(false);
receive.setLineWrap(true);
scrollPane.setViewportView(receive);
final JScrollPane scrollPane_1 = new JScrollPane();
scrollPane_1.setBorder(BorderFactory.createTitledBorder("发送内容"));
scrollPane_1.setBounds(10, 222, 298, 108);
frame.getContentPane().add(scrollPane_1);
send = new JTextArea();
send.addKeyListener(new KeyAdapter(){
public void keyPressed(KeyEvent e)
{
int i=e.getKeyCode();//快捷键Shift
if(i==KeyEvent.VK_ENTER)
{
String str=deptstr+" "+namestr+" "+sim1.format(new Date(System.currentTimeMillis()))+"说:\n"+send.getText()+"\n";
try {
ToServerProcess.oos.writeObject("群聊");
ToServerProcess.oos.writeObject(str);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
FileStream.writeFile(sim.format(new Date(System.currentTimeMillis())),str);
receive.setCaretPosition(receive.getText().length());
send.setText("");
}
}
});
send.setLineWrap(true);
scrollPane_1.setViewportView(send);
final JButton button_1 = new JButton();
button_1.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent e) {
String str=deptstr+" "+namestr+" "+sim1.format(new Date(System.currentTimeMillis()))+"说:\n"+send.getText()+"\n";
receive.append(str);
try {
ToServerProcess.oos.writeObject("群聊");
ToServerProcess.oos.writeObject(str);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
FileStream.writeFile(sim.format(new Date(System.currentTimeMillis())),str);
receive.setCaretPosition(receive.getText().length());
send.setText("");
}
});
button_1.setText("发送");
button_1.setBounds(229, 336, 79, 27);
frame.getContentPane().add(button_1);
final JButton close = new JButton();
close.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent e) {
MainGUI.qun.remove("1");
frame.dispose();
}
});
close.setText("关闭");
close.setBounds(118, 336, 82, 27);
frame.getContentPane().add(close);
}
public void showGUI()
{
frame.setResizable(false);
frame.setSize(324,402);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
//new BandChatGUI("张山","gsdfg").showGUI();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -