我想要得到一個URL
從TextField
exapmle:http://www.google.com
,我有一個WebView
,它將通過單擊「回車鍵」可見,但問題是當我運行應用程序它沒有顯示任何東西請注意,我用FXML File
。這是我的代碼已經traied:如何在單擊按鈕時設置網頁?與JavaFX
@FXML
private void onpressed (ActionEvent ee) {
text1.setOnKeyPressed(new EventHandler<KeyEvent>() {
public void handle(KeyEvent evt) {
if (evt.getCode() == KeyCode.ENTER){
String az = text1.getText();
//c.1
if(text1.getText().equals("1")){
web1.setVisible(true);
String hh = text11.getText();
Socket socket = new Socket();
try {
//open cursor
text1.setCursor(Cursor.WAIT);
que.setCursor(Cursor.WAIT);
writ.setCursor(Cursor.WAIT);
ancpa.setCursor(Cursor.WAIT);
web1.setCursor(Cursor.WAIT);
web2.setCursor(Cursor.WAIT);
web3.setCursor(Cursor.WAIT);
web4.setCursor(Cursor.WAIT);
web5.setCursor(Cursor.WAIT);
web6.setCursor(Cursor.WAIT);
web7.setCursor(Cursor.WAIT);
web8.setCursor(Cursor.WAIT);
web9.setCursor(Cursor.WAIT);
//do work
WebEngine myWebEngine = web1.getEngine();
myWebEngine.load("http://www.google.com");
//close the window chooser
Stage stage = new Stage();
Parent root = FXMLLoader.load(getClass().getResource("Choose.fxml"));
Scene scene = new Scene(root);
stage.setOnCloseRequest(new EventHandler<WindowEvent>() {
@Override public void handle(WindowEvent t) { } });
//close cursor
ancpa.setCursor(Cursor.DEFAULT);
web1.setCursor(Cursor.DEFAULT);
web2.setCursor(Cursor.DEFAULT);
web3.setCursor(Cursor.DEFAULT);
web4.setCursor(Cursor.DEFAULT);
web5.setCursor(Cursor.DEFAULT);
web6.setCursor(Cursor.DEFAULT);
web7.setCursor(Cursor.DEFAULT);
web8.setCursor(Cursor.DEFAULT);
web9.setCursor(Cursor.DEFAULT);
}
catch (IOException e){
final Stage stg = new Stage();
stg.initModality(Modality.APPLICATION_MODAL);
stg.initOwner(stg);
stg.setTitle("Cannot connect to the internet /n Please Verify your connection internet");
labelno.setText("Cannot connect to the internet...");
//close chooser
Stage stage = new Stage();
stage.setOnCloseRequest(new EventHandler<WindowEvent>() {
@Override public void handle(WindowEvent t) { } });
//set cursor
ancpa.setCursor(Cursor.DEFAULT);
web1.setCursor(Cursor.DEFAULT);
web2.setCursor(Cursor.DEFAULT);
web3.setCursor(Cursor.DEFAULT);
web4.setCursor(Cursor.DEFAULT);
web5.setCursor(Cursor.DEFAULT);
web6.setCursor(Cursor.DEFAULT);
web7.setCursor(Cursor.DEFAULT);
web8.setCursor(Cursor.DEFAULT);
web9.setCursor(Cursor.DEFAULT);
} finally{
try{ socket.close(); } catch (Exception e){ }
}
}
}
}
});
}
所以,請能爲我身體的任何地方解釋是這個代碼的問題,我會很感激:)
編輯您的問題包括[MCVE](http://stackoverflow.com /幫幫我/ mcve) - 確保它既小巧又可執行,以便在有人運行時複製問題。 – jewelsea 2015-01-20 21:37:09
我也注意到,你所有的問題都沒有被接受的答案,所以如果你對答案感到滿意,那麼有人已經在右下角發表了投票上下箭頭點擊選中標記以接受答案 – sazzy4o 2015-01-21 00:54:09
@APro我回答了你的問題問題到你的喜好? – sazzy4o 2015-01-21 15:28:19