📄 mainframe.java
字号:
package catking.home.love;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
public class MainFrame extends JFrame implements ActionListener
{
private final String[]menuStr = {"添加数据","删除数据","修改数据","查询数据","退出"};
private Connection con;
public MainFrame()
{
super("班级数据库管理系统");
SplashWindow splashWindow = new SplashWindow(this,"D:/TheBestPhoto/desk/1.jpg");
splashWindow.StartSplash();
//设置全屏
this.setSize(this.getToolkit().getScreenSize());
Container c = this.getContentPane();
c.setBackground(Color.LIGHT_GRAY);
JMenuBar bar = new JMenuBar();
JMenu file = new JMenu("文件");
JPanel buttonPane = new JPanel();
buttonPane.setLayout(new GridLayout(1,5,2,0));
for(int i =0; i < menuStr.length; ++i)
{
JMenuItem menuItem = new JMenuItem(menuStr[i]);
JButton button = new JButton(menuStr[i]);
button.addActionListener(this);
menuItem.addActionListener(this);
file.add(menuItem);
buttonPane.add(button);
}
bar.add(file);
this.setJMenuBar(bar);
c.add(buttonPane,BorderLayout.SOUTH);
//加载数据库
this.loadDBDriver("Class","sa","cat");
this.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent we)
{
MainFrame.this.isQuit();
}
});
try{
Thread.sleep(2000);
}catch(InterruptedException e)
{}
splashWindow.stopSplash();
this.setVisible(true);
}
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
int temp= -1;
for(int i =0; i < this.menuStr.length; ++i)
{
if(this.menuStr[i].equals(e.getActionCommand()))
{
temp = i;
break;
}
}
switch(temp)
{
//添加数据
case 0:
isAppendData();
break;
//删除数据
case 1:
isDeleteData();
break;
//修改数据
case 2:
isAlterData();
break;
//查询数据
case 3:
isInquryData();
break;
case 4:
isQuit();
//退出
}
}
private void loadDBDriver(String DBName,String user,String pw)
{
String url = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName="+DBName;
try {
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
this.con = DriverManager.getConnection(url,user,pw);
} catch (Exception e){
JOptionPane.showMessageDialog(null,
"错误","加载数据库时候出错!",JOptionPane.ERROR_MESSAGE);
System.exit(1);
}
}
private void isAppendData()
{
new InsertInfo(this.con,"添加客户数据","请输入客户的详细信息");
}
private void isDeleteData()
{
new DeleteInfo(this.con,"删除客户信息","请删除要删除的客户编号");
}
private void isAlterData()
{
new AlterLogin(this.con,"修改客户信息","请输入要修改的客户编号");
}
private void isInquryData()
{
new InquryInfo(this.con,"查询客户信息","请输入要查询的客户编号");
}
private void isQuit()
{
if(JOptionPane.YES_OPTION ==
JOptionPane.showConfirmDialog(null,
"Are you sure to quit?","提示",
JOptionPane.YES_NO_CANCEL_OPTION) )
{
try {
con.close();
} catch (SQLException e){
}
System.exit(0);
}
}
public static void main(String[] args)
{
MainFrame mf = new MainFrame();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -