📄 sushe.java
字号:
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
class zuoye1 extends Frame implements ActionListener
{ private Label xing,xue,ww0;
private TextField a1,a2;
private TextArea ww3;
private Panel panal,panal2;
private CheckboxMenuItem debug, test;
Color obj;
Font ww4,ww5,ww6;
Button ww7,ww8,ww11,ww12;
Connection con;
Statement sql;
ResultSet rs;
CardLayout lay;
public zuoye1()
{
super("成绩查询");
setSize(450,450);
setLocation(350,200);
MenuBar mbar = new MenuBar();
setMenuBar(mbar);
Menu file = new Menu("File");
MenuItem item1, item2, item3, item4, item5;
file.add(item1 = new MenuItem("New..."));
file.add(item2 = new MenuItem("Open..."));
file.add(item3 = new MenuItem("Close"));
file.add(item4 = new MenuItem("-"));
file.add(item5 = new MenuItem("Quit..."));
item5.addActionListener(this);
mbar.add(file);
Menu edit = new Menu("Edit");
MenuItem item6, item7, item8, item9;
edit.add(item6 = new MenuItem("Cut"));
edit.add(item7 = new MenuItem("Copy"));
edit.add(item8 = new MenuItem("Paste"));
edit.add(item9 = new MenuItem("-"));
Menu sub = new Menu("Special");
MenuItem item10, item11, item12;
sub.add(item10 = new MenuItem("First"));
sub.add(item11 = new MenuItem("Second"));
sub.add(item12 = new MenuItem("Third"));
edit.add(sub);
debug = new CheckboxMenuItem("Debug");
edit.add(debug);
test = new CheckboxMenuItem("Testing");
edit.add(test);
mbar.add(edit);
panal=new Panel();
add(panal);
ww4=new Font("成绩查询系统", Font.BOLD,20);
ww5=new Font("姓名", Font.BOLD,15);
ww6=new Font("学号", Font.BOLD,15);
panal.setLayout(null);
ww0=new Label("----------------------成绩查询系统-----------------------");
ww0.setFont(ww4);
obj=new Color(200,0,20);
ww0.setForeground(obj);
panal.add(ww0);
ww0.setBounds(5,10,430,50);
xing=new Label("姓名:");
panal.add(xing);
xing.setBounds(100,50,50,50);
xing.setFont(ww5);
a1=new TextField();
panal.add(a1);
a1.setBounds(150,60,150,20);
xue=new Label("学号:");
xue.setFont(ww6);
panal.add(xue);
xue.setBounds(100,100,50,20);
a2=new TextField();
panal.add(a2);
a2.setBounds(150,100,150,20);
ww3=new TextArea();
ww3.setForeground(Color.red);
ww3.setFont(ww6);
panal.add(ww3);
ww3.setBounds(93,170,300,250);
ww7=new Button("查询");
panal.add(ww7);
ww7.setBounds(150,130,50,20);
ww8=new Button("重置");
ww8.setBounds(250,130,50,20);
panal.add(ww8);
ww8.addActionListener(this);
ww7.addActionListener(this);
setVisible(true);
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(Exception e){
ww3.append(e.getMessage()+"\n");
return;
}
addWindowListener(
new WindowAdapter() {
public void windowClosing( WindowEvent e )
{
System.exit( 0 );
}
}
);
}
public void actionPerformed( ActionEvent event )
{ String msg=(String)event.getActionCommand();
if( msg.equals("Quit..."))
System.exit(0);
if ( event.getSource() == ww8 )
{ a1.setText(null);
a2.setText(null);
ww3.setText(null);
}
if ( event.getSource() == ww7)
{
if(a1.getText().length()==0||a2.getText().length()==0)
{
dial d = new
dial(this, "填写","文本框不能为空");
d.setVisible(true);
}
else{
try{
con=DriverManager.getConnection("jdbc:odbc:lili","","");
sql=con.createStatement();
ww3.setText("");
String name3=a1.getText();
String number6=a2.getText();
rs=sql.executeQuery("Select * FROM account where 姓名"+" like '"+name3+"'"+"and 学号 like '"+number6+"'" );
if(!rs.next()){
dial ww = new
dial(this, "信息","对不起,该用户信息不存在!!");
ww.setVisible(true);
}
else
{
do
{ String name=rs.getString("姓名");
String number=rs.getString("学号");
String number2=rs.getString("英语");
String number3=rs.getString("C++");
String number4=rs.getString("数学");
ww3.append(" "+"姓名:"+name+"\n");
ww3.append(" "+"学号:"+number+"\n");
ww3.append(" "+"英语:"+number2+"\n");
ww3.append(" "+"C++:"+number3+"\n");
ww3.append(" "+"数学:"+number4+"\n");
}while(rs.next());
}
}
catch(SQLException e){
}
}
}
}
}
class dial extends Dialog implements ActionListener {
dial(Frame parent, String title,String question) {
super(parent, title, true);
setLayout(new BorderLayout());
setSize(200, 90);
setLocation(470,330);
Panel pa=new Panel();
Panel pp=new Panel();
Label laa=new Label();
pa.add(laa);
laa.setText(question);
add(pa,BorderLayout.NORTH);
Button ok;
ok = new Button("ok");
pp.add(ok);
add(pp,BorderLayout.CENTER);
ok.addActionListener(this);
}
public void actionPerformed(ActionEvent ae) {
hide();
}
}
public class sushe
{
public static void main(String[] args)
{
new zuoye1();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -