📄 adminchat.java
字号:
package edu.sccp.chat.frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
import java.io.IOException;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import com.swtdesigner.SwingResourceManager;
import edu.sccp.chat.jarClass.JarAllege;
import edu.sccp.chat.tools.FileStream;
public class AdminChat {
/**
* @param args
*/
JFrame frame;
public static JTextArea chatText;
JButton update;
File file;
String url="";
public AdminChat()
{
JarAllege.bai();
initGUI();
}
private void initGUI()
{
frame=new JFrame("管理聊天记录");
frame.setIconImage(SwingResourceManager.getImage(AdminChat.class, "/edu/sccp/chat/image/icon.png"));
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(final WindowEvent e) {
frame.dispose();
}
});
frame.getContentPane().setLayout(null);
frame.getContentPane();
final JPanel panel = new JPanel();
panel.setBorder(BorderFactory.createTitledBorder("选择查看日期"));
panel.setLayout(null);
panel.setBounds(22, 266, 357, 56);
frame.getContentPane().add(panel);
final JComboBox yearcomboBox = new JComboBox();
for(int i=2007;i<=2010;i++)
{
yearcomboBox.addItem(""+i);
}
yearcomboBox.setBounds(10, 28, 96, 20);
panel.add(yearcomboBox);
final JLabel label_1 = new JLabel();
label_1.setBounds(112, 30, 25, 16);
panel.add(label_1);
label_1.setText("年");
final JComboBox yuecomboBox = new JComboBox();
for(int i=1;i<=12;i++)
{
if(i<10)
yuecomboBox.addItem("0"+i);
else
yuecomboBox.addItem(""+i);
}
yuecomboBox.setBounds(142, 28, 75, 20);
panel.add(yuecomboBox);
final JLabel label_2 = new JLabel();
label_2.setBounds(224, 30, 23, 16);
panel.add(label_2);
label_2.setText("月");
final JComboBox daycomboBox = new JComboBox();
for(int i=1;i<=31;i++)
{
if(i<10)
daycomboBox.addItem("0"+i);
else
daycomboBox.addItem(""+i);
}
daycomboBox.setBounds(253, 28, 60, 20);
panel.add(daycomboBox);
final JLabel label_3 = new JLabel();
label_3.setBounds(319, 30, 38, 16);
panel.add(label_3);
label_3.setText("日");
final JButton show = new JButton();
show.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent e) {
String date=yearcomboBox.getSelectedItem()+"年"+yuecomboBox.getSelectedItem()+"月"+daycomboBox.getSelectedItem()+"日";
url="com/chatfile/"+date+".txt";
System.out.println(url);
file=new File(url);
if(file.exists())
{
try {
FileStream.inputFile(file);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
else
{
JOptionPane.showMessageDialog(frame,"没有该天的聊天记录!","警告",JOptionPane.WARNING_MESSAGE,null);
return;
}
update.setEnabled(true);
}
});
show.setText("查看");
show.setBounds(137, 328, 82, 25);
frame.getContentPane().add(show);
final JButton close = new JButton();
close.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent e) {
frame.dispose();
}
});
close.setText("关闭");
close.setBounds(327, 328, 86, 25);
frame.getContentPane().add(close);
update = new JButton();
update.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent e) {
int i=JOptionPane.showConfirmDialog(frame,"确定要删除此天的聊天记录?,注意删除后不可恢复!","提示",JOptionPane.YES_OPTION,JOptionPane.INFORMATION_MESSAGE,null);
if(i==0)
{
File file=new File(url);
if(file.delete())
{
JOptionPane.showMessageDialog(frame,"聊天记录删除成功!","提示",JOptionPane.INFORMATION_MESSAGE,null);
chatText.setText("");
update.setEnabled(false);
return;
}else
{
JOptionPane.showMessageDialog(frame,"聊天记录没有删除成功!","提示",JOptionPane.INFORMATION_MESSAGE,null);
return;
}
}
}
});
update.setText("删除");
update.setEnabled(false);
update.setBounds(233, 328, 80, 25);
frame.getContentPane().add(update);
final JScrollPane scrollPane = new JScrollPane();
scrollPane.setBorder(BorderFactory.createTitledBorder("聊天记录内容"));
scrollPane.setBounds(10, 10, 422, 250);
frame.getContentPane().add(scrollPane);
chatText = new JTextArea();
chatText.setEditable(false);
chatText.setLineWrap(true);
scrollPane.setViewportView(chatText);
}
public void showGUI()
{
frame.setResizable(false);
frame.setSize(448,398);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
new AdminChat().showGUI();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -