想弄个查询按钮,但是写不出查询方法。。。求怎样查询文本里指定内容
这个是我的代码
public class SelectDomitory extends JDialog implements ActionListener{
public void actionPerformed(ActionEvent e){
JFrame frame03 = new JFrame();
frame03.setTitle("查询宿舍信息");
frame03.setBounds(450, 200, 400,400);
Container content01 = frame03.getContentPane();
JTextField 宿舍编号 =new JTextField(10);
宿舍编号.addActionListener(this);
/*JTextField 实住人数 =new JTextField(10);
实住人数.setEditable(false);
JTextField 楼栋编号 =new JTextField(10);
楼栋编号.setEditable(false);
JTextField 楼层数 =new JTextField(10);
楼层数.setEditable(false);
JTextField 床位数 =new JTextField(10);
床位数.setEditable(false);
JTextField 房间数 =new JTextField(10);
房间数.setEditable(false);
JRadioButton 男 =new JRadioButton("男",false);
JRadioButton 女 =new JRadioButton("女",false);
ButtonGroup group=new ButtonGroup();
group.add(男);
group.add(女);*/
JTextArea area=new JTextArea();
JButton b3 =new JButton("查询");
b3.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
//实住人数.setText(null);
//楼栋编号.setText(null);
//String key=宿舍编号.getText();
String keyword = "我们";
// String fileName = "D:/eclipse/实训/src/studentdomitory/信息.txt";
try
{
FileReader fr=new FileReader("D:/eclipse/实训/src/studentdomitory/信息.txt");
BufferedReader br=new BufferedReader(fr);
StringBuilder b=new StringBuilder();
String str=null;
while((str=br.readLine())!=null){
b.append(str);
}
br.close();
String be=b.toString();
System.out.println(be);
if(str.indexOf(keyword)!=-1){
String text[]=str.split(keyword);
System.out.println(text[1]);
}
/*Pattern p=Pattern.compile(key);
Matcher m=p.matcher(be);
if(m.find()==true){
area.setText("有匹配字符串");
return;
}*/
}
catch(Exception ee){
}
}
});
Box box1=Box.createHorizontalBox();
box1.add(new JLabel("输入要查询的宿舍编号:",JLabel.CENTER));
box1.add(宿舍编号);
box1.add(b3);
Box box3=Box.createHorizontalBox();
box3.add(new JLabel("查询结果:",JLabel.CENTER));
box3.add(area);
Box boxH=Box.createVerticalBox();
boxH.add(box1);
boxH.add(box3);
/*boxH.add(box2);
boxH.add(box3);
boxH.add(box4);*/
boxH.add(Box.createVerticalGlue());
JPanel pCenter=new JPanel();
pCenter.add(boxH);
content01.add(pCenter,BorderLayout.CENTER);
content01.validate();
frame03.setVisible(true);
frame03.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
frame03.setVisible(true);
}
});
}
}