?? sms.java
字號(hào):
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
public class SMS implements ActionListener{
public static StringBuffer [][]student = new StringBuffer[100][8];
public static StringBuffer temp = new StringBuffer("");
public static int i = -1;
public static int k = 0;
public static int m = 0;
public static int g = 0;
JFrame fmain;
JPanel pmain;
JButton btnadd,btndelete,btnchange,btnsearch,btntaxis;
JLabel lb;
public static void main(String []args){
SMS mainframe = new SMS();
mainframe.go();
}
void go(){
Color c = new Color(0,111,232);
Font h = new Font("幼圓",Font.BOLD,18);
fmain = new JFrame("學(xué)生基本信息管理系統(tǒng)");
pmain = new JPanel();
pmain.setLayout(null);
lb = new JLabel(new ImageIcon("1.jpg"));
btnadd = new JButton("添 加");
btndelete = new JButton("刪 除");
btnchange = new JButton("修 改");
btnsearch = new JButton("查 詢");
btntaxis = new JButton("排 序");
btnadd.setFont(h);
btndelete.setFont(h);
btnchange.setFont(h);
btnsearch.setFont(h);
btntaxis.setFont(h);
btnadd.setForeground(Color.yellow);
btndelete.setForeground(Color.yellow);
btnchange.setForeground(Color.yellow);
btnsearch.setForeground(Color.yellow);
btntaxis.setForeground(Color.yellow);
pmain.add(btnadd);
pmain.add(btndelete);
pmain.add(btnchange);
pmain.add(btnsearch);
pmain.add(btntaxis);
pmain.add(lb);
fmain.add(pmain,"Center");
lb.setBounds(0,0,350,300);
btnadd.setBounds(20,224,90,30);
btndelete.setBounds(122,224,90,30);
btnchange.setBounds(225,224,90,30);
btnsearch.setBounds(71,260,90,30);
btntaxis.setBounds(175,260,90,30);
btnadd.setBackground(c);
btndelete.setBackground(c);
btnchange.setBackground(c);
btnsearch.setBackground(c);
btntaxis.setBackground(c);
btnadd.addActionListener(this);
btndelete.addActionListener(this);
btnchange.addActionListener(this);
btnsearch.addActionListener(this);
btntaxis.addActionListener(this);
fmain.setLocation(500,300);
fmain.setSize(350,335);
fmain.setVisible(true);
fmain.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent e)
{
if((String)e.getActionCommand()=="添 加"){
AddFrame addframe = new AddFrame();
addframe.go();
}
if((String)e.getActionCommand()=="刪 除"){
DeleteFrame deleteframe = new DeleteFrame();
deleteframe.go();
}
if((String)e.getActionCommand()=="修 改"){
ChangeSearchFrame changesearchframe = new ChangeSearchFrame();
changesearchframe.go();
}
if((String)e.getActionCommand()=="查 詢"){
SearchFrame searchframe = new SearchFrame();
searchframe.go();
}
if((String)e.getActionCommand()=="排 序"){
TaxisChoiceFrame taxischoiceframe = new TaxisChoiceFrame();
taxischoiceframe.go();
}
}
}
class AddFrame implements ActionListener{
JFrame fadd;
JPanel padd;
JLabel lb;
JLabel lbnumber,lbname,lbsex,lbage,lbresult,lbchinese,lbmaths,lbenglish;
JTextField tfnumber,tfname,tfsex,tfage,tfchinese,tfmaths,tfenglish;
JButton btsure;
void go(){
Font h = new Font("楷體", Font.BOLD, 18);
Font q = new Font("楷體", Font.BOLD, 22);
fadd = new JFrame("添加");
padd = new JPanel();
padd.setLayout(null);
lb = new JLabel(new ImageIcon("2.jpg"));
lbnumber = new JLabel("學(xué)號(hào)");
lbname = new JLabel("姓名");
lbsex = new JLabel("性別");
lbage = new JLabel("年齡");
lbresult = new JLabel("成 績(jī)");
lbchinese = new JLabel("語(yǔ)文");
lbmaths = new JLabel("數(shù)學(xué)");
lbenglish = new JLabel("英語(yǔ)");
lbnumber.setFont(h);
lbname.setFont(h);
lbsex.setFont(h);
lbage.setFont(h);
lbresult.setFont(q);
lbchinese.setFont(h);
lbmaths.setFont(h);
lbenglish.setFont(h);
lbnumber.setForeground(Color.blue);
lbname.setForeground(Color.blue);
lbsex.setForeground(Color.blue);
lbage.setForeground(Color.blue);
lbresult.setForeground(Color.red);
lbchinese.setForeground(Color.red);
lbmaths.setForeground(Color.red);
lbenglish.setForeground(Color.red);
tfnumber = new JTextField();
tfname = new JTextField();
tfsex = new JTextField();
tfage = new JTextField();
tfchinese = new JTextField();
tfmaths = new JTextField();
tfenglish = new JTextField();
btsure = new JButton("確 定");
btsure.setFont(h);
btsure.setForeground(Color.blue);
padd.add(lbnumber);
padd.add(lbname);
padd.add(lbsex);
padd.add(lbage);
padd.add(lbresult);
padd.add(lbchinese);
padd.add(lbmaths);
padd.add(lbenglish);
padd.add(tfnumber);
padd.add(tfname);
padd.add(tfsex);
padd.add(tfage);
padd.add(tfchinese);
padd.add(tfmaths);
padd.add(tfenglish);
padd.add(btsure);
padd.add(lb);
fadd.add(padd,"Center");
lb.setBounds(0,0,500,320);
lbnumber.setBounds(15,30,40,25);
lbname.setBounds(15,85,40,25);
lbsex.setBounds(15,140,40,25);
lbage.setBounds(15,195,40,25);
lbresult.setBounds(330,30,80,25);
lbchinese.setBounds(250,85,40,25);
lbmaths.setBounds(250,140,40,25);
lbenglish.setBounds(250,195,40,25);
tfnumber.setBounds(70,30,150,25);
tfname.setBounds(70,85,150,25);
tfsex.setBounds(70,140,150,25);
tfage.setBounds(70,195,150,25);
tfchinese.setBounds(300,85,150,25);
tfmaths.setBounds(300,140,150,25);
tfenglish.setBounds(300,195,150,25);
btsure.setBounds(340,240,100,30);
fadd.setLocation(500,300);
fadd.setSize(500,320);
fadd.setVisible(true);
fadd.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
btsure.addActionListener(this);
}
public void actionPerformed(ActionEvent e){
if((String)e.getActionCommand()=="確 定"){
if(tfnumber.getText().equals(""))
{
fadd.dispose();
AddError adderror = new AddError();
adderror.go();
return;
}
for(int j=0;j<=SMS.i;j++){
if(SMS.student[j][0].toString().equals(tfnumber.getText())){
fadd.dispose();
AddNo addno = new AddNo();
addno.go();
return;
}
}
SMS.i ++;
StringBuffer temp;
temp = new StringBuffer(tfnumber.getText());
SMS.student[SMS.i][0] = temp;
temp = new StringBuffer(tfname.getText());
SMS.student[SMS.i][1] = temp;
temp = new StringBuffer(tfsex.getText());
SMS.student[SMS.i][2] = temp;
temp = new StringBuffer(tfage.getText());
SMS.student[SMS.i][3] = temp;
if(tfchinese.getText().equals("")){
SMS.student[SMS.i][4] = new StringBuffer("0");
}
else{
temp = new StringBuffer(tfchinese.getText());
SMS.student[SMS.i][4] = temp;
}
if(tfmaths.getText().equals("")){
SMS.student[SMS.i][5] = new StringBuffer("0");
}
else{
temp = new StringBuffer(tfmaths.getText());
SMS.student[SMS.i][5] = temp;
}
if(tfenglish.getText().equals("")){
SMS.student[SMS.i][6] = new StringBuffer("0");
}
else{
temp = new StringBuffer(tfenglish.getText());
SMS.student[SMS.i][6] = temp;
}
/*temp = new StringBuffer(tfmaths.getText());
SMS.student[SMS.i][5] = temp;
temp = new StringBuffer(tfenglish.getText());
SMS.student[SMS.i][6] = temp;*/
SMS.student[SMS.i][7] = null;
fadd.dispose();
AddFrame_True addframe_true = new AddFrame_True();
addframe_true.go();
}
}
}
class AddError implements ActionListener{
JFrame faddError;
JPanel paddError;
JLabel laddError,lb;
JButton btsure;
void go(){
Font h = new Font("楷體", Font.BOLD, 18);
lb = new JLabel(new ImageIcon("2.jpg"));
faddError = new JFrame("添加出錯(cuò)");
paddError = new JPanel();
paddError.setLayout(null);
laddError = new JLabel("必須輸入學(xué)號(hào)!");
btsure = new JButton("確 定");
laddError.setFont(h);
btsure.setFont(h);
laddError.setForeground(Color.red);
btsure.setForeground(Color.blue);
paddError.add(laddError);
paddError.add(btsure);
paddError.add(lb);
faddError.add(paddError,"Center");
laddError.setBounds(80,25,150,30);
btsure.setBounds(180,60,90,30);
lb.setBounds(0,0,300,140);
btsure.addActionListener(this);
faddError.setLocation(530,400);
faddError.setSize(300,140);
faddError.setVisible(true);
faddError.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
}
public void actionPerformed(ActionEvent e){
if((String)e.getActionCommand()=="確 定"){
faddError.dispose();
}
}
}
class AddNo implements ActionListener{
JFrame faddno;
JPanel paddno;
JLabel laddno,lb;
JButton btsure;
void go(){
Font h = new Font("楷體", Font.BOLD, 18);
lb = new JLabel(new ImageIcon("2.jpg"));
faddno = new JFrame("添加不成功");
paddno = new JPanel();
paddno.setLayout(null);
laddno = new JLabel("該學(xué)號(hào)已存在!");
btsure = new JButton("確 定");
laddno.setFont(h);
btsure.setFont(h);
laddno.setForeground(Color.red);
btsure.setForeground(Color.blue);
paddno.add(laddno);
paddno.add(btsure);
paddno.add(lb);
faddno.add(paddno,"Center");
laddno.setBounds(80,25,150,30);
btsure.setBounds(180,60,90,30);
lb.setBounds(0,0,300,140);
btsure.addActionListener(this);
faddno.setLocation(530,400);
faddno.setSize(300,140);
faddno.setVisible(true);
faddno.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
}
public void actionPerformed(ActionEvent e){
if((String)e.getActionCommand()=="確 定"){
faddno.dispose();
}
}
}
class AddFrame_True implements ActionListener{
JFrame faddtrue;
JPanel paddtrue;
JLabel laddtrue,lb;
JButton btsure;
void go(){
Font h = new Font("楷體", Font.BOLD, 18);
lb = new JLabel(new ImageIcon("2.jpg"));
faddtrue = new JFrame("添加結(jié)果");
paddtrue = new JPanel();
paddtrue.setLayout(null);
laddtrue = new JLabel("添加成功!");
btsure = new JButton("確 定");
laddtrue.setFont(h);
btsure.setFont(h);
laddtrue.setForeground(Color.red);
btsure.setForeground(Color.blue);
paddtrue.add(laddtrue);
paddtrue.add(btsure);
paddtrue.add(lb);
faddtrue.add(paddtrue,"Center");
laddtrue.setBounds(100,25,120,30);
btsure.setBounds(180,60,90,30);
lb.setBounds(0,0,300,140);
btsure.addActionListener(this);
faddtrue.setLocation(530,400);
faddtrue.setSize(300,140);
faddtrue.setVisible(true);
faddtrue.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
}
public void actionPerformed(ActionEvent e){
if((String)e.getActionCommand()=="確 定"){
faddtrue.dispose();
}
}
}
class DeleteFrame implements ActionListener{
Font h = new Font("楷體", Font.BOLD, 18);
JFrame fdelete;
JPanel pdelete;
JLabel lbnumber,lb;
JTextField tfnumber;
JButton btsure;
void go(){
lb = new JLabel(new ImageIcon("3.jpg"));
fdelete = new JFrame("刪除");
pdelete = new JPanel();
pdelete.setLayout(null);
lbnumber = new JLabel("學(xué)號(hào)");
tfnumber = new JTextField();
btsure = new JButton("確 定");
lbnumber.setFont(h);
btsure.setFont(h);
lbnumber.setForeground(Color.yellow);
btsure.setForeground(Color.blue);
pdelete.add(lbnumber);
pdelete.add(tfnumber);
pdelete.add(btsure);
pdelete.add(lb);
fdelete.add(pdelete,"Center");
lbnumber.setBounds(50,30,40,30);
tfnumber.setBounds(100,30,180,30);
btsure.setBounds(200,80,100,30);
lb.setBounds(0,0,350,160);
fdelete.setLocation(500,300);
fdelete.setSize(350,160);
fdelete.setVisible(true);
fdelete.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
btsure.addActionListener(this);
}
public void actionPerformed(ActionEvent e){
if((String)e.getActionCommand()=="確 定"){
if(tfnumber.getText().equals(""))
{
fdelete.dispose();
DeleteError deleteerror = new DeleteError();
deleteerror.go();
return;
}
int o=0;
for(int j=0;j<=SMS.i;j++){
if(SMS.student[j][0].toString().equals(tfnumber.getText())){
o++;
SMS.student[j][0] = SMS.temp ;
break;
}
}
if(o==0){
fdelete.dispose();
DeleteNo deleteno = new DeleteNo();
deleteno.go();
return;
}
fdelete.dispose();
DeleteFrame_True deleteframe_true = new DeleteFrame_True();
deleteframe_true.go();
}
}
}
class DeleteError implements ActionListener{
JFrame fdeleteError;
JPanel pdeleteError;
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -