Results 1 to 3 of 3
  1. #1
    doha786 is offline Member
    Join Date
    Mar 2009
    Posts
    48
    Rep Power
    0

    Question 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);
    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

  2. #2
    MasterD is offline Member
    Join Date
    Mar 2009
    Location
    Germany
    Posts
    22
    Rep Power
    0

    Default

    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);
    (This code is not compiler tested ;))

  3. #3
    doha786 is offline Member
    Join Date
    Mar 2009
    Posts
    48
    Rep Power
    0

    Default thanks

    thanks for ur compliments....

    right now i m starter and trying to improve my skill.
    i m trying ur code now and let u know the output..

    thanks again.

Similar Threads

  1. JMF: Cannot connect to device
    By jonsamwell in forum New To Java
    Replies: 2
    Last Post: 06-10-2011, 08:20 PM
  2. Connect DB2 with struts
    By anilonwebs in forum Web Frameworks
    Replies: 0
    Last Post: 11-22-2008, 08:24 AM
  3. how connect
    By herfnai in forum JDBC
    Replies: 1
    Last Post: 08-18-2008, 07:34 AM
  4. connect two applet
    By dg_iiita in forum Java Applets
    Replies: 0
    Last Post: 02-15-2008, 02:59 PM
  5. connect to MSDE
    By leonard in forum JDBC
    Replies: 1
    Last Post: 08-06-2007, 05:37 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •