GUI + Seitenquelltext => Textfield

Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

  • GUI + Seitenquelltext => Textfield

    Hallo,

    um mal eins klarzustellen ich bin eher auf der PHP/CSS/HTML-Ebene und nicht JAVA ;)

    Ich fang jetzt aber an ein bisschen zu üben, denn ich werde das auf meiner nächsten Schule brauchen.

    Mein vorhaben ist es den Vorgang zu verstehen.

    Und zwar hole ich mir damit den Seitenquelltext (falls es kürzer geht dann bitte erklären).

    Quellcode

    1. //------------------------------------------------------------//
    2. // JavaGetUrl.java: //
    3. //------------------------------------------------------------//
    4. // A Java program that demonstrates a procedure that can be //
    5. // used to download the contents of a specified URL. //
    6. //------------------------------------------------------------//
    7. // Code created by Developer's Daily //
    8. // http://www.DevDaily.com //
    9. //------------------------------------------------------------//
    10. import java.io.*;
    11. import java.net.*;
    12. public class JavaGetUrl {
    13. public static void main (String[] args) {
    14. //-----------------------------------------------------//
    15. // Step 1: Start creating a few objects we'll need.
    16. //-----------------------------------------------------//
    17. URL u;
    18. InputStream is = null;
    19. DataInputStream dis;
    20. String s;
    21. try {
    22. //------------------------------------------------------------//
    23. // Step 2: Create the URL. //
    24. //------------------------------------------------------------//
    25. // Note: Put your real URL here, or better yet, read it as a //
    26. // command-line arg, or read it from a file. //
    27. //------------------------------------------------------------//
    28. u = new URL("http://200.210.220.1:8080/index.html");
    29. //----------------------------------------------//
    30. // Step 3: Open an input stream from the url. //
    31. //----------------------------------------------//
    32. is = u.openStream(); // throws an IOException
    33. //-------------------------------------------------------------//
    34. // Step 4: //
    35. //-------------------------------------------------------------//
    36. // Convert the InputStream to a buffered DataInputStream. //
    37. // Buffering the stream makes the reading faster; the //
    38. // readLine() method of the DataInputStream makes the reading //
    39. // easier. //
    40. //-------------------------------------------------------------//
    41. dis = new DataInputStream(new BufferedInputStream(is));
    42. //------------------------------------------------------------//
    43. // Step 5: //
    44. //------------------------------------------------------------//
    45. // Now just read each record of the input stream, and print //
    46. // it out. Note that it's assumed that this problem is run //
    47. // from a command-line, not from an application or applet. //
    48. //------------------------------------------------------------//
    49. while ((s = dis.readLine()) != null) {
    50. System.out.println(s);
    51. }
    52. } catch (MalformedURLException mue) {
    53. System.out.println("Ouch - a MalformedURLException happened.");
    54. mue.printStackTrace();
    55. System.exit(1);
    56. } catch (IOException ioe) {
    57. System.out.println("Oops- an IOException happened.");
    58. ioe.printStackTrace();
    59. System.exit(1);
    60. } finally {
    61. //---------------------------------//
    62. // Step 6: Close the InputStream //
    63. //---------------------------------//
    64. try {
    65. is.close();
    66. } catch (IOException ioe) {
    67. // just going to ignore this one
    68. }
    69. } // end of 'finally' clause
    70. } // end of main
    71. } // end of class definition
    Alles anzeigen



    Und das wäre das GUI.

    Quellcode

    1. import java.awt.*;
    2. import java.awt.event.*;
    3. public class class_test extends Frame
    4. {
    5. public class_test ()
    6. {
    7. // Fenster
    8. setTitle("Beispiel");
    9. addWindowListener(new TestWindowListener());
    10. setLayout(new BorderLayout()); // BorderLayout setzen
    11. setSize(300,150);
    12. setVisible(true);
    13. // Fenster
    14. // Elemente
    15. add(new TextField("Blubb"));
    16. // Elemente
    17. }
    18. class TestWindowListener extends WindowAdapter
    19. {
    20. public void windowClosing(WindowEvent e)
    21. {
    22. e.getWindow().dispose();
    23. System.exit(0);
    24. }
    25. }
    26. public static void main (String args[])
    27. {
    28. new class_test ();
    29. }
    30. }
    Alles anzeigen




    Meine Wunschvorstellung wäre die beiden Sachen zu kombinieren.
    Und zwar => Seitenquelltext soll in dem TextField angezeigt werden.
  • Naja, aber irgendwie musst du deiner GUI ja im Endeffekt einen String geben. Ans system.print landet eben nur auf STDOUT - in dem Fall der Textkonsole ;)
    Was jedoch performanter als das String konkatenieren ist ein StringBuffer.

    Kannst ja mal in diesen Thread reinschauen: Java Streams: Dateioperationen
    War eine alte Studienaufgabe von mir.