📄 mainwindow.java
字号:
/*主函数类,数据库连接*/
/*作者:曾文秋*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
public class MainWindow extends JWindow implements ActionListener{
public static Connection con=null;//连接对象
public static boolean conn(String url,String username,String password){
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");//jdbc连接数据库
}catch(Exception e){
e.printStackTrace();return false;
}
try{
con=DriverManager.getConnection(url,username,password);//连接数据库
}catch(SQLException e){
e.printStackTrace();return false;
}
return true;//连接数据库成功
}
public static boolean close(){
try{
con.close();//关闭数据库
con=null;
}catch(SQLException e){
e.printStackTrace();return false;
}
return true;
}
JLabel back=new JLabel(new ImageIcon("tree.jpg"));//显示图形的标签
JProgressBar progressBar=new JProgressBar(1,100);//进度条
Timer timer;//时间组件
int n=100;
public MainWindow(){
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));//设置鼠标的形状
progressBar.setStringPainted(true); //允许进度条显示文本
progressBar.setString("正在加载程序.......");//设置进度条文本
this.getContentPane().add(back,BorderLayout.CENTER);
this.getContentPane().add(progressBar,BorderLayout.SOUTH);
this.setSize(600,400);//设置大小
this.toFront();//界面移到最前
this.setLocation(200,200);//设置位置
this.setVisible(true);//设置为可显示
timer=new Timer(10,this);//建立时间组件
timer.addActionListener(this);//注册事件监听器
timer.start();
}
public void actionPerformed(ActionEvent e){//事件处理
if(--n>0){
progressBar.setValue(100-n);//设置进度条的值
timer.restart(); //重新启动时间组件
}
else {
timer.stop();//停止计时
dispose();
Fat person=new Fat();//创建Fat的对象
person.setVisible(true);//显示
}
}
public static void main(String [] args){
JFrame.setDefaultLookAndFeelDecorated(true);
//连接SQL Server200 数据库
if(!conn("jdbc:odbc:fatness","sa","")){
JOptionPane.showMessageDialog(null,"数据库连接失败");
System.exit(0);//退出并结束程序
}
MainWindow splashwindow=new MainWindow();//创建对象
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -