I trying to solve a this problem from 3 days and its difficult and I can't find how to solve it. I tried to compare two dimension array from another class to ActionListener class with JtextField that the user input in search box then view the result in a JTable. Any one can help and I am thankful for that.
the class how contain the array
public class SerachClassic extends JFrame{
String[]columnNames2 = { "Car Name", "Color", "Miles", "Year Model"," Prise"};
String [][]info2 = {{"Ford","Black","1000","1923","34000$"},
{"Ford Mustang","red","1300","1969","58500$"},
{"Dodge","Sliver","6000","1972","38000$"},
{"Chevrolet Corvette","red & Whiat","500","1960","89000$"},
{"Buick Electra","blu","2000","1969","24000$"},
{"Pontiac Bonneville","blu","700","1963","26900$"},
{"Lincoln Continental","Black","1500","1964","79000$"},
{"Cadillac Fleetwood","Black","1200","1959","90000$"},
{"Ford Thunderbird","Sliver","500","1957","75000$"}};
public String[] getColumnNames2() {
return columnNames2;
}
public String[][] getInfo2() {
return info2;
}
}
this the class that create a search box
static class Action1 implements ActionListener{
@Override
public void actionPerformed(ActionEvent e){
SwingUtilities.invokeLater(new Runnable() { //using this method to update UI
@Override
public void run() {
TextFile textFile = new TextFile();// create a new object to write somthing
}
});
}
}
public static class TextFile{
JFrame ftext = new JFrame();
JPanel panel = new JPanel();
JTextField text = new JTextField("",30);
JButton button = new JButton("Serach");
public TextFile(){
text.addFocusListener(new FocusListener(){
@Override
public void focusGained(FocusEvent arg0){
text.setText("");
}
@Override
public void focusLost(FocusEvent arg0){
text.setText("Please enter something");
}
});
panel.add(text);
panel.add(button);
ftext.add(panel);
ftext.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
ftext.pack();
ftext.setVisible(true);
}
}
I tried here to do somthing by compare the JTextfile from the search box with string but its not working
static class Action8 implements ActionListener{
@Override
public void actionPerformed(ActionEvent e) {
SerachClassic findt = new SerachClassic();
TextFile find1 = new TextFile();
String fromUser = find1.text.getText();
if(Arrays.asList(findt.info2).contains(fromUser)){
JFrame searchType = new JFrame("Car Type");
JPanel panel = new JPanel();
searchType.setVisible(true);
searchType.setSize(400, 200);
JTable table = new JTable();
panel.add(table);
searchType.add(panel);