JAVA awt eventqueue_线程“AWT-EventQueue-1”中的异常java.lang.NullPointerException

嗨,我收到错误

Exception in thread "AWT-EventQueue-1" java.lang.NullPointerException

at P6.itemStateChanged(P6.java:215)

at javax.swing.AbstractButton.fireItemStateChanged(AbstractButton.java:2

023)

at javax.swing.AbstractButton$Handler.itemStateChanged(AbstractButton.ja

va:2325)

at javax.swing.DefaultButtonModel.fireItemStateChanged(DefaultButtonMode

l.java:440)

at javax.swing.JToggleButton$ToggleButtonModel.setSelected(JToggleButton

.java:255)

at javax.swing.ButtonGroup.setSelected(ButtonGroup.java:147)

at javax.swing.JToggleButton$ToggleButtonModel.setSelected(JToggleButton

.java:237)

at javax.swing.JToggleButton$ToggleButtonModel.setPressed(JToggleButton.

java:272)

at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonL

istener.java:236)

at java.awt.Component.processMouseEvent(Component.java:6267)

at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)

at java.awt.Component.processEvent(Component.java:6032)

at java.awt.Container.processEvent(Container.java:2041)

at java.awt.Component.dispatchEventImpl(Component.java:4630)

at java.awt.Container.dispatchEventImpl(Container.java:2099)

at java.awt.Component.dispatchEvent(Component.java:4460)

at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4577

)

at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)

at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)

at java.awt.Container.dispatchEventImpl(Container.java:2085)

at java.awt.Component.dispatchEvent(Component.java:4460)

at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)

at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThre

ad.java:269)

at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.

java:184)

at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre

ad.java:174)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)

at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)在

import java.awt.Color;

import java.awt.Container;

import java.awt.FlowLayout;

import java.awt.Font;

import java.awt.Graphics;

import java.awt.event.ItemEvent;

import java.awt.event.ItemListener;

import java.awt.event.MouseEvent;

import java.awt.event.MouseListener;

import java.awt.event.MouseMotionListener;

import javax.swing.ButtonGroup;

import javax.swing.JApplet;

import javax.swing.JComboBox;

import javax.swing.JRadioButton;

public class P6 extends JApplet implements MouseListener, MouseMotionListener, ItemListener

{

private final int RED = 1;

private final int ORANGE = 2;

private final int YELLOW = 3;

private final int GREEN = 4;

private final int BLUE = 5;

private final int CYAN = 6;

private final int PINK = 7;

private final int MAGENTA =8;

private final int BLACK = 9;

private final int ARC = 1;

private final int LINE = 2;

private final int OVAL = 3;

private final int RECT = 4;

private final int POLY = 5;

private String[] colorNames = { "Red", "Orange", "Yellow", "Green", "Blue",

"Cyan", "Pink", "Magenta", "Black"};

private JComboBox colorComboBox;

private JRadioButton jrbArc;

private JRadioButton jrbLine;

private JRadioButton jrbOval;

private JRadioButton jrbRect;

private JRadioButton jrbPolygon;

private int color = 0;

private int shape = 0;

private int x1;

private int y1;

private int x2;

private int y2;

public void init()

{

Container c = getContentPane();

c.setLayout( new FlowLayout() );

c.setBackground( Color.orange );

JComboBox colorComboBox = new JComboBox(colorNames);

colorComboBox.addItemListener(this);

JRadioButton jrbArc = new JRadioButton("Arc");

jrbArc.addItemListener(this);

JRadioButton jrbLine = new JRadioButton("Line");

jrbLine.addItemListener(this);

JRadioButton jrbOval = new JRadioButton("Oval");

jrbOval.addItemListener(this);

JRadioButton jrbRect = new JRadioButton("Rectangle");

jrbRect.addItemListener(this);

JRadioButton jrbPolygon = new JRadioButton("Polygon");

jrbPolygon.addItemListener(this);

ButtonGroup btg = new ButtonGroup();

btg.add(jrbArc);

c.add(jrbArc);

btg.add(jrbLine);

c.add(jrbLine);

btg.add(jrbOval);

c.add(jrbOval);

btg.add(jrbRect);

c.add(jrbRect);

btg.add(jrbPolygon);

c.add(jrbPolygon);

c.add(colorComboBox);

addMouseMotionListener(this);

addMouseListener(this);

}

public void paint(Graphics g)

{

super.paint(g);

g.setColor(Color.white);

g.fillRect(20, 50, 500, 500);

g.setFont( new Font("Serif", Font.ITALIC+Font.BOLD, 18));

g.setColor(Color.black);

g.drawString("Start Here!", 10, 50);

g.drawString("End Here!", 510, 560);

switch (this.color)

{

case 1:

g.setColor(Color.red);

break;

case 2:

g.setColor(Color.orange);

break;

case 3:

g.setColor(Color.yellow);

break;

case 4:

g.setColor(Color.green);

break;

case 5:

g.setColor(Color.blue);

break;

case 6:

g.setColor(Color.cyan);

break;

case 7:

g.setColor(Color.pink);

break;

case 8:

g.setColor(Color.magenta);

break;

case 9:

g.setColor(Color.black);

break;

}

switch (shape)

{

case 1:

g.fillArc(this.x1, this.y1, this.x2 - this.x1, this.y2 - this.y1, 0, 90);

g.fillArc(this.x1, this.y1, this.x2 - this.x1, this.y2 - this.y1, 180,90);

break;

case 2:

g.drawLine(this.x1, this.y1, this.x2, this.y2);

break;

case 3:

g.fillOval(this.x1, this.y1, this.x2 - this.x1, this.y2 - this.y1);

break;

case 4:

g.fillRect(this.x1, this.y1, this.x2 - this.x1, this.y2 - this.y1);

break;

case 5:

int[] arr1 = { this.x1, this.x2, this.x1, this.x2, this.x1};

int[] arr2 = { this.y1, this.y1, this.y2 ,this.y2, this.y1};

g.fillPolygon(arr1, arr2, 5);

break;

}

}

public void mousePressed( MouseEvent e)

{

this.x1 = e.getX();

this.y1 = e.getY();

}

public void mouseDragged( MouseEvent e)

{

this.x2 = e.getX();

this.y2 = e.getY();

}

public void mouseReleased( MouseEvent e)

{

this.x2 = e.getX();

this.y2 = e.getY();

}

public void mouseClicked( MouseEvent e)

{

}

public void mouseEntered( MouseEvent e)

{

}

public void mouseExited( MouseEvent e)

{

}

public void mouseMoved( MouseEvent e)

{

showStatus( " (" + e.getX() + ", " + e.getY() +")");

}

public void itemStateChanged(ItemEvent i)

{

if(this.jrbArc.isSelected())

this.shape = ARC;

else if( this.jrbLine.isSelected())

this.shape = LINE;

else if( this.jrbOval.isSelected())

this.shape = OVAL;

else if( this.jrbRect.isSelected())

this.shape = RECT;

else if( this.jrbPolygon.isSelected())

this.shape = POLY;

this.color = ( this.colorComboBox.getSelectedIndex() + 1 );

repaint();

}

}我一直在想这个,但没有运气。

请帮忙吗?

215行是:

if(this.jrbArc.isSelected())

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/529377.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

java构造方法赋值内存图_java 面向对象(九):类的结构:构造器(一)简介;属性赋值顺序;JavaBean的概念...

1.构造器(或构造方法):Constructor构造器的作用:* 1.创建对象* 2.初始化对象的信息2.使用说明:* 1.如果没显式的定义类的构造器的话,则系统默认提供一个空参的构造器* 2.定义构造器的格式:权限修饰符 类名(形参列表){}…

java 集合modcount_源码|jdk源码之LinkedList与modCount字段

链表是对上一篇博文所说的顺序表的一种实现。与ArrayList思路截然不同,链表的实现思路是:不同元素实际上是存储在离散的内存空间中的。每一个元素都有一个指针指向下一个元素,这样整个离散的空间就被“串”成了一个有顺序的表。从链表的概念来…

idea 新建ssm java ee_IDEA搭建SSM项目实现增删改查

首先打开IDEA,File—>New—>Project创建项目选择左侧导航栏里的Maven,勾上勾,选择webapp按如下图进行填写创建完成后进入项目,右下角弹出的提示点击右边的Enable Auto-Import,自动配置连接数据库,我用…

php mail centos_centos怎么发送邮件

一、安装sendmail与mail1、安装sendmail:1) centos下可以安装命令:yum -y install sendmail2) 安装完后启动sendmail命令:service sendmail start2、安装mail安装命令:yum install -y mailx二、发送邮件1、通过文件内容发送发送命…

php文件的作用,php入口文件的作用-PHP问题

php入口文件的作用php入口文件能够完成主动加载性能。解析PHP入口文件的主动加载性能php的主动加载:正在php5之前,咱们要用某个类或类的办法,那必需include或许require,之后能力应用,每一次用一个类,都需求…

emacs php 配置文件,如何配置emacs进行正确的PHP开发?

我使用web模式(http://web-mode.org/)混合HTML / PHP文件和php模式为纯PHP文件.最新版本的php-mode还推荐使用混合HTML / PHP文件的Web模式:https://github.com/ejmr/php-mode#avoid-html-template-compatibility.不同于其他模式,如mmm模式,mumamo或多网络模式,尝试…

php 5.3.9 漏洞,PHP-5.3.9远程执行任意代码漏洞(CVE-2012-0830) 详解

这个新的修复方法初衷是好的, 但是却带来一个严重的问题(5.3.10中已经修复), 这个问题最初是由Stefan Esser发现的. 请看之前(5.3.9)最终的修复方案(php_register_variable_ex):代码如下while (1) {if (zend_symtable_find(symtable1, escaped_index, index_len 1, (void **) …

java中随机数边界问题,java 简单Dice问题(随机数的运用)

[java]代码库/*** Dice Write a program that simulates rolling two dice using the following* steps: 1. Prompt the user for the number of sides for two dice. 2. “Roll” the* dice three times by generating a random number between 1 (inclusive) and the* number…

php 正则替换 ubb,php实现过滤UBB代码的类

本文实例讲述了php实现过滤UBB代码的类。分享给大家供大家参考。具体如下:PHP代码如下:class Day{function ubb($Text) { /// UBB代码转换//$Texthtmlspecialchars($Text);//$Textereg_replace("\r\n","",$Text);$Textereg_rep…

java单词测试,java单词 - 在线打字测试(dazi.kukuw.com)

java单词贡献者:15533470608类别:英文 时间:2018-08-04 22:32:16 收藏数:20 评分:0返回上页举报此文章请选择举报理由:广告/谣言/欺诈政治敏感色情/违法信息垃圾文章其他收藏到我的文章改错字public static…

java vector list,Java基础之:List——ArrayList Vector

Java基础之:List——ArrayList & VectorArrayList简单介绍ArrayList实现了List接口,底层是一个数组,并实现了可变的功能。底层属性(transient Object[] elementData;)在序列化时,忽略该属性。ArrayList实现了List接口&#xf…

java建立线性表的链式结构,数据结构学习----线性表的链式表示(Java实现)

线性表接口LList:package com.clarck.datastructure.linked;/*** 线性表接口LList,描述线性表抽象数据类型,泛型参数T表示数据元素的数据类型** author clarck**/public interface LList {/*** 判断线性表是否空* return*/boolean isEmpty();…

php prepare 批量,PreparedStatement批处理

PreparedStatement批量更新关键代码 无 import java.sql.Connection;import java.sql.PreparedStatement; //...String sql "insert into employee (name, city, phone) values (?, ?, ?)";Connection connection new getConnection();PreparedStatement pPrepa…

钉钉 php 推送,微信模板推送,钉钉信息推送

上午的时候看到有朋友需要微信推送,正好我也需要,之前一直用 Server 酱的,但是最近用不了,想找一个替代品,一开始准备选择钉钉,除了打卡,我很少使用钉钉,邮件提醒是备用方案&#xf…

java repaint 重画图形,学习笔记:WINDOWS的图形重绘基础

OnPaint()与OnDraw()的区别:OnPaint是WM_PAINT的消息响应函数,在MFC的基类里OnPaint函数调用了OnDraw()函数。OnPaint函数另外还调用了OnPrepareDC()函数。如果在窗口子类覆盖了OnPaint函数,当MFC调用我们重写的OnPaint函数时,就调…

php定义数据表类,phpwind中的数据库操作类

phpwind中的数据库操作类2021-01-22 20:12:15141/*来源:phpwind.net*/ClassDB{var$query_num0;functionDB($dbhost,$dbuser,$dbpw,$dbname,$pconnect0){$this->connect($dbhost,$dbuser,$dbpw,$dbname,$pconnect);}functionconnect($dbhost,$dbuser,$dbpw,$dbnam…

涡轮机叶片matlab强度分析论文,一种基于MATLAB及Pro_E的涡轮建模方法

自动化与控制与二一种基于MATLAB及Pro/E的涡轮建模方法王智明(中海油服油田技术事业部北京1011&am…

基于matlab的传热学虚拟实验开发,基于MATLAB的传热学课程虚拟实验软件的开发

215教育现代化2018 年 12 月第 49 期 教育信息技术 基于 MATLAB 的传热学课程虚拟实验软件的开发 周永利,李友荣,石万元,张力元,杨晨,卞煜,王国强,李俊,包键 ( 重庆大学 低品位能源利…

java做 binggo,Linux启动与停止spring boot工程的脚本示例

在springboot项目启动有三种方式:1、运行主方法程序2、使用命令mvn spring-boot:run 在命令行运行3、使用 mvn packpage打包位jar文件以后,使用java -jar yourapp.jar命令行运行一般我们在开发的时候经常使用的是前面两种运行方式,在部署实施…

php计划任务 框架,计划任务的使用 ThinkCMF内容管理框架,做最简约的ThinkPHP开源软件...

1、先不管是是否是独立分组,必须在Application\common\项目名下的Conf文件夹内创建2个文件一个是tags.php(项目默认有,直接加入需要执行的代码即可) 一个是 crons.php。注意这两个文件名为thinkphp标准文件名,不可以改变tages.php内容是&…