Results 1 to 3 of 3
Thread: how to connect with my GUI
- 04-01-2009, 05:14 PM #1
Member
- Join Date
- Mar 2009
- Posts
- 48
- Rep Power
- 0
how to connect with my GUI
i have GUI class named 'myGUI' where contains textField, button, textArea and so on....
the code like this:
Java Code: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);
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"); }
}
how can i do this ?? anybody can pls help me... i m very new in java
- 04-01-2009, 05:31 PM #2
Member
- Join Date
- Mar 2009
- Location
- Germany
- Posts
- 22
- Rep Power
- 0
The "problem" you have is that you are trying to mix a GUI with a console.
Reading your code looks like you have some experience in C or assembler? Don't get me wrong, but you should really think over your variable names (speaking of "c,m,b,.."), and programming style (assigning values within a method call ("p2.add(m=new TextField(10));") but if you're a starter and want to do better in the future, everything's fine :)
So, take that as an advice, now to your question:
Try to think of a seperation of GUI and logic: Strip all off the input/output stuff from your SearchCompare class and just feed it with your input.
In your GUI class, when the action from the SEARCH button arrives, create your second class and call that method, with all I/O stripped. This could be something like:
Java Code:SearchCompare = new SearchCompare(); String[] results = searchCompare.search(m.getText()); String displayText = ""; for(String result : results) { displayText += result + "\n"; } t.setText(displayText);
- 04-01-2009, 05:59 PM #3
Member
- Join Date
- Mar 2009
- Posts
- 48
- Rep Power
- 0
Similar Threads
-
JMF: Cannot connect to device
By jonsamwell in forum New To JavaReplies: 2Last Post: 06-10-2011, 08:20 PM -
Connect DB2 with struts
By anilonwebs in forum Web FrameworksReplies: 0Last Post: 11-22-2008, 08:24 AM -
how connect
By herfnai in forum JDBCReplies: 1Last Post: 08-18-2008, 07:34 AM -
connect two applet
By dg_iiita in forum Java AppletsReplies: 0Last Post: 02-15-2008, 02:59 PM -
connect to MSDE
By leonard in forum JDBCReplies: 1Last Post: 08-06-2007, 05:37 PM
Bookmarks