📄 markqueryframe.java
字号:
package com.sccp.StudentMS.baseFrame;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import com.sccp.StudentMS.DBtools.DBtool;
import com.swtdesigner.SwingResourceManager;
public class MarkQueryFrame extends JFrame {
private JTextField t;
private JComboBox oper;
private JComboBox type;
ResultSet rs,rs1;
String sql;
DBtool db=new DBtool();
/**
* Launch the application
* @param args
*/
public static void main(String args[]) {
try {
MarkQueryFrame frame = new MarkQueryFrame();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Create the frame
*/
public MarkQueryFrame() {
super();
setTitle("成绩查询");
setBounds(100, 100, 500, 212);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final JPanel panel = new JPanel();
panel.setLayout(null);
getContentPane().add(panel, BorderLayout.CENTER);
final JLabel label = new JLabel();
label.setText("查询类别:");
label.setBounds(58, 36, 86, 15);
panel.add(label);
type = new JComboBox();
type.setModel(new DefaultComboBoxModel(new String[] {"学号", "总分", "政治", "高数", "英语", "专业课"}));
type.setBounds(58, 74, 119, 23);
panel.add(type);
oper = new JComboBox();
oper.setModel(new DefaultComboBoxModel(new String[] {"=", "<", ">"}));
oper.setBounds(225, 74, 80, 23);
panel.add(oper);
final JLabel label_1 = new JLabel();
label_1.setText("操作符:");
label_1.setBounds(225, 36, 60, 15);
panel.add(label_1);
final JLabel label_2 = new JLabel();
label_2.setText("查询值:");
label_2.setBounds(337, 36, 60, 15);
panel.add(label_2);
t = new JTextField();
t.setBounds(337, 76, 95, 20);
panel.add(t);
final JButton button = new JButton();
button.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent e) {
if(t.getText().equals(""))
JOptionPane.showMessageDialog(null,"查询值不能为空!");
else{
sql="select * from grade";
if(type.getSelectedIndex()==0)
sql=sql+" where ID"+oper.getSelectedItem().toString()+t.getText();
else if(type.getSelectedIndex()==1)
sql=sql+" where Total"+oper.getSelectedItem().toString()+t.getText();
else if(type.getSelectedIndex()==2)
sql=sql+" where philosophy"+oper.getSelectedItem().toString()+t.getText();
else if(type.getSelectedIndex()==3)
sql=sql+" where math"+oper.getSelectedItem().toString()+t.getText();
else if(type.getSelectedIndex()==4)
sql=sql+" where english"+oper.getSelectedItem().toString()+t.getText();
else if(type.getSelectedIndex()==5)
sql=sql+" where specialty"+oper.getSelectedItem().toString()+t.getText();
rs=db.getResult(sql);
rs1=db.getResult(sql);
try {
if(rs.next())
{
if(!(rs.next()))
{ rs1.next();
showResult(rs1);
MarkQueryFrame.this.dispose();
}else
{
markTableShow();
MarkQueryFrame.this.dispose();
}
}else
{
JOptionPane.showMessageDialog(null,"Sorry,无此人信息!");
}
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}
});
button.setText("确定");
button.setBounds(64, 130, 80, 23);
panel.add(button);
final JButton button_1 = new JButton();
button_1.setText("重置");
button_1.setBounds(226, 130, 78, 23);
panel.add(button_1);
final JButton button_2 = new JButton();
button_2.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent e) {
MarkQueryFrame.this.dispose();
}
});
button_2.setText("取消");
button_2.setBounds(379, 130, 72, 23);
panel.add(button_2);
final JLabel label_4 = new JLabel();
panel.add(label_4);
label_4.setIcon(SwingResourceManager.getIcon(MarkQueryFrame.class, "/images/cool6.gif"));
label_4.setText(" ");
label_4.setBounds(150, 10, 43, 50);
final JLabel label_3 = new JLabel();
label_3.setIcon(SwingResourceManager.getIcon(MarkQueryFrame.class, "/images/发.JPG"));
label_3.setText(" ");
label_3.setBounds(0, 0, 492, 178);
panel.add(label_3);
//
}
public void setContent(MarkInfoFrame mif,ResultSet rs1)
{
try {
mif.id.setText(rs1.getString("ID"));
mif.total.setText(rs1.getString("Total"));
mif.philosophy.setText(rs1.getString("philosopy"));
mif.math.setText(rs1.getString("math"));
mif.english.setText(rs1.getString("english"));
mif.specialty.setText(rs1.getString("specialty"));
} catch (SQLException e) {
// TODO Auto-generated catch block
JOptionPane.showMessageDialog(null,"成绩查询时出错!");
e.printStackTrace();
}
}
public void markTableShow()//查询结果为多个
{
StudentMarkTableFrame smtf=new StudentMarkTableFrame();
smtf.resultShow(rs1);
smtf.setVisible(true);
}
public void showResult(ResultSet rs)//查询结果为一个
{
try {
MainFrame.mif.id.setText(rs.getString("ID"));
MainFrame.mif.total.setText(rs.getString("Total"));
MainFrame.mif.philosophy.setText(rs.getString("philosophy"));
MainFrame.mif.math.setText(rs.getString("math"));
MainFrame.mif.english.setText(rs.getString("english"));
MainFrame.mif.specialty.setText(rs.getString("specialty"));
MainFrame.mif.setVisible(true);
MainFrame.mif.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
MainFrame.mif.setTextAbled(false);
MainFrame.mif.setButton(true, true, true, false, false);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -