qq_36707607
2017-11-07 02:52
采纳率: 50%
浏览 960
已采纳

初学者新人求问,这段代码在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条回答 默认 最新

  • mango-mango 2017-11-07 07:48
    已采纳

    package aaa;

    import javax.swing.*;
    import java.awt.event.*;

    public class test {

    public static void main(String[] args) {
        new test().getP();
        System.out.println("hello java");
    }
    
    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 p206 getP(){
        return new p206();
    }
    

    }

    已采纳该答案
    评论
    解决 无用
    打赏 举报
  • 唐磊的糖 2017-11-07 03:44

    报什么错你也要贴出啦啊

    评论
    解决 无用
    打赏 举报
  • qq_36707607 2017-11-07 04:19

    没有提示报错,但是运行不了

    评论
    解决 无用
    打赏 举报
  • mango-mango 2017-11-07 06:49

    的哪个main方法 static 就已经报错了啊

    评论
    解决 无用
    打赏 举报
  • mango-mango 2017-11-07 07:48

    改了一下方式 但是可以运行

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题