Yeah... That's what I'm planning to do.. But first, I'll have to assess the implementation and the affected areas for this change..Originally Posted by boxingfan529
Yeah... That's what I'm planning to do.. But first, I'll have to assess the implementation and the affected areas for this change..Originally Posted by boxingfan529
guys, i have this problem on searching strings!! can anyone help me about it!!
this problem wud search a data on a file...
dara and code ai....
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
public class SearchRecord extends JFrame implements ActionListener{
public static final int width = 300;
public static final int height = 250;
JTextField tfSearchItem;
JLabel displayItem;
JTextArea textArea;
public SearchRecord(){
JPanel North;
JPanel South;
setTitle("Search Record");
setSize(width,height);
Container contentPane = getContentPane();
contentPane.setLayout(new BorderLayout());
JLabel searchItem = new JLabel("Enter Record");
tfSearchItem = new JTextField(10);
JButton search = new JButton("Search");
search.addActionListener(this);
JButton clear = new JButton("Clear");
clear.addActionListener(this);
textArea = new JTextArea(5,23);
North = new JPanel();
North.setLayout(new FlowLayout());
North.add(searchItem);
North.add(tfSearchItem);
contentPane.add(North,BorderLayout.NORTH);
South = new JPanel();
South.setLayout(new FlowLayout());
South.add(search);
South.add(textArea);
contentPane.add(South,BorderLayout.CENTER);
}
public void actionPerformed(ActionEvent e){
String command = e.getActionCommand();
if("Search".equals(command)){
String line1 = null;
line1 = tfSearchItem.getText();
try{
BufferedReader inputStream = null;
inputStream = new BufferedReader(new FileReader("students.txt"));
String line = null;
while((line = inputStream.readLine()) != null){
if(line.equals(line1) == true){
textArea.setText(line);
}
else
textArea.setText("not Found!!");
}
}
catch(IOException exe){
//do something here.
}
}//if
if("Clear".equals(command)){
//do something here.
}
}//actionPerformed
public static void main(String[] args){
SearchRecord r = new SearchRecord();
r.setVisible(true);
}
}
mo type kag word sa textfield and then mo display siya sa textArea nga akong gibuhat diha!! unsa may class nga akong gamiton para maka search ko!! hope u will give me some advise! tanx....
Use the class Document and its derived classes like DefaultStyledDocument. Assign this in the JTextAre.setDocument() method. Check also the demo on Notepad.
ako na diayng na solve ako probs!!
ni gamit ra kog indexOf() nga method! unya gi sud nako siya sa while nga loop!! dali ra mn diay!! hehehehehe....
cool!
di diay apil ang seach and hightlight? kung simple lang, magamit ra nimo ang String nga class.
tanx kaayo boxinFan ni tagad jud ka sa kwe probs!! hehehehe
no problem...![]()
hey guys been following this thread .. im quite impress about the support you share.. I guess its about time to sticky this thread ..![]()
![]()
.
ALONE:Hated and Punished
heeyy!!! mga java programmer! unsa namn ayo nto??
daghan opening ron sa manila ug singapore even japan for j2ee developers for old timers.
for newbies, you can hone your skills sa NSP, Pejman, etc.![]()
Similar Threads |
|