?? chatbase.java
字號:
package business;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.*;
import java.util.Calendar;
import java.util.Enumeration;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTextArea;
import Form.*;
public class ChatBase extends JFrame implements ActionListener{
/**
* Launch the application
* @param args
*/
protected int userNum;
protected int friendNum;
protected String userName;
protected boolean openRecrod = false;
protected JLabel infomation;
protected JTextArea input;
protected JTextArea output;
protected JPanel pnlButtom;
protected JPanel pnlCenter;
protected JButton btnSend;
protected JButton btnCancel;
protected JButton btnRecord;
protected Client parent;
protected JScrollPane panel;
protected JTextArea recrod;
//用于初始控件和布局
public void setup()
{
infomation = new JLabel("");
String info = User.getInfo(friendNum);
infomation.setText(info);
input = new JTextArea();
output = new JTextArea();
JScrollPane jspInput = new JScrollPane(input,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
JScrollPane jspOutput = new JScrollPane(output,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
pnlButtom = new JPanel();
pnlCenter = new JPanel();
pnlButtom.setLayout(new FlowLayout());
btnSend = new JButton("發送");
btnCancel = new JButton("取消");
btnRecord = new JButton("聊天記錄");
btnSend.addActionListener(this);
btnCancel.addActionListener(this);
btnRecord.addActionListener(this);
pnlCenter.setLayout(new BorderLayout());
pnlCenter.add("Center",jspInput);
pnlCenter.add("South",jspOutput);
javax.swing.JSplitPane js = new JSplitPane(JSplitPane.VERTICAL_SPLIT,jspInput,jspOutput);
js.setDividerSize(4);
jspInput.setPreferredSize(new Dimension(200,200));
pnlButtom.add(btnSend);
pnlButtom.add(btnCancel);
pnlButtom.add(btnRecord);
recrod = new JTextArea();
recrod.setPreferredSize(new Dimension(200,280));
panel = new JScrollPane(recrod,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
Read();
this.getContentPane().add(panel,"East");
getContentPane().add("North",infomation);
getContentPane().add("Center",pnlCenter);
getContentPane().add("South",pnlButtom);
getContentPane().add(js);
input.setEditable(false);
}
//寫聊天記錄信息
public void Save()
{
String recrod = input.getText();
File f = new File("recrods\\"+userNum+"to"+friendNum+".txt");
FileOutputStream fos;
try {
fos = new FileOutputStream(f,true);
fos.write(recrod.getBytes());
}
catch (FileNotFoundException e) {
// TODO 自動生成 catch 塊
e.printStackTrace();
} catch (IOException e) {
// TODO 自動生成 catch 塊
e.printStackTrace();
}
}
//讀聊天記錄信息
public void Read()
{
int width = 200;
int height = 280;
int row = -10;
recrod.setText("");
File f = new File("recrods\\"+userNum+"to"+friendNum+".txt");
if(!f.exists())
{
recrod.append(" ");
return;
}
FileReader fis;
try {
fis = new FileReader(f);
BufferedReader bif = new BufferedReader(fis);
String temp;
while((temp=bif.readLine())!=null)
{
recrod.append(temp+"\n");
row ++;
if(row>0)
{
height +=20;
recrod.setPreferredSize(new Dimension(200,height));
}
}
} catch (FileNotFoundException e) {
// TODO 自動生成 catch 塊
e.printStackTrace();
} catch (IOException e) {
// TODO 自動生成 catch 塊
e.printStackTrace();
}
}
public ChatBase()
{
}
public void setMessage(String string) {
}
public void actionPerformed(ActionEvent e) {
// TODO 自動生成方法存根
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -