为了账号安全,请及时绑定邮箱和手机立即绑定

Java的ActionListenr总是安装不成功无法正常运行

Java的ActionListenr总是安装不成功无法正常运行

慕先生7453236 2017-05-20 23:59:18
用cmd运行,给出提示“Exception in thread "main"java.lang.NullPointerException”。为什么安装的监听器老是不成功呢?import java.awt.*;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.*;public class task3 extends JFrame implements ActionListener{     private static JFrame frame;     private static JPanel panel1;//下方     private static JPanel panel2;//图片     JLabel tips;//用户正误提示处     JButton check;//     JTextField answer;//输入答案     int newNum = 10;//初始图片数量     public task3()     {         this.setTitle("Welcom to Jungle Party");         this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);         this.setLayout(new BorderLayout());         this.getContentPane().add(panel1,BorderLayout.SOUTH);              this.setBounds(120,120,1200,600);         panel1 = new JPanel();         panel1.setLayout(new BoxLayout(panel1,BoxLayout.Y_AXIS));         answer = new JTextField(10);         tips = new JLabel("Hello");         check = new JButton("check");         panel1.add(tips);         panel1.add(answer);         panel1.add(check);         simpleListener ourListener = new simpleListener();        check.addActionListener(ourListener);         this.setVisible(true);     } private class simpleListener implements ActionListener {     public void actionPerformed(ActionEvent e)     {         String buttonName = e.getActionCommand();         if(buttonName.equals("check"));         {                 tips.setText("hahaha successful");         }     } } public static void main(String[] args) { task3 abc = new task3(); }}
查看完整描述

目前暂无任何回答

  • 0 回答
  • 0 关注
  • 1474 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信