Create a program that simulates the student information management. After user e
ID: 3777948 • Letter: C
Question
Create a program that simulates the student information management. After user enters the information, the "Submit" button will store the student's information; when we click the "Show Student Info" button, the student's information will be displayed; while when we click the "Modify" button, a second window will pop up and the student's information will be filled automatically. After the student's information modification, we click the "Submit'' button in the second window, then the second windows disappears and the new student's information will be filled in the first window automatically. Student name: Jacksmith Student namel Student ID 012 Student ID: Student Age: Student Age Name: Jack Smith, ID: 0123456788, AgExplanation / Answer
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
class student
{
String msg="";
Button btnNew,btnSubmit,btnshow student info,btnmodify;
Label lblName,lblid,lblAge,
TextField txtName,txtid,txtage;
{
super(name);
setLayout(new GridLayout(3,2));
lblName = new Label("Name: ");
lblid = new Label("id: ");
lblage = new Label("age: ");
txtName = new TextField(20);
txtid = new TextField(20);
txtage = new TextArea();
btnNew = new Button("NEW");
btnSubmit = new Button("SUBMIT");
btn show student info = new Button("show student info");
btnmodify=new button("modify");
btnNew.addActionListener(this);
btnSubmit.addActionListener(this);
btnshowstudentinfo.addActionListener(this);
btnmodify.addActionListener(this);
add(lblName);
add(txtName);
add(lblid);
add(txtid);
add(lblage);
add(txtage);
add(btnNew);
add(btnSubmit);
add(btnView);
txtAns = new TextArea();
add(txtAns);
}
publicvoid actionPerformed(ActionEvent ae)
{
String s="";
boolean b;
FileInputStream Fin;
DataInputStream dis;
FileOutputStream Fout;
DataOutputStream dos;
try
{
Fout = new FileOutputStream("Biodata.txt",true);
dos = new DataOutputStream(Fout);
String str = ae.getActionCommand();
if(str.equals("SUBMIT"))
{
s=txtName.getText().trim();
dos.writeUTF(s);
dos..writeInt(integer parseint(intid.gettext()));
dos.writeInt(Integer.parseInt(txtAge.getText()));
s+="!";
dos.writeUTF(s);
Fout.close();
}
if(str.equals("VIEW"))
{
String tmp,name;
int id,age;
Fin = new FileInputStream("Biodata.txt");
dis = new DataInputStream(Fin);
int i=0,j;
while(Fin.available()>0)
{
name = dis.readUTF();
id = dis.readInt();
age = dis.readint();
if(name.equals(txtName.getText().trim()))
{
txtid.setid(id+"");
txtAge.setText(age+"");
}
}
catch(Exception e)
{
System.out.println("The Exception Is : " +e);
}
}
}
class Bio2
{
publicstaticvoid main(String args[])
{
try{
Frame1 F = new Frame1("Biodata");
F.setSize(400,400);
F.show();
}catch(Exception e)
{
System.out.println(e);
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.