?? propertiesdlg.java
字號:
package JTerm;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.io.*;
/**
* <p>Title: JTerm </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company: Tsinghua</p>
* @author Frank.Wang
* @version 1.0
*/
public class PropertiesDlg extends JDialog {
JLabel jLabel1 = new JLabel();
JTextField slottimefield = new JTextField();
JLabel jLabel2 = new JLabel();
JLabel jLabel3 = new JLabel();
JTextField dumycharfield = new JTextField();
JLabel jLabel4 = new JLabel();
JCheckBox autoreturn = new JCheckBox();
JRadioButton RandomMsgBtn = new JRadioButton();
JRadioButton SortMsgBtn = new JRadioButton();
JScrollPane jScrollPane1 = new JScrollPane();
DefaultListModel listMsg=new DefaultListModel();
JList jList1 = new JList(listMsg);
JLabel jLabel5 = new JLabel();
JTextField MsgField = new JTextField();
JButton jButton1 = new JButton();
JButton jButton2 = new JButton();
JButton jButton3 = new JButton();
JButton jButton4 = new JButton();
JCheckBox checkSound = new JCheckBox();
public PropertiesDlg(Frame frame, String title, boolean modal) {
super(frame, title, modal);
try {
jbInit();
pack();
this.setSize(500,300);
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = this.getSize();
if (frameSize.height > screenSize.height) {
frameSize.height = screenSize.height;
}
if (frameSize.width > screenSize.width) {
frameSize.width = screenSize.width;
}
this.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
this.setVisible(true);
}
catch(Exception ex) {
ex.printStackTrace();
}
}
public PropertiesDlg() {
this(null, "", false);
}
private void jbInit() throws Exception {
this.getContentPane().setLayout(null);
jLabel1.setFont(new java.awt.Font("Monospaced", 0, 12));
jLabel1.setText("每隔");
jLabel1.setBounds(new Rectangle(79, 11, 34, 16));
slottimefield.setFont(new java.awt.Font("Monospaced", 0, 12));
slottimefield.setText("1");
slottimefield.setBounds(new Rectangle(111, 6, 19, 22));
jLabel2.setFont(new java.awt.Font("Monospaced", 0, 12));
jLabel2.setText("秒發送一個");
jLabel2.setBounds(new Rectangle(141, 10, 65, 16));
jLabel3.setFont(new java.awt.Font("Monospaced", 0, 12));
jLabel3.setText("發呆控制:");
jLabel3.setBounds(new Rectangle(15, 11, 69, 16));
dumycharfield.setFont(new java.awt.Font("Monospaced", 0, 12));
dumycharfield.setText("19");
dumycharfield.setBounds(new Rectangle(210, 8, 57, 18));
jLabel4.setFont(new java.awt.Font("Monospaced", 0, 12));
jLabel4.setText("號字符");
jLabel4.setBounds(new Rectangle(279, 9, 42, 16));
autoreturn.setFont(new java.awt.Font("Monospaced", 0, 12));
autoreturn.setText("自動回復消息");
autoreturn.setBounds(new Rectangle(11, 32, 119, 25));
RandomMsgBtn.setFont(new java.awt.Font("Monospaced", 0, 12));
RandomMsgBtn.setText("隨機回復");
RandomMsgBtn.setBounds(new Rectangle(130, 32, 91, 25));
RandomMsgBtn.addActionListener(new PropertiesDlg_RandomMsgBtn_actionAdapter(this));
SortMsgBtn.setFont(new java.awt.Font("Monospaced", 0, 12));
SortMsgBtn.setText("順序回復");
SortMsgBtn.setBounds(new Rectangle(225, 32, 91, 25));
SortMsgBtn.addActionListener(new PropertiesDlg_SortMsgBtn_actionAdapter(this));
jScrollPane1.setBounds(new Rectangle(13, 91, 433, 114));
this.setModal(true);
jLabel5.setFont(new java.awt.Font("Monospaced", 0, 12));
jLabel5.setText("回復消息");
jLabel5.setBounds(new Rectangle(16, 64, 51, 16));
MsgField.setFont(new java.awt.Font("Monospaced", 0, 12));
MsgField.setToolTipText("");
MsgField.setSelectionStart(7);
MsgField.setText("對不起,我正忙!");
MsgField.setBounds(new Rectangle(79, 60, 232, 22));
jButton1.setBounds(new Rectangle(318, 59, 59, 25));
jButton1.setFont(new java.awt.Font("Monospaced", 0, 12));
jButton1.setRolloverEnabled(false);
jButton1.setText("添加");
jButton1.addActionListener(new PropertiesDlg_jButton1_actionAdapter(this));
jButton2.setText("刪除");
jButton2.addActionListener(new PropertiesDlg_jButton2_actionAdapter(this));
jButton2.setRolloverEnabled(false);
jButton2.setFont(new java.awt.Font("Monospaced", 0, 12));
jButton2.setBounds(new Rectangle(385, 59, 59, 25));
jButton3.setBounds(new Rectangle(244, 235, 73, 25));
jButton3.setFont(new java.awt.Font("Monospaced", 0, 12));
jButton3.setText("確定");
jButton3.addActionListener(new PropertiesDlg_jButton3_actionAdapter(this));
jButton4.setBounds(new Rectangle(351, 235, 73, 25));
jButton4.setFont(new java.awt.Font("Monospaced", 0, 12));
jButton4.setText("取消");
jButton4.addActionListener(new PropertiesDlg_jButton4_actionAdapter(this));
checkSound.setFont(new java.awt.Font("Monospaced", 0, 12));
checkSound.setMargin(new Insets(2, 2, 2, 2));
checkSound.setText("收到消息發提示音");
checkSound.setBounds(new Rectangle(13, 216, 126, 25));
checkSound.addActionListener(new PropertiesDlg_checkSound_actionAdapter(this));
this.getContentPane().add(jLabel3, null);
this.getContentPane().add(jLabel2, null);
this.getContentPane().add(jLabel1, null);
this.getContentPane().add(slottimefield, null);
this.getContentPane().add(dumycharfield, null);
this.getContentPane().add(jLabel4, null);
this.getContentPane().add(autoreturn, null);
this.getContentPane().add(RandomMsgBtn, null);
this.getContentPane().add(SortMsgBtn, null);
this.getContentPane().add(jScrollPane1, null);
this.getContentPane().add(jLabel5, null);
this.getContentPane().add(MsgField, null);
this.getContentPane().add(jButton1, null);
this.getContentPane().add(jButton2, null);
this.getContentPane().add(jButton3, null);
this.getContentPane().add(jButton4, null);
this.getContentPane().add(checkSound, null);
jScrollPane1.getViewport().add(jList1, null);
java.util.Properties properties=System.getProperties();
slottimefield.setText(properties.getProperty("DumySlotTime"));
dumycharfield.setText(properties.getProperty("DumyChar"));
String t=properties.getProperty("AutoReturnMsg");
if (t!=null){
if (t.compareTo("true") == 0)
autoreturn.setSelected(true);
}
t=properties.getProperty("ReturnMethod");
if (t!=null){
if (t.compareTo("Sort") == 0) {
SortMsgBtn.setSelected(true);
}
else {
RandomMsgBtn.setSelected(true);
}
}
t=properties.getProperty("SoundOn");
if (t!=null){
if (t.compareTo("true") == 0) {
checkSound.setSelected(true);
}
}
try{
String filename=System.getProperties().getProperty("user.dir")+java.io.File.separator+"message.dat";
FileInputStream file = new FileInputStream(filename);
InputStreamReader in = new InputStreamReader(file);
String data="";
char[] ch=new char[1];
while(true){
if (in.read(ch,0,1)==1){
if (ch[0]=='\r'){
listMsg.addElement(new String(data));
data="";
}if (ch[0]=='\n'){
data="";
continue;
}else{
data+=ch[0];
}
continue;
}
break;
}
in.close();
}catch(Exception e){
}
}
void jButton1_actionPerformed(ActionEvent e) {
listMsg.addElement(MsgField.getText());
}
void RandomMsgBtn_actionPerformed(ActionEvent e) {
SortMsgBtn.setSelected(false);
RandomMsgBtn.setSelected(true);
}
void SortMsgBtn_actionPerformed(ActionEvent e) {
SortMsgBtn.setSelected(true);
RandomMsgBtn.setSelected(false);
}
void jButton2_actionPerformed(ActionEvent e) {
if (jList1.getSelectedIndex()>=0){
listMsg.remove(jList1.getSelectedIndex());
}
}
void jButton3_actionPerformed(ActionEvent e) {
java.util.Properties properties=System.getProperties();
try{
int slot=Integer.parseInt(slottimefield.getText());
}catch(Exception err){
JOptionPane.showMessageDialog(this,"請輸入合法的時間數字");
return;
}
try{
int ch=Integer.parseInt(dumycharfield.getText());
if (ch<0||ch>128){
throw new Exception("");
}
}catch(Exception err){
JOptionPane.showMessageDialog(this,"請輸入合法的字符十進制數");
return;
}
properties.setProperty("DumySlotTime",slottimefield.getText());
properties.setProperty("DumyChar",dumycharfield.getText());
properties.setProperty("AutoReturnMsg",(autoreturn.isSelected()?"true":"false"));
properties.setProperty("SoundOn",(checkSound.isSelected()?"true":"false"));
properties.setProperty("ReturnMethod",SortMsgBtn.isSelected()?"Sort":"Random");
try{
String filename=System.getProperties().getProperty("user.dir")+java.io.File.separator+"message.dat";
FileOutputStream file = new FileOutputStream(filename);
OutputStreamWriter out = new OutputStreamWriter(file);
String data;
int i=listMsg.size();
System.out.println(i);
for (i=0;i<listMsg.size();i++) {
data=(String)listMsg.elementAt(i);
out.write(data);
out.write("\r\n");
out.flush();
}
out.close();
}catch(Exception err){
}
this.dispose();
}
void jButton4_actionPerformed(ActionEvent e) {
this.dispose();
}
void checkSound_actionPerformed(ActionEvent e) {
}
}
class PropertiesDlg_jButton1_actionAdapter implements java.awt.event.ActionListener {
PropertiesDlg adaptee;
PropertiesDlg_jButton1_actionAdapter(PropertiesDlg adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton1_actionPerformed(e);
}
}
class PropertiesDlg_RandomMsgBtn_actionAdapter implements java.awt.event.ActionListener {
PropertiesDlg adaptee;
PropertiesDlg_RandomMsgBtn_actionAdapter(PropertiesDlg adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.RandomMsgBtn_actionPerformed(e);
}
}
class PropertiesDlg_SortMsgBtn_actionAdapter implements java.awt.event.ActionListener {
PropertiesDlg adaptee;
PropertiesDlg_SortMsgBtn_actionAdapter(PropertiesDlg adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.SortMsgBtn_actionPerformed(e);
}
}
class PropertiesDlg_jButton2_actionAdapter implements java.awt.event.ActionListener {
PropertiesDlg adaptee;
PropertiesDlg_jButton2_actionAdapter(PropertiesDlg adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton2_actionPerformed(e);
}
}
class PropertiesDlg_jButton3_actionAdapter implements java.awt.event.ActionListener {
PropertiesDlg adaptee;
PropertiesDlg_jButton3_actionAdapter(PropertiesDlg adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton3_actionPerformed(e);
}
}
class PropertiesDlg_jButton4_actionAdapter implements java.awt.event.ActionListener {
PropertiesDlg adaptee;
PropertiesDlg_jButton4_actionAdapter(PropertiesDlg adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton4_actionPerformed(e);
}
}
class PropertiesDlg_checkSound_actionAdapter implements java.awt.event.ActionListener {
PropertiesDlg adaptee;
PropertiesDlg_checkSound_actionAdapter(PropertiesDlg adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.checkSound_actionPerformed(e);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -