我這個程式主要是一個基本的瀏覽器
問題就在於我在url輸入的地方 我在這個JTextField有新增一個KeyListener
如果按了enter 理當應該進去 可是實際我在輸入完網址按enter卻一點反應也沒有
就算我改成其他的按鍵也一樣@@
而我的jbutton則是加了一個Actionlistener 裡面做的也是一樣的事
不過這個button按下去就有反應
我在一些地方爬了文 好像是focus的問題
所以嘗試加了下面第二行和第三行 嘗試把focus移到這個物件
可是還是不行:(
以下是部分code.....
是我加錯了位置嗎?? 我還是搞不太懂requestFocus到底應該要加在什麼位置才好
而且另外好像還有什麼requestFocusInWindow的 ~"~ 看說明都搞不太懂差別...
還是說 不是這個的問題啊? orz
locationTextField = new JTextField(35);
locationTextField.setFocusable(true);
locationTextField.requestFocus();
locationTextField.addKeyListener(new KeyAdapter()
{
public void KeyPressed(KeyEvent e)
{
if(e.getKeyCode() == KeyEvent.VK_ENTER) // 如果輸入是enter的話
{
actionGo();
}
}
});
buttonPanel.add(locationTextField);
JButton goButton = new JButton("GO");
goButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
actionGo();
}
});
buttonPanel.add(goButton);
以下是我這個瀏覽器的code
http://rafb.net/p/kir7lg27.html
= =a 剛剛po錯板了...
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 218.171.137.3