java鼠标事件的问题
publicclasssishibaextendsJApplet{JTreetree;JTextFieldjtf;publicvoidinit(){Containercp...
public class sishiba extends JApplet {
JTree tree; JTextField jtf;
public void init(){Container cp=getContentPane();
cp.setLayout(new BorderLayout());
DefaultMutableTreeNode top =new DefaultMutableTreeNode("TOP");
DefaultMutableTreeNode a =new DefaultMutableTreeNode("A");
DefaultMutableTreeNode a1 =new DefaultMutableTreeNode("A1");
a.add(a1);DefaultMutableTreeNode a2 =new DefaultMutableTreeNode("A2");
a.add(a2);DefaultMutableTreeNode a3 =new DefaultMutableTreeNode("A3");
a.add(a3);DefaultMutableTreeNode b =new DefaultMutableTreeNode("B");
DefaultMutableTreeNode b1 =new DefaultMutableTreeNode("B1");
b.add(b1);DefaultMutableTreeNode b2 =new DefaultMutableTreeNode("B2");
b.add(b2);DefaultMutableTreeNode b3= new DefaultMutableTreeNode("B3");
b.add(b3); top.add(a);top.add(b);
tree =new JTree(top);
int v= ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;
int h =ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;
JScrollPane jsp =new JScrollPane(tree,v,h);
cp.add(jsp,BorderLayout.CENTER);jtf =new JTextField(20);
cp.add(jsp,BorderLayout.SOUTH);
tree.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent me){doMouseClicked(me);}});}
void doMouseClicked(MouseEvent me){
TreePath tp =tree.getPathForLocation(me.getX(), me.getY());
if(tp!=null)jtf.setText(tp.toString());elsejtf.setText(""); } 鼠标事件的me.getX(),me.getY()报错,为什么? 展开
JTree tree; JTextField jtf;
public void init(){Container cp=getContentPane();
cp.setLayout(new BorderLayout());
DefaultMutableTreeNode top =new DefaultMutableTreeNode("TOP");
DefaultMutableTreeNode a =new DefaultMutableTreeNode("A");
DefaultMutableTreeNode a1 =new DefaultMutableTreeNode("A1");
a.add(a1);DefaultMutableTreeNode a2 =new DefaultMutableTreeNode("A2");
a.add(a2);DefaultMutableTreeNode a3 =new DefaultMutableTreeNode("A3");
a.add(a3);DefaultMutableTreeNode b =new DefaultMutableTreeNode("B");
DefaultMutableTreeNode b1 =new DefaultMutableTreeNode("B1");
b.add(b1);DefaultMutableTreeNode b2 =new DefaultMutableTreeNode("B2");
b.add(b2);DefaultMutableTreeNode b3= new DefaultMutableTreeNode("B3");
b.add(b3); top.add(a);top.add(b);
tree =new JTree(top);
int v= ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;
int h =ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;
JScrollPane jsp =new JScrollPane(tree,v,h);
cp.add(jsp,BorderLayout.CENTER);jtf =new JTextField(20);
cp.add(jsp,BorderLayout.SOUTH);
tree.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent me){doMouseClicked(me);}});}
void doMouseClicked(MouseEvent me){
TreePath tp =tree.getPathForLocation(me.getX(), me.getY());
if(tp!=null)jtf.setText(tp.toString());elsejtf.setText(""); } 鼠标事件的me.getX(),me.getY()报错,为什么? 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询