Hallo Leute!
Ich möchte bei meinen 2 Klassen gerne das outputTextField der Klasse RS_GUI in der Klasse RS_URLCON setzten. Wie macht man soetwas? Ich habs schon mit einem Objekt Probiert jedoch öffnet sich die GUI dann zweimal auch mit einer abgeleiteten Klasse funktioniert es nicht.
Hier Meine Klassen
Ich möchte bei meinen 2 Klassen gerne das outputTextField der Klasse RS_GUI in der Klasse RS_URLCON setzten. Wie macht man soetwas? Ich habs schon mit einem Objekt Probiert jedoch öffnet sich die GUI dann zweimal auch mit einer abgeleiteten Klasse funktioniert es nicht.
Hier Meine Klassen
Java:
import java.net.*;
import java.io.*;
/*
* [url=http://forums.sun.com/thread.jspa?threadID=500360]Java Technologies for Web Services - HTTP 407 - Proxy Authentication Required[/url]
*
*/
public class RS_URLCON extends RS_GUI {
boolean proxySet = false;
public String inputLine;
URL url;
public void openURL(String URLName) throws IOException {
// Configure proxy ...
// System.setProperty("http.proxySet", "true");
// System.setProperty("http.proxyHost", "10.24.17.18");
// System.setProperty("http.proxyPort", "8082");
String proxyUser = "lmiglbau", proxyPassword = "";
// Open URL ...
url = new URL("http://" + URLName);
URLConnection con = url.openConnection();
// proxy user and pass
/*
* con.setRequestProperty("Proxy-Authorization", "Basic " + new
* sun.misc.BASE64Encoder() .encode((proxyUser + ":" +
* proxyPassword).getBytes()));
*/
// Read it ...
// OutputStream os = new FileOutputStream("H:/output.html");
BufferedReader in = new BufferedReader(new InputStreamReader(con
.getInputStream()));
while ((inputLine = in.readLine()) != null) {
this.outputTxtField.setText("" + inputLine);
}
}
public void openSite() {
}
public static void main(String[] args) throws Exception {
}
}
Java:
/**
*
*/
import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.UIManager;
import javax.swing.filechooser.FileNameExtensionFilter;
/**
* @author Tom
*/
public class RS_GUI extends JFrame implements ActionListener {
JPanel readin = new JPanel();
JPanel parameters = new JPanel();
JButton openURL = new JButton("Öffnen");
JButton readSITE = new JButton("Suchen");
JButton saveof = new JButton("Speichern");
JTextField inputSearch = new JTextField();
JTextField inputURL = new JTextField();
JTextField outputTxtField = new JTextField();
JCheckBox check = new JCheckBox("Proxy On/Off");
JFileChooser fc = new JFileChooser();
RS_URLCON uc = new RS_URLCON();
public RS_GUI() {
super("NimbusLookAndFeelExample");
setLayout(new BorderLayout());
readin.setLayout(new GridLayout(2, 2)); // Panel für Suchen und URL
parameters.setLayout(new GridLayout(1, 2));
setVisible(true);
setSize(400, 400);
}
public void setGUI() {
add(readin, BorderLayout.NORTH);
add(parameters, BorderLayout.SOUTH);
add(outputTxtField, BorderLayout.CENTER);
saveof.addActionListener(this);
readSITE.addActionListener(this);
readin.add(openURL);
readin.add(inputURL);
readin.add(readSITE);
readin.add(inputSearch);
parameters.add(check);
parameters.add(saveof);
openURL.addActionListener(this);
}
public void setTXT(String setText) {
}
public void actionPerformed(ActionEvent arg0) {
if (arg0.getSource() == saveof) {
FileNameExtensionFilter filter = new FileNameExtensionFilter(
"MP3 file", "mp3");
fc.addChoosableFileFilter(filter);
int returnVal = fc.showOpenDialog(null);
if (returnVal == JFileChooser.APPROVE_OPTION) {
String filename = fc.getSelectedFile().getPath();
}
}
if (arg0.getSource() == openURL) {
String URLName = inputURL.getText();
try {
uc.openURL(URLName);
uc.openSite();
outputTxtField.setText("" + uc.inputLine);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
public static void main(String[] args) throws Exception {
UIManager
.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
RS_GUI rs = new RS_GUI();
rs.setGUI();
}
}