📄 test.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.jface.viewers.IStructuredSelection;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.widgets.Button;
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 Test {
public static void main(String[] args)
{
Test test=new Test();
test.open();
}
public void open(){
final Display display=new Display();
final Shell shell=new Shell();
shell.setText("登陆页面");
shell.setSize(365, 248);
shell.setLayout(null);
int width,height;
width=365;
height= 248;
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
{
if(!rs.next())
{
db.executeInsert("insert into config(id) values(1)");
Config config=new Config(null,display);
config.open();
ShowMail showmail=new ShowMail(shell,display);
showmail.open();
}
else
{
final Text text = new Text(shell, SWT.BORDER);
text.setBounds(98, 33, 170, 19);
final Text text_1 = new Text(shell, SWT.PASSWORD | SWT.BORDER);
text_1.setBounds(98, 79, 170, 19);
final Label label = new Label(shell, SWT.NONE);
label.setText("用户名");
label.setBounds(40, 35, 57, 19);
final Label label_1 = new Label(shell, SWT.NONE);
label_1.setText("密 码");
label_1.setBounds(40, 85, 36, 19);
final Button button = new Button(shell, SWT.NONE);
button.setText("确定");
button.addMouseListener(new MouseAdapter(){
public void mouseUp(MouseEvent e){
DataBase db=new DataBase();
db.connectToDB();
ResultSet rs=null;
rs=db.executeQuery("select * from config where id=1");
String local_username="";
String local_password="";
try {
rs.next();
local_username=rs.getString("local_username");
local_password=rs.getString("local_password");
} catch (SQLException e1) {
e1.printStackTrace();
}
if(text.getText().equals(local_username)&&text_1.getText().equals(local_password))
{
shell.close();
ShowMail showmail=new ShowMail(shell,display);
showmail.open();
}
else
{
MessageDialog.openError(null, "登陆错误", "用户名或密码错误!");
}
}
});
button.setBounds(104, 135, 48, 22);
final Button button_1 = new Button(shell, SWT.NONE);
button_1.setText("取消");
button_1.addMouseListener(new MouseAdapter(){
public void mouseUp(MouseEvent e){
System.exit(0);
}
});
button_1.setBounds(192, 135, 48, 22);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
}
db.stmt.close();
db.conn.close();
}
catch (SQLException e) {
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -