?? stusearchsmajor.java
字號:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.net.*;
/**
* 學(xué)生信息查詢模塊
* 根據(jù)學(xué)生的專業(yè)查詢學(xué)生信息
*/
public class StuSearchSmajor extends JFrame implements ActionListener{
Container contentPane;
//框架的大小
Dimension faceSize = new Dimension(300, 100);
JLabel jLabel1 = new JLabel();
JTextField sMajor = new JTextField(8);
JButton searchInfo = new JButton();
public StuSearchSmajor() {
//設(shè)置標(biāo)題
this.setTitle("按專業(yè)查詢");
this.setResizable(false);
//設(shè)置程序圖標(biāo)
this.setIconImage(getImage("icon.gif"));
try {
Init();
}
catch (Exception e) {
}
//設(shè)置運(yùn)行位置,使對話框居中
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
this.setLocation( (int) (screenSize.width - 400) / 2 ,
(int) (screenSize.height - 300) / 2 + 45);
}
private void Init() throws Exception {
this.setSize(faceSize);
contentPane = this.getContentPane();
contentPane.setLayout(new FlowLayout());
jLabel1.setText("請輸入專業(yè)名稱: ");
jLabel1.setFont(new Font("Dialog",0,12));
contentPane.add(jLabel1);
sMajor.setText(null);
sMajor.setFont(new Font("Dialog",0,12));
contentPane.add(sMajor);
searchInfo.setText("確定");
searchInfo.setFont(new Font("Dialog",0,12));
contentPane.add(searchInfo);
searchInfo.addActionListener(this);
}
/**
* 事件處理
*/
public void actionPerformed(ActionEvent e) {
Object obj = e.getSource();
if (obj == searchInfo) { //查詢
ResultStudent rS = new ResultStudent("smajor",sMajor.getText());
this.dispose();
}
}
/**
* 通過給定的文件名獲得圖像
*/
Image getImage(String filename) {
URLClassLoader urlLoader = (URLClassLoader)this.getClass().
getClassLoader();
URL url = null;
Image image = null;
url = urlLoader.findResource(filename);
image = Toolkit.getDefaultToolkit().getImage(url);
MediaTracker mediatracker = new MediaTracker(this);
try {
mediatracker.addImage(image, 0);
mediatracker.waitForID(0);
}
catch (InterruptedException _ex) {
image = null;
}
if (mediatracker.isErrorID(0)) {
image = null;
}
return image;
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -