我目前遇到的问题是我要创建一个简单的网络浏览器,并希望编写每个访问过的网页的网址。无论如何,当历史记录组合框被URL填充时,.addItem函数正在触发我的动作监听器。有没有办法解决这个问题?
Action Listener:
historyList.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent event){
final String url= historyList.getSelectedItem().toString();
addressbar.setText(url); //set the address bar to the url
historyArray[historynum] = url; //add the url to the array which contains the history
historynum = historynum + 1; //move one up the history array
Display(url); //display the url
backplace = 1; //reset the amount of backs a user can take
forwardBtn = false; //not allow the user to go forward again
}
}
);
}
将配置文件中的URL添加到组合:
for (String linehistory : Files.readAllLines(Paths.get("config.history"),Charset.defaultCharset())) {
if (!(linehistory ==null)){
for (String partHistory : linehistory.split("\\s+")) {
String historylines = partHistory;
if( i >6){
if (!(partHistory ==null)){
historyList.addItem(partHistory);
}
}
i = i +1;
}
}
我注意到了这一点,我认为可能是由于组合框的状态发生了变化,有没有办法将其更改为onClick? http://imgur.com/aTg9n2E