qq_36707607
qq_36707607
2017-11-07 02:52

初学者新人求问,这段代码在eclipse上为何没报错却无法运行?

  • eclipse

package aaa;
import javax.swing.*;
import java.awt.event.*;
class p206 implements ActionListener,KeyListener,MouseListener{
JTextArea ta=new JTextArea(5,5);
p206(){
JFrame f=new JFrame("Listener");
JButton bme=new JButton("press me");
JButton byou=new JButton("press you");
bme.addActionListener(this);
bme.addMouseListener(this);
byou.addActionListener(this);
byou.addKeyListener(this);
f.add(ta);f.add(bme,"South");f.add(byou,"East");
f.setBounds(200,200,400,200);
f.setVisible(true);

}
public void actionPerformed(ActionEvent x){
    ta.setText(ta.getText()+"\n"+x.getActionCommand());
}
public void keyPressed(KeyEvent e){ta.setText(e.paramString());}
public void keyReleased(KeyEvent e){}
public void keyTyped(KeyEvent e){}
public void mousePressed(MouseEvent e){}
public void mouseReleased(MouseEvent e){}
public void mouseEntered(MouseEvent e){}
public void mouseExited(MouseEvent e){}
public void mouseClicked(MouseEvent e){
    ta.setText(ta.getText()+"\n"+e.getX()+","+e.getY());
}

public class test {

public static void main(String[] args) {
    // TODO Auto-generated method stub
    new p206();

}

}
}

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

5条回答