【发布时间】:2015-01-20 21:30:41
【问题描述】:
我正在尝试从TextField 获取URL 示例:http://www.google.com 并且我有一个WebView,通过单击“Enter 键”可以看到它,但问题是当我运行应用程序它没有显示任何内容请注意我正在使用FXML File。这是我的代码:
@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 - 确保它既是最小的又是可执行的,以便在有人运行它时复制问题。
-
我还注意到您的所有问题都没有被接受的答案,所以如果您对有人在投票上下箭头右下方发布的答案感到满意,请单击复选标记以接受答案
-
@APro 我是否按照您的喜好回答了您的问题?
-
@sazzy4o 现在我正在尝试您的代码,如果问题解决了,我会提出“接受这个问题”,但无论如何感谢您的帮助:)
-
@APro 如果它不起作用,请发布错误并尝试修复它