主题:[原创]帮我看看我这个代码什么地方错了
package dilog;
import java.awt.*;
import javax.swing.*;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class DilogFrame
extends JFrame {
JPanel contentPane;
JButton jButton1 = new JButton();
JLabel jLabel1 = new JLabel();
JLabel jLabel2 = new JLabel();
public DilogFrame() {
try {
setDefaultCloseOperation(EXIT_ON_CLOSE);
jbInit();
}
catch (Exception exception) {
exception.printStackTrace();
}
}
/**
* Component initialization.
*
* @throws java.lang.Exception
*/
private void jbInit() throws Exception {
contentPane = (JPanel) getContentPane();
contentPane.setLayout(null);
setSize(new Dimension(400, 300));
setTitle("选择对话框");
jButton1.setBounds(new Rectangle(95, 40, 108, 34));
jButton1.setText("显示对话框");
jButton1.addActionListener(new DilogFrame_jButton1_actionAdapter(this));
jLabel1.setText("选定的国家");
jLabel1.setBounds(new Rectangle(21, 101, 67, 30));
jLabel2.setText("");
jLabel2.setBounds(new Rectangle(106, 101, 129, 30));
contentPane.add(jButton1);
contentPane.add(jLabel1);
contentPane.add(jLabel2);
}
public void jButton1_actionPerformed(ActionEvent e) {
JOptionPane jOptionPane1=new JOptionPane();
Object[] possibleValues = { "中国", "印度", "澳大利亚" };
Object o=JOptionPane.showInputDialog(this,"国家(地区)","选定的国家(地区)",
JOptionPane.INFORMATION_MESSAGE,null,possibleValues,possibleValues[0]);
[color=FF0000]if(o.equals("中国"))
{
jLabel2.setText("中国");
}
if(o.equals("印度"))
{
jLabel2.setText("印度");
}
if(o.equals("澳大利亚"))
{
jLabel2.setText("澳大利亚");
}[/color]
}
}
class DilogFrame_jButton1_actionAdapter
implements ActionListener {
private DilogFrame adaptee;
DilogFrame_jButton1_actionAdapter(DilogFrame adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton1_actionPerformed(e);
}
}
如果没有红的部分运行对话框时点撤销可以正常退出但是加上之后就会出现异常
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
哪里错了 谢谢大家
import java.awt.*;
import javax.swing.*;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class DilogFrame
extends JFrame {
JPanel contentPane;
JButton jButton1 = new JButton();
JLabel jLabel1 = new JLabel();
JLabel jLabel2 = new JLabel();
public DilogFrame() {
try {
setDefaultCloseOperation(EXIT_ON_CLOSE);
jbInit();
}
catch (Exception exception) {
exception.printStackTrace();
}
}
/**
* Component initialization.
*
* @throws java.lang.Exception
*/
private void jbInit() throws Exception {
contentPane = (JPanel) getContentPane();
contentPane.setLayout(null);
setSize(new Dimension(400, 300));
setTitle("选择对话框");
jButton1.setBounds(new Rectangle(95, 40, 108, 34));
jButton1.setText("显示对话框");
jButton1.addActionListener(new DilogFrame_jButton1_actionAdapter(this));
jLabel1.setText("选定的国家");
jLabel1.setBounds(new Rectangle(21, 101, 67, 30));
jLabel2.setText("");
jLabel2.setBounds(new Rectangle(106, 101, 129, 30));
contentPane.add(jButton1);
contentPane.add(jLabel1);
contentPane.add(jLabel2);
}
public void jButton1_actionPerformed(ActionEvent e) {
JOptionPane jOptionPane1=new JOptionPane();
Object[] possibleValues = { "中国", "印度", "澳大利亚" };
Object o=JOptionPane.showInputDialog(this,"国家(地区)","选定的国家(地区)",
JOptionPane.INFORMATION_MESSAGE,null,possibleValues,possibleValues[0]);
[color=FF0000]if(o.equals("中国"))
{
jLabel2.setText("中国");
}
if(o.equals("印度"))
{
jLabel2.setText("印度");
}
if(o.equals("澳大利亚"))
{
jLabel2.setText("澳大利亚");
}[/color]
}
}
class DilogFrame_jButton1_actionAdapter
implements ActionListener {
private DilogFrame adaptee;
DilogFrame_jButton1_actionAdapter(DilogFrame adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton1_actionPerformed(e);
}
}
如果没有红的部分运行对话框时点撤销可以正常退出但是加上之后就会出现异常
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
哪里错了 谢谢大家