📄 run.java
字号:
package huazheng;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextArea;
import javax.swing.JTextField;
public class Run {
JTextField f = new JTextField("请输入姓名", 10);
static JTextArea area = new JTextArea();
public void List() throws SQLException {
String name = null, xuehao = null;
String math = null, physics = null, english = null;
Connection con = null;
Statement sql=null;
ResultSet rs;
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println(" 成功加载JDBC-ODBC桥驱动器");
} catch (ClassNotFoundException e) {
System.out.println("加载失败");
}
try {
con = DriverManager.getConnection("jdbc:odbc:hua", "huazheng",
"huazheng");
System.out.println("连接成功");
sql = con.createStatement();
rs = sql.executeQuery("SELECT * FROM huazheng3");
while (rs.next()) {
name = rs.getString(2);
xuehao = rs.getString(1);
math = rs.getString(3);
physics = rs.getString(4);
english = rs.getString(5);
if (name.trim().equals(f.getText().trim())) {
area.setText(xuehao + " " + name + " " + math + " "
+ physics + " " + english + "\n");
}
}
} catch (SQLException e) {
}
finally{
con.close();
sql.close();
}
}
public void list2() throws SQLException {
String name, xuehao;
String math, physics, english;
Connection con=null;
Statement sql=null;
ResultSet rs;
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println(" 成功加载JDBC-ODBC桥驱动器");
} catch (ClassNotFoundException e) {
}
try {
con = DriverManager.getConnection("jdbc:odbc:hua", "huazheng",
"huazheng");
System.out.println("连接成功");
sql = con.createStatement();
rs = sql.executeQuery("SELECT * FROM huazheng3");
while (rs.next()) {
name = rs.getString(2);
xuehao = rs.getString(1);
math = rs.getString(3);
physics = rs.getString(4);
english = rs.getString(5);
area.append(xuehao + " " + name + " " + math + " " + physics
+ " " + english + "\n");
}
} catch (SQLException e) {
}
finally{
con.close();
sql.close();
}
}
public static void main(String[] args) {
Sleep s = new Sleep();
Id id = new Id();
final Run run = new Run();
JFrame frame = new JFrame("信计031");
frame.setLocation(100, 100);
frame.setSize(770, 600);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setAlwaysOnTop(false);
BorderLayout l = new BorderLayout();
frame.setLayout(l);
JPanel panel3 = new JPanel();
panel3.setLayout(new BorderLayout());
panel3.add(id.myPanel(), BorderLayout.SOUTH);
panel3.add(new Caidan().huazheng(), BorderLayout.NORTH);
frame.add(panel3, BorderLayout.NORTH);
JButton b1 = new JButton("班级信息");
JButton b2 = new JButton("成绩查询");
JButton b3 = new JButton("班委成员");
JButton b4 = new JButton("班级公约");
JButton b5 = new JButton("班级照片");
JButton b6 = new JButton("通讯录");
JButton b7 = new JButton("秘密");
JButton b8 = new JButton("作者信息");
JButton b11 = new JButton("操作");
b1.setToolTipText("班级信息");
b2.setToolTipText("成绩查询");
b3.setToolTipText("班委成员");
b4.setToolTipText("班级公约");
b5.setToolTipText("班级照片");
b6.setToolTipText("个人通讯录");
b7.setToolTipText("秘密");
b8.setToolTipText("华正-张华");
b11.setToolTipText("单击实现对学生信息的更改等操作");
b1.setBackground(Color.red);
b2.setBackground(Color.BLUE);
b3.setBackground(Color.CYAN);
b4.setBackground(Color.orange);
b5.setBackground(Color.MAGENTA);
b6.setBackground(Color.yellow);
b7.setBackground(Color.PINK);
final JButton b9 = new JButton("查询");
JButton b10 = new JButton("退出");
JButton b12 = new JButton("清空");
JLabel label = new JLabel("华正制作");
label.setFont(new java.awt.Font("华文新魏", java.awt.Font.BOLD, 18));
label.setForeground(new java.awt.Color(200, 51, 0));
JPanel panel = new JPanel();
JPanel panel2 = new JPanel();
panel.setLayout(new GridLayout(8, 2, 8, 8));
panel.add(b1);
panel.add(b2);
panel.add(b3);
panel.add(b4);
panel.add(b5);
panel.add(b6);
panel.add(b7);
panel.add(label);
panel2.add(s.j);
panel2.add(b8);
panel2.add(b9);
panel2.add(run.f);
panel2.add(b11);
panel2.add(b12);
panel2.add(b10);
area.setBackground(Color.GREEN);
frame.add(new JScrollPane(area));
area.setEditable(false);
// frame.add(id.myPanel(),BorderLayout.WEST);
frame.add(panel, BorderLayout.WEST);
frame.add(panel2, BorderLayout.SOUTH);
area.setFont(new java.awt.Font("楷体", java.awt.Font.BOLD, 30));
area.setForeground(new java.awt.Color(14, 151, 0));
b9.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (e.getSource() == b9) {
area.append("信息\n");
try {
run.List();
} catch (SQLException ex) {
}
}
}
});
b10.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
});
b8.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(null, "张华\n兰州交通大学");
}
});
b1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
new Information().huazheng();
}
});
b11.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
new Drive().huazheng();
}
});
b12.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
area.setText("");
}
});
b5.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
final Album album = new Album();
album.Display();
album.getj1().addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
album.change();
}
});
album.getj2().addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
album.change();
}
});
}
});
b2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
new Mark().mark();
}
});
b3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
new Banwei().banwei();
}
});
b6.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
Chuangkou ch=new Chuangkou();
JFrame f=ch.frame("通讯录",400,400,300,300);
f.add(new JTable(25,10));
f.add(BorderLayout.NORTH,new Caidan().huazheng());
f.setVisible(true);
}
});
frame.setVisible(true);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -