i have GUI class named 'myGUI' where contains textField, button, textArea and so on....

the code like this:

p2.add(c=new Label("Type name to search:")); 
p2.add(m=new TextField(10));
p2.add(b=new Button ("SEARCH"));	b.addActionListener(this);
p.add(k= new Label("CLICK SEARCH TO START ACTION")
p1.add(t=new TextArea(""), BorderLayout.CENTER);

i have another class file named 'searchCompare' where user able to key in to find a string and see the results with similarity score and path.
the code like this :

Scanner scanner = new Scanner(System.in);
  String SearchClass;
System.out.print("Enter namt to Search : ");
SearchClass = scanner.next();
  for (String found: names) {
  double compare = ReadFilesAndCompare.LCS(found, SearchClass);
  	if (compare !=null) {
	System.out.println("Found names : "+found+ "  Similarity score: " +compare+ "File Name: "+found.toString());  }
 	else {System.out.println("No search result found"); }
	}

individualy both r working correctly... but now want to connect this 'searchComare' class with 'myGui' class where user will input search name in textFiled and press start button to search and get results in the textArea.

how can i do this ?? anybody can pls help me... i m very new in java

Recommended Answers

All 2 Replies

This can be accomplished the same way you would "connect" two classes that are not GUI classes. You have to make sure your GUI class implements ActionListener though. ActionListener has one method, actionPerformed(ActionEvent e), so implement that method and put the code to get the search term from the text field using the getText method, then use the search class in your actionPerformed method.

This can be accomplished the same way you would "connect" two classes that are not GUI classes. You have to make sure your GUI class implements ActionListener though. ActionListener has one method, actionPerformed(ActionEvent e), so implement that method and put the code to get the search term from the text field using the getText method, then use the search class in your actionPerformed method.

thanks for ur compliments.
i already add this method and trying to get the output.
i m going to post this code shortly where i stucked..............

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.