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

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();
}

}

报什么错你也要贴出啦啊

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

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

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

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐