一个java的学生管理系统 出现错误了求高手解答 20
importjava.awt.*;importjava.awt.event.*;importjavax.swing.*;classstu{Stringname;Strin...
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class stu
{ String name;
String sex;
int age;
String hobby;
stu(String name, String sex,int age,String hobby)
{
this.name=name;
this.sex=sex;
this.age=age;
this.hobby=hobby;
}
void print()
{
System.out.println(name+" "+sex+" "+age+" "+hobby);
}
}
class sttb
{
static int i=0;
stu stua[];
public sttb()
{
stua=new stu[5];
}
/**
* @param st
* @return
*/
public boolean addrecord(stu st)//添加元素
{
if(i<5)
{
stua[i]=st;
i++;
return true;
}
else
return false;
}
}
public class aoo implements ActionListener
{ sttb stub;
Frame f=new Frame("学生信息系统");
Label l1=new Label("姓名:");
Label l2=new Label("性别:");
Label l3=new Label("年龄:");
Label l4=new Label("爱好:");
TextField t1=new TextField(10);
TextField t2=new TextField(10);
TextField t3=new TextField(10);
TextField t4=new TextField(10);
Button b1=new Button("输入");
Button b2=new Button("删除");
Button b3=new Button("查找");
Button b4=new Button("清空");
Button b6=new Button("退出");
TextArea ta=new TextArea(10,20);
Panel p=new Panel(new GridLayout(1,3,10,10));
Panel p1=new Panel();
Panel p2=new Panel();
Panel p3=new Panel();
public aoo(sttb stub)
{this.stub=stub;
p1.add(l1);p1.add(t1);
p1.add(l2);p1.add(t2);
p1.add(l3);p1.add(t3);
p1.add(l4);p1.add(t4);
p2.add(b1);p2.add(b2);
p2.add(b3);p2.add(b4);
p2.add(b6);
p3.add(ta);
p.add(p1);p.add(p2);p.add(p3);
f.add(p);
b1.addActionListener(this) ;
b2.addActionListener(this) ;
b6.addActionListener(this);
f.setSize(500,300);
f.setVisible(true);
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource().equals(b1))//添加事件
{
String x;
String y;
int z;
String m;
x=t1.getText();
y=t2.getText();
z=Integer.parseInt(t4.getText());
m=t3.getText();
ta.getText();
stu ss=new stu(x,y,z,m);
if(stub.addrecord(ss))
{
ta.append("\n----------------\n");
t1.setText("");t2.setText("");t3.setText("");
}
else
ta.setText("out");
}
if(ae.getSource().equals(b2))//添加事件
{
for(int i=0;i<5;i++)
stub.stua[i].print();
}
if(ae.getSource().equals(b6))
{
System.exit(0);
}
}
public static void main(String args[])
{ sttb sss=new sttb();
aoo s=new aoo(sss);
}
} 展开
import java.awt.event.*;
import javax.swing.*;
class stu
{ String name;
String sex;
int age;
String hobby;
stu(String name, String sex,int age,String hobby)
{
this.name=name;
this.sex=sex;
this.age=age;
this.hobby=hobby;
}
void print()
{
System.out.println(name+" "+sex+" "+age+" "+hobby);
}
}
class sttb
{
static int i=0;
stu stua[];
public sttb()
{
stua=new stu[5];
}
/**
* @param st
* @return
*/
public boolean addrecord(stu st)//添加元素
{
if(i<5)
{
stua[i]=st;
i++;
return true;
}
else
return false;
}
}
public class aoo implements ActionListener
{ sttb stub;
Frame f=new Frame("学生信息系统");
Label l1=new Label("姓名:");
Label l2=new Label("性别:");
Label l3=new Label("年龄:");
Label l4=new Label("爱好:");
TextField t1=new TextField(10);
TextField t2=new TextField(10);
TextField t3=new TextField(10);
TextField t4=new TextField(10);
Button b1=new Button("输入");
Button b2=new Button("删除");
Button b3=new Button("查找");
Button b4=new Button("清空");
Button b6=new Button("退出");
TextArea ta=new TextArea(10,20);
Panel p=new Panel(new GridLayout(1,3,10,10));
Panel p1=new Panel();
Panel p2=new Panel();
Panel p3=new Panel();
public aoo(sttb stub)
{this.stub=stub;
p1.add(l1);p1.add(t1);
p1.add(l2);p1.add(t2);
p1.add(l3);p1.add(t3);
p1.add(l4);p1.add(t4);
p2.add(b1);p2.add(b2);
p2.add(b3);p2.add(b4);
p2.add(b6);
p3.add(ta);
p.add(p1);p.add(p2);p.add(p3);
f.add(p);
b1.addActionListener(this) ;
b2.addActionListener(this) ;
b6.addActionListener(this);
f.setSize(500,300);
f.setVisible(true);
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource().equals(b1))//添加事件
{
String x;
String y;
int z;
String m;
x=t1.getText();
y=t2.getText();
z=Integer.parseInt(t4.getText());
m=t3.getText();
ta.getText();
stu ss=new stu(x,y,z,m);
if(stub.addrecord(ss))
{
ta.append("\n----------------\n");
t1.setText("");t2.setText("");t3.setText("");
}
else
ta.setText("out");
}
if(ae.getSource().equals(b2))//添加事件
{
for(int i=0;i<5;i++)
stub.stua[i].print();
}
if(ae.getSource().equals(b6))
{
System.exit(0);
}
}
public static void main(String args[])
{ sttb sss=new sttb();
aoo s=new aoo(sss);
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询