📄 frame1.java~9~
字号:
package pack_Name;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import com.borland.jbcl.layout.*;
import java.sql.*;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2006</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/
public class Frame1 extends JFrame {
JPanel contentPane;
XYLayout xYLayout1 = new XYLayout();
JTextField jTextField1 = new JTextField();
JLabel jLabel1 = new JLabel();
JToggleButton jToggleButton1 = new JToggleButton();
Connection con=null;
Statement sql=null;
ResultSet rs=null;
//Construct the frame
public Frame1() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
//Component initialization
private void jbInit() throws Exception {
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e) {}
try{
con=DriverManager.getConnection("jdbc:odbc:grade","","");
sql=con.createStatement();
}
catch(SQLException e)
{}
contentPane = (JPanel) this.getContentPane();
jTextField1.setText("jTextField1");
contentPane.setLayout(xYLayout1);
this.setSize(new Dimension(400, 300));
this.setTitle("Frame Title");
jLabel1.setFont(new java.awt.Font("Dialog", 1, 14));
jLabel1.setText("姓名");
jToggleButton1.setText("查询");
jToggleButton1.addActionListener(new Frame1_jToggleButton1_actionAdapter(this));
contentPane.add(jTextField1, new XYConstraints(182, 70, 79, -1));
contentPane.add(jLabel1, new XYConstraints(86, 72, -1, -1));
contentPane.add(jToggleButton1, new XYConstraints(195, 187, -1, -1));
}
//Overridden so we can exit when window is closed
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
try{
sql.close();
con.close();
}
catch(SQLException ex)
{}
System.exit(0);
}
}
void jToggleButton1_actionPerformed(ActionEvent e) {
String condition="SELECT * FROM students WHERE name ="+"'"+name+"'";
rs=sql.executeQuery(condition);
System.out.print("hhhhhhhhhhhhh");
System.out.println();
System.out.print("学号");
System.out.print("姓名");
System.out.print("数学成绩");
System.out.print("英语成绩");
System.out.print("物理成绩");
System.out.println();
while(rs.next())
{
out.print("<TR>");
out.print("<TD >"+rs.getString(1)+"</TD>");
out.print("<TD >"+rs.getString(2)+"</TD>");
out.print("<TD >"+rs.getInt(3)+"</TD>");
out.print("<TD >"+rs.getInt(4)+"</TD>");
out.print("<TD >"+rs.getInt(5)+"</TD>");
out.print("</TR>");
}
}
}
class Frame1_jToggleButton1_actionAdapter implements java.awt.event.ActionListener {
Frame1 adaptee;
Frame1_jToggleButton1_actionAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jToggleButton1_actionPerformed(e);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -