WOXUEIT 2019年05月08日
java运行问题 请大神指点
请大神指点一下 为什么运行不了啊?抱拳啦
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.*;

public class Example3 {

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

}
class MyFm extends JFrame implements ActionListener
{
JButton jb1,jb2;
Listener ls;
public MyFm()
{
jb1=new JButton("jb1");
jb2=new JButton("jb2");
ls=new Listener();

jb1.add(jb1);
jb2.add(jb2);


jb2.setActionCommand("jb2");
jb2.addActionListener(ls);
jb1.addActionListener(this);

this.setLayout(new FlowLayout());
this.add(jb1);
this.add(jb2);


this.addMouseListener(new Mouse());
this.setSize(300, 300);
this.setLocation(100, 100);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void paint(Graphics g)
{
super.paint(g);
g.drawLine(100, 100, 200, 300);
g.setColor(Color.black);
}

@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if(e.getSource()==jb1)
System.out.println("jb1");
}

}
class Mouse implements MouseListener
{
public void mouseClicked(MouseEvent e) {
// TODO Auto-generated method stub
System.out.println("clicked");
}

@Override
public void mousePressed(MouseEvent e) {
// TODO Auto-generated method stub
System.out.println("pressed");
}

@Override
public void mouseReleased(MouseEvent e) {
// TODO Auto-generated method stub
System.out.println("released");
}

@Override
public void mouseEntered(MouseEvent e) {
// TODO Auto-generated method stub
System.out.println("entered");
}

@Override
public void mouseExited(MouseEvent e) {
// TODO Auto-generated method stub
System.out.println("exited");
}


}

class Listener implements ActionListener
{

@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
String mess=e.getActionCommand();
if(mess=="jb2")
{
System.out.println("jb2");
}
}

}
...全文
25 1 收藏 2
写回复
2 条回复

还没有回复,快来抢沙发~

发动态
发帖子
Eclipse
创建于2007-09-28

3.1w+

社区成员

4.9w+

社区内容

Java Eclipse
社区公告
暂无公告