📄 query.java
字号:
/*查询学生信息程序Query.java*/
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.util.*;
public class Query implements ActionListener
{ JTextField [] value=new JTextField[6];
JTextField condition=new JTextField(10);
JButton queryButton,exitButton;
JPanel panel1,panel2;
StudentManager server;
public Query(StudentManager server,JPanel content) //构造器
{ this.server=server;
content.setLayout(new GridLayout(2,1));
for(int i=0;i<value.length; i++) value[i] = new JTextField(30);
queryButton = new JButton("查询");
exitButton = new JButton("退出");
panel1=new JPanel(new GridLayout(4,1));
panel2=new JPanel(new GridLayout(7,1));
panel1.add(new JLabel("输入条件如:学号='20060132102'或入学成绩>600等"));
panel1.add(condition);
panel1.add(queryButton);
panel1.add(exitButton);
panel2.add(new JLabel("---------- 学号---------姓名--出生年月--性别--入学成绩-备注"));
for(int i=0;i<value.length; i++) panel2.add(value[i]);
content.add(panel1);
content.add(panel2);
queryButton.addActionListener(this);
exitButton.addActionListener(this);
} //构造器结束
public void actionPerformed(ActionEvent evt) //事件方法
{
Object obj = evt.getSource();
if(obj == queryButton)
{panel1.setVisible(false); //禁止查询条件输入和查询按钮功能,保证本查询完成
try
{String cond=condition.getText().trim();
if(cond.length()>1) cond=" where "+cond;
String sqlstr="select * from student_login "+cond;
Vector vec=server.query(sqlstr); //调用远程方法
int count=0;
int elementCount=0;
while(elementCount<vec.size())
{ String str="";
for(int i=1; i<=6; i++)
{ String temp=(String)vec.get(elementCount++);
if(temp==null) temp=" ";
str=str+temp.trim()+" ";
}
value[count].setText(str);
count++;
if(count>=value.length)
{ count=0;
JOptionPane.showMessageDialog(null,"下一屏!","提示信息",JOptionPane.PLAIN_MESSAGE);
}
}
for(;count<value.length;count++) value[count].setText("");
}
catch(Exception e) { System.out.println("Error:"+e); }
panel1.setVisible(true);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -