java大作业报告模板 下载本文

内容发布更新时间 : 2024/12/25 21:33:42星期一 下面是文章的全部内容请认真阅读。

5点击修改按钮来到修改界面,先输入学号查询,然后更改信息再点击保○

存按钮,为了验证这一功能我们把小王改为小赵,然后在查询界面中查学10007,运行如下:

六、 代码如下:

import java.awt.Color; import java.awt.Font;

import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.File;

import java.io.FileInputStream;

import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import javax.swing.*;

public class JFrameDemo extends JFrame { String s123; char ch=' ';

int number1,number=5;

JButton b1,b2,b3,b4,b5,b6,jb1,jb2,b7;

JLabel l1,l2,l3,l4,l5,l6,l7,jl1,jl2,jl3,jl4, jl5,jl6,jl7,jl8,jl9,jll1,jll2,jll3; JRadioButton r1,r2;

JTextField t1,t2,t3,t4,t5,t6,jt1,jt2,jt3,jt4,jt5, jt6,jt7,jtt,jtt1; JPanel j1,j2,j3,j4; JTextArea jArea;

public JFrameDemo() throws IOException{

File file=new File(\ file.createNewFile(); FileInputStream fis=new

FileInputStream(\ File file1=new File(\ file.createNewFile();

this.setTitle(\学生个人信息管理系统\

this.setLayout(null);

r1=new JRadioButton(\男\ r2=new JRadioButton(\女\

t1=new JTextField(30); t2=new JTextField(30); //t3=new JTextField(30); t4=new JTextField(30); t5=new JTextField(30); t6=new JTextField(30); j1=new JPanel(); j2=new JPanel(); j2.setLayout(null);

j3=new JPanel(); j3.setLayout(null); j4=new JPanel(); j4.setLayout(null); b1=new JButton(\录入\ b2=new JButton(\修改\ b3=new JButton(\查询\ b4=new JButton(\重置\ b5=new JButton(\提交\ b6=new JButton(\查询\

b7=new JButton(\显示全部信息\ jll1=new JLabel(\查找学生信息\

jll1.setFont(new Font(\ jll1.setBounds(200,20,300,30); jll2=new JLabel(\输入学号\

jll2.setFont(new Font(\ jll2.setBounds(90, 100, 80,30); jtt=new JTextField(30);

jtt.setBounds( 190, 100, 80, 25); jArea=new JTextArea( 10, 570);

jArea.setBounds( 10, 170, 580, 230); b6.setBounds( 305, 100, 80, 25); b7.setBounds(405, 100, 120, 25);

//JScrollPane scrollpane = new JScrollPane(jtt1); // j4.add(scrollpane);

//scrollpane.setBounds(100, 200, 20, 40); //add(j4 );

b6.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) { FileReader fr = null; try {

fr = new FileReader(\ } catch (FileNotFoundException e1) {

e1.printStackTrace(); }

try {

number1=(int)fr.read(); } catch (IOException e1) {

// TODO Auto-generated catch block e1.printStackTrace(); } try {

fr.close();

} catch (IOException e1) {

// TODO Auto-generated catch block e1.printStackTrace(); }

if (number1!=-1) number=number1;

System.out.println(number);

if(!jtt.getText().trim().equals(\ filefind(); }

else{

JOptionPane.showMessageDialog(null,\请输入需要查询学生的学号\

\温馨提示\ } }

public void filefind() { byte a[]=new byte[1000]; int i;

int findpersion=-1;

String str=null; try{

FileInputStream fis=new FileInputStream(\

i=fis.read(a,0,1000); try{

str=new String(a,0,i); }

catch(Exception ee){

System.out.println(\编码没有被发现\ }

fis.close(); }

catch(FileNotFoundException e){

System.out.println(\ }

catch(IOException e){ e.printStackTrace(); }

System.out.println(\ System.out.println(str);

System.out.println(\

String[] findstring=new String[number]; String[] sstr=new String[5]; findstring=str.split(\ String sfind=null;

for(int j=0;j

if(findstring[j].indexOf(jtt.getText())!=-1){ findpersion=j;

jArea.setText( findstring[findpersion]); break; } }

if(findpersion==-1)

JOptionPane.showMessageDialog(null, \查无此学生\

\提示

\ } });