动作监听器不在mac os x中工作

时间:2017-06-30 15:16:21

标签: java macos swing netbeans graphics

我无法使用netbeans IDE和mac OSX编译actionlistener。我是初学者,请帮忙。它说不兼容的类型。我试图实现ActionListerner接口但没有运气。我不明白该怎么做。

package test1;

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

public class Test1 {
    public static void main(String[] args) {
        JFrame jf= new JFrame("xyz");
        JTextField jt= new JTextField("hello!!");
        jt.setBounds(200,200,50,90);
        JButton jb= new JButton("click");
        jb.setBounds(50,100,100,100);

        jf.add(jb);
        jf.add(jt);
        jf.setSize(400,500);
        jf.setLayout(null);
        jf.setVisible(true);

        //this line is not compiling and showing error

        jb.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    JOptionPane.showMessageDialog(null,"working");
                }
            });
    }

0 个答案:

没有答案