如何添加键盘监听器 我做了一个聊天室系统,我想将输入的地方有JText改为JTextArea,同时添加一个快捷键,如同QQ的ctrl + Enter,请问该监听器该怎么写呢,举个例子好吗? 谢谢了 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 ActionListener,增加捕获键盘就可以了。 KeyListener是不是只能够监听一个键盘事件 package com.bmt.oops.ui.gis.tools.maptoolbar.nodeseclet;import java.awt.Dimension;import java.awt.FlowLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.JButton;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JTextField;import twaver.Element;import twaver.gis.GeographyMap;import twaver.gis.TWaverGisConst;import twaver.gis.utils.GeoCoordinate;import twaver.network.TNetwork;import com.bmt.oops.ui.components.MainFrame;import com.bmt.oops.ui.gis.datalayer.GisFactory;import com.bmt.oops.ui.util.SectorFindThread;public class NodeSecletPanel extends JPanel{ //private AutoCompletionField txt; private static JTextField txt; private static TNetwork mTNetwork; public NodeSecletPanel(final TNetwork mTNetwork,final GeographyMap map){ txt = new JTextField(); this.mTNetwork = mTNetwork; this.setLayout(new FlowLayout(FlowLayout.LEFT)); JButton btnSelect = new JButton("按小区ID查找"); txt.setPreferredSize(new Dimension(100,22)); this.add(txt); this.add(btnSelect); btnSelect.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { if("".equals(txt.getText().trim())){ return; } Element element = mTNetwork.getDataBox().getElementByName(txt.getText()); if(element==null){ JOptionPane.showMessageDialog(MainFrame.getInstance(),"未搜索到目标网元。","提示",JOptionPane.INFORMATION_MESSAGE); return; } new SectorFindThread(element).start(); GeoCoordinate geo = (GeoCoordinate) element.getClientProperty(TWaverGisConst.GEOCOORDINATE); double lon = geo.getLongitude(); double lan = geo.getLatitude(); GisFactory.winXY[0] = lon-0.005; GisFactory.winXY[1] = lan-0.0046; GisFactory.winXY[2] = lon+0.005; GisFactory.winXY[3] = lan+0.0046; map.setWindow(GisFactory.winXY[0], GisFactory.winXY[1], GisFactory.winXY[2], GisFactory.winXY[3]);//控制显示比例 }}); }// private static JLabel label = new JLabel("默认为空");// class TextAction implements ActionListener{// public void actionPerformed(ActionEvent e){// NodeSecletPanel.label.setText(NodeSecletPanel.txt.getText());// }// }} isReachable方法的基础问题 学了这么久Java编程,头一回特么地用它干了件正事~~ 求算法 打印菱形三角 请问怎样 按顺序 把JTextField 的内容输入到 JList ! *****初学者的问题,java多线程通信的问题****** 关于taglib的问题 如何将STRING "2003-11-01 11:12:23" 转为系统时间long。急急~! score 菜鸟之问:一个关于继承的程序...... 请问解析一个XML文件的时候,如何获得结点的属性信息? java判断邮件格式是否正确? java怎样实现视频播放
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;import twaver.Element;
import twaver.gis.GeographyMap;
import twaver.gis.TWaverGisConst;
import twaver.gis.utils.GeoCoordinate;
import twaver.network.TNetwork;import com.bmt.oops.ui.components.MainFrame;
import com.bmt.oops.ui.gis.datalayer.GisFactory;
import com.bmt.oops.ui.util.SectorFindThread;public class NodeSecletPanel extends JPanel{
//private AutoCompletionField txt;
private static JTextField txt;
private static TNetwork mTNetwork;
public NodeSecletPanel(final TNetwork mTNetwork,final GeographyMap map){
txt = new JTextField();
this.mTNetwork = mTNetwork; this.setLayout(new FlowLayout(FlowLayout.LEFT));
JButton btnSelect = new JButton("按小区ID查找");
txt.setPreferredSize(new Dimension(100,22));
this.add(txt);
this.add(btnSelect);
btnSelect.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
if("".equals(txt.getText().trim())){
return;
}
Element element = mTNetwork.getDataBox().getElementByName(txt.getText());
if(element==null){
JOptionPane.showMessageDialog(MainFrame.getInstance(),"未搜索到目标网元。","提示",JOptionPane.INFORMATION_MESSAGE);
return;
}
new SectorFindThread(element).start();
GeoCoordinate geo = (GeoCoordinate) element.getClientProperty(TWaverGisConst.GEOCOORDINATE);
double lon = geo.getLongitude();
double lan = geo.getLatitude();
GisFactory.winXY[0] = lon-0.005;
GisFactory.winXY[1] = lan-0.0046;
GisFactory.winXY[2] = lon+0.005;
GisFactory.winXY[3] = lan+0.0046;
map.setWindow(GisFactory.winXY[0], GisFactory.winXY[1], GisFactory.winXY[2], GisFactory.winXY[3]);//控制显示比例
}});
}
// private static JLabel label = new JLabel("默认为空");
// class TextAction implements ActionListener{
// public void actionPerformed(ActionEvent e){
// NodeSecletPanel.label.setText(NodeSecletPanel.txt.getText());
// }
// }
}