Es geht um folgendes: Ich habe die exemplarische Internetadresse http://www.w3.org/Mark/Up/ .
Nun würde ich gern erfahren wie das Protokoll, File, Host und die URL ext. Form lauten.
Dies würde so aussehen:
Protokoll : http
File: /MarkUp/
Host: World Wide Web Consortium (W3C)
URL ext.Form: http://www.w3.org/Mark/Up/
Ich habe 2 Java Programme geschrieben.
Beim ersten erhalte ich alles bis auf Host wie gewünscht.Die Ausgabe erfolgt in der CMD.
Host:/Mark/Up
Programmcode vom 1sten:
Beim zweiten klapptdie Ausgabe perfekt.
Ich habe eine grafische Benutzeroberfläche programmiert bei der beim Anklicken des Info Buttons
die gewünschte Ausgabe in ein Textfeld erfolgt.
Programmcode vom 2ten:[Java]import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.net.*;
public class RateGUIApp extends Frame
implements ActionListener, WindowListener {
Label labSuche1,labSuche2, labSuche3;
Label labText1, labText2;
TextField tfVersuch1, tfVersuch2, tfVersuch3;
Button bInfo, bNeu, bVersuch;
TextArea taInfo;
Rate spiel;
Font fntFett, fntHead, fntAusgabe;
private String strVersuch1="";
private String strVersuch2="";
private String strVersuch3="";
int ergebnis;
int anzahl;
public RateGUIApp() {
setLayout(null);
setSize(400,400);
addWindowListener(this);
spiel=new Rate();
fntFett= new Font("SansSerif",1,14);
fntHead= new Font("SansSerif",1,20);
fntAusgabe= new Font("Monospaced",0,12);
labText1=new Label("Raten Sie die 3 Ziffern");
labText1.setFont(fntHead);
labText1.setBounds(20,25,350,25);
add(labText1);
labText2=new Label("Loesungen");
labText2.setFont(fntFett);
labText2.setBounds(20,70,120,25);
add(labText2);
labSuche1=new Label("x");
labSuche1.setFont(fntHead);
labSuche1.setBounds(175,70,25,25);
add(labSuche1);
labSuche2=new Label("x");
labSuche2.setFont(fntHead);
labSuche2.setBounds(255,70,25,25);
add(labSuche2);
labSuche3=new Label("x");
labSuche3.setFont(fntHead);
labSuche3.setBounds(335,70,25,25);
add(labSuche3);
tfVersuch1 =new TextField("");
tfVersuch1.setFont(fntFett);
tfVersuch1.setBounds(170,110,25,25);
add(tfVersuch1);
tfVersuch2 =new TextField("");
tfVersuch2.setFont(fntFett);
tfVersuch2.setBounds(250,110,25,25);
add(tfVersuch2);
tfVersuch3 =new TextField("");
tfVersuch3.setFont(fntFett);
tfVersuch3.setBounds(330,110,25,25);
add(tfVersuch3);
bInfo=new Button("Info");
bInfo.setFont(fntFett);
bInfo.setBounds(20,160,80,25);
bInfo.addActionListener(this);
add(bInfo);
bNeu =new Button("Neues Spiel");
bNeu.setFont(fntFett);
bNeu.setBounds(140,160,100,25);
bNeu.addActionListener(this);
add(bNeu);
bVersuch = new Button("Versuch");
bVersuch.setFont(fntFett);
bVersuch.setBounds(280,160,100,25);
bVersuch.addActionListener(this);
add(bVersuch);
taInfo = new TextArea();
taInfo.setFont(fntAusgabe);
taInfo.setBounds(20,210,360,140);
add(taInfo);
setVisible(true);
spiel.zufallsWerte();
}
public static void main(String[] args) {
RateGUIApp rate = new RateGUIApp();
}
public void actionPerformed(ActionEvent e) {
if (e.getSource()==bVersuch) {
versuchClicked();
}
if (e.getSource()==bNeu) {
neuClicked();
}
if (e.getSource()==bInfo) {
infoClicked();
}
}
public void windowClosing (WindowEvent e) {
dispose();
System.exit(0);
}
public void windowClosed(WindowEvent e){}
public void windowOpened(WindowEvent e) {}
public void windowActivated (WindowEvent e) {}
public void windowDeactivated(WindowEvent e){}
public void windowIconified(WindowEvent e) {}
public void windowDeiconified(WindowEvent e){}
private void neuClicked () {
//taInfo.append("\"" + "Neues Spiel\"" + "geklickt" + "\n");
anzahl=0;
tfVersuch1.setVisible(true);
tfVersuch2.setVisible(true);
tfVersuch3.setVisible(true);
tfVersuch1.setText("");
tfVersuch2.setText("");
tfVersuch3.setText("");
labSuche1.setText("x");
labSuche2.setText("x");
labSuche3.setText("x");
}
private void versuchClicked() {
//taInfo.append("\""+ "Versuchen" + "\"" + "gecklickt" + "\"");
anzahl++;
boolean ok = false;
strVersuch1=tfVersuch1.getText();
strVersuch2=tfVersuch2.getText();
strVersuch3=tfVersuch3.getText();
ok=spiel.ueberpruefe(strVersuch1, strVersuch2, strVersuch3);
if(ok) {
ergebnis=spiel.werteAus();
if((ergebnis & 4)==4) {
labSuche1.setText(strVersuch1);
tfVersuch1.setVisible(false);
taInfo.append("1.Feld geraten"+"\n");
}
if((ergebnis & 2)==2) {
labSuche2.setText(strVersuch2);
tfVersuch2.setVisible(false);
taInfo.append("2. Feld geraten" + "\n");
}
if((ergebnis & 1)==1) {
labSuche3.setText(strVersuch3);
tfVersuch3.setVisible(false);
taInfo.append("3. Feld geraten\n");
}
if(ergebnis==7) {
taInfo.append("Nach" + anzahl + "Versuchen fertig"+"\n");
//statistik(anzahl);
}
else taInfo.append("Bitte noch einmal probieren"+"\n");
}
}
private void infoClicked() {
// taInfo.append("Info gecklickt\n");
try {
URL url = new URL( "http://www.w3.org/MarkUp/");
taInfo.append("Protokoll: " + url.getProtocol()+"\n");
taInfo.append("File: " + url.getFile()+"\n");
taInfo.append("Host: " + url.getHost()+"\n");
taInfo.append("URL ext.Form:" +url.toExternalForm()+"\n");
} catch(MalformedURLException ex)
{taInfo.append("Fehler in der URL");
}
}
/*private void statistik(int anzahl) {
String filename ="Raten.txt";
File file = new File(filename);
FileOutputStream fos;
DataOutputStream dos;
try {
fos = new FileOutputStream(file);
dos = new DataOutputStream(fos);
dos.writeBytes("Anzahl der Versuche: ");
dos.writeBytes(Integer.toString(anzahl));
dos.flush();
dos.close();
taInfo.append("\n" + "Zahl der Versuche in Datei" + "\n" + "\""+filename+"\""+"geschrieben" + "\n" + "\n");
} catch (IOException ioe) {
taInfo.append("Fehler beim Schreiben des Files" + "\n");
taInfo.append(ioe.getMessage());
}
}*/
}
[/code]
Das ist der Teil des Codes der Interessiert:
Ich kann den Unterschied nicht erkennen.
Woran liegt das ?
Falls Ihr das 2te Programm zum laufen bringen wollt, benötigt ihr Rate.java, dass ich bei Nachfrage reinstellen .
Da ich viel geschrieben habe<<Danke im Voraus>> an alle mutigen Leser.:rtfm:
Nun würde ich gern erfahren wie das Protokoll, File, Host und die URL ext. Form lauten.
Dies würde so aussehen:
Protokoll : http
File: /MarkUp/
Host: World Wide Web Consortium (W3C)
URL ext.Form: http://www.w3.org/Mark/Up/
Ich habe 2 Java Programme geschrieben.
Beim ersten erhalte ich alles bis auf Host wie gewünscht.Die Ausgabe erfolgt in der CMD.
Host:/Mark/Up
Programmcode vom 1sten:
Java:
import java.net.*;
import java.awt.*;
public class URLAusgabe extends Frame{
public static void main(String[] args) {
try {// a,b,c,d sind Variablen in denen ich den String speichere
URL url = new URL("ftp://java.sun.com/as/");
String a = url.getProtocol();
System.out.println("Protokoll :" + a+ "\n");
String b = url.getFile();
System.out.println("File :" + b + "\n");
String c = url.getHost();
System.out.println("Host :"+b+"\n");
String d = url.toExternalForm();
System.out.println("URL ext. For:" +d+"\n");
} catch (MalformedURLException ex) {
System.out.println("Fehler in der URL");
}
}
}
Beim zweiten klapptdie Ausgabe perfekt.
Ich habe eine grafische Benutzeroberfläche programmiert bei der beim Anklicken des Info Buttons
die gewünschte Ausgabe in ein Textfeld erfolgt.
Programmcode vom 2ten:[Java]import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.net.*;
public class RateGUIApp extends Frame
implements ActionListener, WindowListener {
Label labSuche1,labSuche2, labSuche3;
Label labText1, labText2;
TextField tfVersuch1, tfVersuch2, tfVersuch3;
Button bInfo, bNeu, bVersuch;
TextArea taInfo;
Rate spiel;
Font fntFett, fntHead, fntAusgabe;
private String strVersuch1="";
private String strVersuch2="";
private String strVersuch3="";
int ergebnis;
int anzahl;
public RateGUIApp() {
setLayout(null);
setSize(400,400);
addWindowListener(this);
spiel=new Rate();
fntFett= new Font("SansSerif",1,14);
fntHead= new Font("SansSerif",1,20);
fntAusgabe= new Font("Monospaced",0,12);
labText1=new Label("Raten Sie die 3 Ziffern");
labText1.setFont(fntHead);
labText1.setBounds(20,25,350,25);
add(labText1);
labText2=new Label("Loesungen");
labText2.setFont(fntFett);
labText2.setBounds(20,70,120,25);
add(labText2);
labSuche1=new Label("x");
labSuche1.setFont(fntHead);
labSuche1.setBounds(175,70,25,25);
add(labSuche1);
labSuche2=new Label("x");
labSuche2.setFont(fntHead);
labSuche2.setBounds(255,70,25,25);
add(labSuche2);
labSuche3=new Label("x");
labSuche3.setFont(fntHead);
labSuche3.setBounds(335,70,25,25);
add(labSuche3);
tfVersuch1 =new TextField("");
tfVersuch1.setFont(fntFett);
tfVersuch1.setBounds(170,110,25,25);
add(tfVersuch1);
tfVersuch2 =new TextField("");
tfVersuch2.setFont(fntFett);
tfVersuch2.setBounds(250,110,25,25);
add(tfVersuch2);
tfVersuch3 =new TextField("");
tfVersuch3.setFont(fntFett);
tfVersuch3.setBounds(330,110,25,25);
add(tfVersuch3);
bInfo=new Button("Info");
bInfo.setFont(fntFett);
bInfo.setBounds(20,160,80,25);
bInfo.addActionListener(this);
add(bInfo);
bNeu =new Button("Neues Spiel");
bNeu.setFont(fntFett);
bNeu.setBounds(140,160,100,25);
bNeu.addActionListener(this);
add(bNeu);
bVersuch = new Button("Versuch");
bVersuch.setFont(fntFett);
bVersuch.setBounds(280,160,100,25);
bVersuch.addActionListener(this);
add(bVersuch);
taInfo = new TextArea();
taInfo.setFont(fntAusgabe);
taInfo.setBounds(20,210,360,140);
add(taInfo);
setVisible(true);
spiel.zufallsWerte();
}
public static void main(String[] args) {
RateGUIApp rate = new RateGUIApp();
}
public void actionPerformed(ActionEvent e) {
if (e.getSource()==bVersuch) {
versuchClicked();
}
if (e.getSource()==bNeu) {
neuClicked();
}
if (e.getSource()==bInfo) {
infoClicked();
}
}
public void windowClosing (WindowEvent e) {
dispose();
System.exit(0);
}
public void windowClosed(WindowEvent e){}
public void windowOpened(WindowEvent e) {}
public void windowActivated (WindowEvent e) {}
public void windowDeactivated(WindowEvent e){}
public void windowIconified(WindowEvent e) {}
public void windowDeiconified(WindowEvent e){}
private void neuClicked () {
//taInfo.append("\"" + "Neues Spiel\"" + "geklickt" + "\n");
anzahl=0;
tfVersuch1.setVisible(true);
tfVersuch2.setVisible(true);
tfVersuch3.setVisible(true);
tfVersuch1.setText("");
tfVersuch2.setText("");
tfVersuch3.setText("");
labSuche1.setText("x");
labSuche2.setText("x");
labSuche3.setText("x");
}
private void versuchClicked() {
//taInfo.append("\""+ "Versuchen" + "\"" + "gecklickt" + "\"");
anzahl++;
boolean ok = false;
strVersuch1=tfVersuch1.getText();
strVersuch2=tfVersuch2.getText();
strVersuch3=tfVersuch3.getText();
ok=spiel.ueberpruefe(strVersuch1, strVersuch2, strVersuch3);
if(ok) {
ergebnis=spiel.werteAus();
if((ergebnis & 4)==4) {
labSuche1.setText(strVersuch1);
tfVersuch1.setVisible(false);
taInfo.append("1.Feld geraten"+"\n");
}
if((ergebnis & 2)==2) {
labSuche2.setText(strVersuch2);
tfVersuch2.setVisible(false);
taInfo.append("2. Feld geraten" + "\n");
}
if((ergebnis & 1)==1) {
labSuche3.setText(strVersuch3);
tfVersuch3.setVisible(false);
taInfo.append("3. Feld geraten\n");
}
if(ergebnis==7) {
taInfo.append("Nach" + anzahl + "Versuchen fertig"+"\n");
//statistik(anzahl);
}
else taInfo.append("Bitte noch einmal probieren"+"\n");
}
}
private void infoClicked() {
// taInfo.append("Info gecklickt\n");
try {
URL url = new URL( "http://www.w3.org/MarkUp/");
taInfo.append("Protokoll: " + url.getProtocol()+"\n");
taInfo.append("File: " + url.getFile()+"\n");
taInfo.append("Host: " + url.getHost()+"\n");
taInfo.append("URL ext.Form:" +url.toExternalForm()+"\n");
} catch(MalformedURLException ex)
{taInfo.append("Fehler in der URL");
}
}
/*private void statistik(int anzahl) {
String filename ="Raten.txt";
File file = new File(filename);
FileOutputStream fos;
DataOutputStream dos;
try {
fos = new FileOutputStream(file);
dos = new DataOutputStream(fos);
dos.writeBytes("Anzahl der Versuche: ");
dos.writeBytes(Integer.toString(anzahl));
dos.flush();
dos.close();
taInfo.append("\n" + "Zahl der Versuche in Datei" + "\n" + "\""+filename+"\""+"geschrieben" + "\n" + "\n");
} catch (IOException ioe) {
taInfo.append("Fehler beim Schreiben des Files" + "\n");
taInfo.append(ioe.getMessage());
}
}*/
}
[/code]
Das ist der Teil des Codes der Interessiert:
Java:
private void infoClicked() {
// taInfo.append("Info gecklickt\n");
try {
URL url = new URL( "http://www.w3.org/MarkUp/");
taInfo.append("Protokoll: " + url.getProtocol()+"\n");
taInfo.append("File: " + url.getFile()+"\n");
taInfo.append("Host: " + url.getHost()+"\n");
taInfo.append("URL ext.Form:" +url.toExternalForm()+"\n");
} catch(MalformedURLException ex)
{taInfo.append("Fehler in der URL");
}
Ich kann den Unterschied nicht erkennen.
Woran liegt das ?
Falls Ihr das 2te Programm zum laufen bringen wollt, benötigt ihr Rate.java, dass ich bei Nachfrage reinstellen .
Da ich viel geschrieben habe<<Danke im Voraus>> an alle mutigen Leser.:rtfm: