改通程序就给分 中午前结帖

胖奶糖 2007-11-24 01:02:25
保留接口,别的随意,实在该不通了。。。中午前节帖,谢谢
import java.io.*; 
import java.awt.event.*;
//import java.util.*;
class Content
{
String names;
String position;
String department;
String name;
String type;
public Content(){}
public void setcontent(String ns, String p, String d, String na, String t)
{
names=ns;
position=p;
department=d;
name=na;
type=t;
}
public String getnames()
{
return names;
}
public String getposition()
{
return position;
}
public String getdepartment()
{
return department;
}
public String getname()
{
return name;
}
public String gettype()
{
return type;
}

}
interface display{
int i=0;
public void display();
}

public class InforFound extends WindowAdapter implements ActionListener,
ItemListener
{

Frame f;
TextField tf1, tf2, tf3, tf4;
Button b1, b2, b3, b4;
List l;
Content content[] = new Content[3];

public InforFound()
{
content[0] = new Content();
content[1] = new Content();
content[2] = new Content();

f = new Frame("信息查询系统");
f.setSize(640, 480);
Panel p = new Panel();
p.add(new Label("学校:"));
tf1 = new TextField(10);
p.add(tf1);
p.add(new Label("单位:"));
tf2 = new TextField(10);
p.add(tf2);



p.add(new Label("部门:"));
tf3 = new TextField(10);
p.add(tf3);
p.add(new Label("教师:"));
tf4 = new TextField(10);
p.add(tf4);
f.add("North",p);
b1 = new Button("教师信息查询");
b2 = new Button("教师学校信息查询");
b3 = new Button("学校信息查询");
b4 = new Button("部门信息查询");
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
Panel p3 = new Panel();
p3.add(b1);
p3.add(b2);
p3.add(b3);
p3.add(b4);
f.add("South",p3);

l = new List();
l.add("您要查询的信息如下:");
l.addItemListener(this);
f.add(l);
f.setVisible(true);
f.addWindowListener(this);
content[0].setcontent("范书国", "副教授", "项目开发部",
"软件学院", "沈阳师范大学");
content[1].setcontent("宋波", "副教授", "项目研究部",
"软件学院", "沈阳师范大学");
content[2].setcontent("赵大宇", "教授", "校领导部", "行政部",
"沈阳师范大学");
}




public void actionPerformed(ActionEvent e)
{
if (e.getSource() == b1)
{
f.setVisible(true);
displaymentb1 d1=new displaymentb1();
}
if (e.getSource() == b2)

{
f.setVisible(true);
displaymentb2 d2=new displaymentb2();
}
if (e.getSource() == b3)
{

f.setVisible(true);
displaymentb3 d3=new displaymentb3();
}


if (e.getSource() == b4)
{

f.setVisible(true);
displaymentb4 d4=new displaymentb4();
}

}


public static void main(String args[])
{
new InforFound();


}
public void itemStateChanged(ItemEvent e){}
//实现条目状态改变

public void windowClosing(WindowEvent e)
{
//实现窗口关闭
System.exit(0);
}
}


class displaymentb3 implements display
{
public void display()
{

for (i = 0; i < content.length; i++)
{
if (tf1.getText().equals(content[i].getname()))
l.add(content[i].getname()+" "+content[i].getdepartment());
}
if (i > content.length)
l.add("您要查找的信息不存在");
}


}
class diplaymentb4 implements display
{
public void display()
{
int i;
for (i = 0; i < content.length; i++)
{
if (tf2.getText().equals(content[i].getposition()) && tf3.getText().equals(content[i].getdepartment()))
l.add(content[i].getnames()+" "+
content[i].getposition()+" "+content[i].getdepartment());
}
if (i > content.length)
l.add("您要查找的信息不存在");
}
}
class diplaymentb2 implements display
{
public void display()
{
int i;
for (i = 0; i < content.length; i++)
{
if (tf4.getText().equals(content[i].getnames()) && tf1.getText().equals(content[i].getname()))
l.add(content[i].getname()+" "+content[i].gettype()+" "
+content[i].getnames()+" "+content[i].getposition()+" "+content[i].getdepartment());
}
if (i > content.length)
l.add("您要查找的信息不存在");

}
}
class diplaymentb1 implements display
{
public void display()
{
int i;
for (i = 0; i < content.length; i++)
{
if (tf4.getText().equals(content[i].getnames()))
l.add(content[i].getname()+" "+content[i].gettype()+" "
+content[i].getnames()+" "+content[i].getposition()+" "+content[i].getdepartment());

}
if (i > content.length)
l.add("您要查找的信息不存在");

}
}

...全文
98 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
胖奶糖 2007-11-24
  • 打赏
  • 举报
回复
谢谢
xiyuan1999 2007-11-24
  • 打赏
  • 举报
回复
Up

So long code
cursor_wang 2007-11-24
  • 打赏
  • 举报
回复
不知道你具体的要求,我想大概是这样的.你运行下.

import java.awt.*;
import java.awt.event.*;
class Content
{
String names;
String position;
String department;
String name;
String type;
public Content(){}
public void setcontent(String ns, String p, String d, String na, String t)
{
names=ns;
position=p;
department=d;
name=na;
type=t;
}
public String getnames()
{
return names;
}
public String getposition()
{
return position;
}
public String getdepartment()
{
return department;
}
public String getname()
{
return name;
}
public String gettype()
{
return type;
}

}
interface display{
int i=0;
public void display();
}

public class InforFound extends WindowAdapter implements ActionListener,display,
ItemListener
{

Frame f;
TextField tf1, tf2, tf3, tf4;
Button b1, b2, b3, b4;
List l;
Content content[] = new Content[3];

public InforFound()
{
content[0] = new Content();
content[1] = new Content();
content[2] = new Content();

f = new Frame("信息查询系统");
f.setSize(640, 480);
Panel p = new Panel();
p.add(new Label("学校:"));
tf1 = new TextField(10);
p.add(tf1);
p.add(new Label("单位:"));
tf2 = new TextField(10);
p.add(tf2);



p.add(new Label("部门:"));
tf3 = new TextField(10);
p.add(tf3);
p.add(new Label("教师:"));
tf4 = new TextField(10);
p.add(tf4);
f.add("North",p);
b1 = new Button("教师信息查询");
b2 = new Button("教师学校信息查询");
b3 = new Button("学校信息查询");
b4 = new Button("部门信息查询");
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
Panel p3 = new Panel();
p3.add(b1);
p3.add(b2);
p3.add(b3);
p3.add(b4);
f.add("South",p3);

l = new List();
l.add("您要查询的信息如下:");
l.addItemListener(this);
f.add(l);
f.setVisible(true);
f.addWindowListener(this);
content[0].setcontent("范书国", "副教授", "项目开发部",
"软件学院", "沈阳师范大学");
content[1].setcontent("宋波", "副教授", "项目研究部",
"软件学院", "沈阳师范大学");
content[2].setcontent("赵大宇", "教授", "校领导部", "行政部",
"沈阳师范大学");
}




public void actionPerformed(ActionEvent e)
{
if (e.getSource() == b1)
{
f.setVisible(true);
//displaymentb1 d1=new displaymentb1();
display();
}
if (e.getSource() == b2)

{
f.setVisible(true);
//displaymentb2 d2=new displaymentb2();
display();
}
if (e.getSource() == b3)
{

f.setVisible(true);
//displaymentb3 d3=new displaymentb3();
display();
}


if (e.getSource() == b4)
{

f.setVisible(true);
//displaymentb4 d4=new displaymentb4();
display();
}

}


public static void main(String args[])
{
new InforFound();


}
public void itemStateChanged(ItemEvent e){}
//实现条目状态改变

public void windowClosing(WindowEvent e)
{
//实现窗口关闭
System.exit(0);
}




public void display()
{
int i;
int flag=1;
for (i = 0; i < content.length; i++)
{
if (tf1.getText().equals(content[i].gettype()))
{
l.add(content[i].getnames()+" "+
content[i].getposition()+" "+content[i].getdepartment());
}

else if(tf2.getText().equals(content[i].getname()))
{
l.add(content[i].getnames()+" "+
content[i].getposition()+" "+content[i].getdepartment());
}
else if(tf3.getText().equals(content[i].getdepartment()))
{
l.add(content[i].getnames()+" "+
content[i].getposition()+" "+content[i].getdepartment());
}
else if(tf4.getText().equals(content[i].getnames()))
{
l.add(content[i].getnames()+" "+
content[i].getposition()+" "+content[i].getdepartment());
}
else{
flag++;
}
}
if (flag==3)
l.add("");
else if(flag==1){
l.add("");
}
else if(flag==2){
l.add("");
}
else
l.add("您要查找的信息不存在");
}
}
cursor_wang 2007-11-24
  • 打赏
  • 举报
回复
你要查什么我一点都不知道?根据什么查什么?你要写下你代码要实现的功能.

62,623

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧