📄 configchange.java
字号:
package source;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.swing.JOptionPane;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
public class ConfigChange {
protected Shell shell;
private Shell parent;
private Display display;
private String local_username="";
private String local_password="";
private String username="";
private String password="";
private String pop3="";
private String smtp="";
private boolean del=false;
private String save_folder="d:/";
private String s_addr="";
private String s_name="";
public ConfigChange(Shell parent,Display display)
{
this.parent=parent;
this.display=display;
}
public void open()
{
shell=new Shell();
shell.setText("系统配置");
shell.setSize(312, 410);
int width,height;
width=312;
height=410;
shell.setSize(width, height);
shell.setCapture(true);
shell.setLayout(null);
Toolkit kit=Toolkit.getDefaultToolkit();
Dimension screenSize=kit.getScreenSize();
shell.setBounds((screenSize.width-width)/2, (screenSize.height-height)/2, width,height);
DataBase db=new DataBase();
db.connectToDB();
ResultSet rs=null;
rs=db.executeQuery("select top 1 * from config");
try {
rs.next();
local_username=rs.getString("local_username")+"";
local_password=rs.getString("local_password")+"";
username=rs.getString("username")+"";
password=rs.getString("password")+"";
pop3=rs.getString("pop3")+"";
smtp=rs.getString("smtp")+"";
save_folder=rs.getString("save_folder")+"";
s_addr=rs.getString("s_addr")+"";
s_name=rs.getString("s_name")+"";
} catch (SQLException e1) {
// TODO 自动生成 catch 块
e1.printStackTrace();
}
final Label label = new Label(shell, SWT.NONE);
label.setText("本地用户名:");
label.setBounds(35, 35, 60, 21);
final Text text = new Text(shell, SWT.BORDER);
text.setBounds(120, 30, 150, 20);
text.setText(local_username);
final Label label_1 = new Label(shell, SWT.NONE);
label_1.setText("本地密码");
label_1.setBounds(35, 60, 60, 12);
final Text text_1 = new Text(shell, SWT.PASSWORD | SWT.BORDER);
text_1.setBounds(120, 60, 150, 20);
text_1.setText(local_password);
final Label label_2 = new Label(shell, SWT.NONE);
label_2.setText("邮箱用户名");
label_2.setBounds(35, 90, 60, 12);
final Text text_2 = new Text(shell, SWT.BORDER);
text_2.setBounds(120, 90, 150, 20);
text_2.setText(username);
final Text text_3 = new Text(shell, SWT.PASSWORD | SWT.BORDER);
text_3.setBounds(120, 120, 150, 20);
text_3.setText(password);
final Label label_3 = new Label(shell, SWT.NONE);
label_3.setText("邮箱密码");
label_3.setBounds(35, 120, 60, 12);
final Label label_4 = new Label(shell, SWT.NONE);
label_4.setText("pop3服务器");
label_4.setBounds(35, 150, 60, 12);
final Text text_4 = new Text(shell, SWT.BORDER);
text_4.setBounds(120, 150, 150, 20);
text_4.setText(pop3);
final Text text_5 = new Text(shell, SWT.BORDER);
text_5.setBounds(120, 180, 150, 20);
text_5.setText(smtp);
final Label label_5 = new Label(shell, SWT.NONE);
label_5.setText("smtp服务器");
label_5.setBounds(35, 180, 60, 12);
final Label label_6 = new Label(shell, SWT.NONE);
label_6.setText("发件人姓名");
label_6.setBounds(35, 215, 60, 12);
final Text text_6 = new Text(shell, SWT.BORDER);
text_6.setBounds(120, 210, 150, 20);
text_6.setText(s_name);
final Label label_7 = new Label(shell, SWT.NONE);
label_7.setText("发件人地址");
label_7.setBounds(35, 245, 60, 12);
final Text text_7 = new Text(shell, SWT.BORDER);
text_7.setBounds(120, 240, 150, 20);
text_7.setText(s_addr);
final Label label_8 = new Label(shell, SWT.NONE);
label_8.setText("附件存储目录");
label_8.setBounds(35, 275, 79, 12);
final Text text_8 = new Text(shell, SWT.BORDER);
text_8.setBounds(120, 270, 100, 20);
text_8.setText(save_folder);
final Label label_9 = new Label(shell, SWT.NONE);
label_9.setText("在收完邮件后是否删除原邮件");
label_9.setBounds(35, 305, 164, 14);
final Combo combo = new Combo(shell, SWT.READ_ONLY);
combo.setBounds(217, 302, 53, 20);
combo.add("是",0);
combo.add("否",1);
combo.select(0);
final Button button_2 = new Button(shell, SWT.NONE);
button_2.setText("浏览");
button_2.addSelectionListener(new SelectionAdapter(){
public void widgetSelected(SelectionEvent e){
String dir=DirectoryDialog1.getDirectory2();
text_8.setText(dir);
}
});
button_2.setBounds(225, 270, 48, 22);
final Button button_3 = new Button(shell, SWT.NONE);
button_3.setText("确定");
button_3.addMouseListener(new MouseAdapter(){
public void mouseUp(MouseEvent e){
if(text.getText().trim()==""||text_1.getText().trim()==""||text_2.getText().trim()==""||text_3.getText().trim()==""||
text_4.getText().trim()==""||text_5.getText().trim()==""||text_6.getText().trim()==""||text_7.getText().trim()==""||text_8.getText().trim()=="")
{
MessageDialog.openInformation(null, "系统提示!", "必须将所有项目填写完整!");
}
else
{
local_username=text.getText().trim();
local_password=text_1.getText().trim();
username=text_2.getText().trim();
password=text_3.getText().trim();
pop3=text_4.getText().trim();
smtp=text_5.getText().trim();
s_name=text_6.getText().trim();
s_addr=text_7.getText().trim();
save_folder=text_8.getText().trim();
if(combo.getSelectionIndex()==1)
{
del=false;
}
else
{
del=true;
}
DataBase db=new DataBase();
db.connectToDB();
String sql="";
if(del==true)
sql="update config set [delete]=true where id=1";
else
sql="update config set [delete]=false where id=1";
db.executeUpdate(sql);
sql = "update config set local_username='"+local_username+"',local_password='"+local_password+
"',username='"+username+"',password='"+password+"',pop3='"+pop3+"',smtp='"+smtp+"',s_name='"+s_name+"',s_addr='"+s_addr+"',save_folder='"+save_folder+"' where id=1";
db.executeUpdate(sql);
db.close();
MessageDialog.openInformation(null, "系统提示!", "设置成功!");
shell.close();
}
}
});
button_3.setBounds(65, 335, 48, 22);
final Button button_4 = new Button(shell, SWT.NONE);
button_4.setText("取消");
button_4.addMouseListener(new MouseAdapter(){
public void mouseUp(MouseEvent e){
shell.close();
}
}
);
button_4.setBounds(180, 335, 48, 22);
shell.open();
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
{
display.sleep();
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -