[求助]怎么没有输出?
import javax.swing.JOptionPane;public class Pic1 {
public static void main(String args[])
{
JOptionPane.showInternalMessageDialog(null, "* * * * * * * * \n * * * * * * * *\n" +
"* * * * * * * * \n * * * * * * * *\n" +
"* * * * * * * * \n * * * * * * * *\n" +
"* * * * * * * * \n * * * * * * * *\n","result", JOptionPane.PLAIN_MESSAGE);
}
}
报了这样的错误:
Exception in thread "main" java.lang.RuntimeException: JOptionPane: parentComponent does not have a valid parent
at javax.swing.JOptionPane.createInternalFrame(Unknown Source)
at javax.swing.JOptionPane.showInternalOptionDialog(Unknown Source)
at javax.swing.JOptionPane.showInternalMessageDialog(Unknown Source)
at javax.swing.JOptionPane.showInternalMessageDialog(Unknown Source)
at Pic1.main(Pic1.java:6)
图形输不出来
----------------解决方案--------------------------------------------------------
没有高手来解决吗`?
----------------解决方案--------------------------------------------------------
少导了一个包.import.java.awt.*;
----------------解决方案--------------------------------------------------------
还是一样的不行啊` `
----------------解决方案--------------------------------------------------------
不用那个包的,我不用JOpionPane的就能输出了,觉得好奇怪 ,也不知道是什么错误?
----------------解决方案--------------------------------------------------------
以下是引用yushui在2006-10-12 13:20:57的发言:
import javax.swing.JOptionPane;
public class Pic1 {
public static void main(String args[])
{
JOptionPane.showInternalMessageDialog(null, "* * * * * * * * \n * * * * * * * *\n" +
"* * * * * * * * \n * * * * * * * *\n" +
"* * * * * * * * \n * * * * * * * *\n" +
"* * * * * * * * \n * * * * * * * *\n","result", JOptionPane.PLAIN_MESSAGE);
}
}
报了这样的错误:
Exception in thread "main" java.lang.RuntimeException: JOptionPane: parentComponent does not have a valid parent
at javax.swing.JOptionPane.createInternalFrame(Unknown Source)
at javax.swing.JOptionPane.showInternalOptionDialog(Unknown Source)
at javax.swing.JOptionPane.showInternalMessageDialog(Unknown Source)
at javax.swing.JOptionPane.showInternalMessageDialog(Unknown Source)
at Pic1.main(Pic1.java:6)
图形输不出来
import javax.swing.JOptionPane;
public class Pic1 {
public static void main(String args[])
{
JOptionPane.showInternalMessageDialog(null, "* * * * * * * * \n * * * * * * * *\n" +
"* * * * * * * * \n * * * * * * * *\n" +
"* * * * * * * * \n * * * * * * * *\n" +
"* * * * * * * * \n * * * * * * * *\n","result", JOptionPane.PLAIN_MESSAGE);
}
}
报了这样的错误:
Exception in thread "main" java.lang.RuntimeException: JOptionPane: parentComponent does not have a valid parent
at javax.swing.JOptionPane.createInternalFrame(Unknown Source)
at javax.swing.JOptionPane.showInternalOptionDialog(Unknown Source)
at javax.swing.JOptionPane.showInternalMessageDialog(Unknown Source)
at javax.swing.JOptionPane.showInternalMessageDialog(Unknown Source)
at Pic1.main(Pic1.java:6)
图形输不出来
你这样当然会错了,你JOptionPane.showInternalMessageDialog,这显示的是一个内部消息窗口,它的父窗口引用不能为null的
你要显示消息,推荐 用
JOptionPane.showMessageDialog()就可以了,这样第一个参数可以为null了,
----------------解决方案--------------------------------------------------------
API上是这么说的:parentComponent - 确定在其中显示对话框的 Frame;如果为 null 或者 parentComponent 不具有 Frame,则使用默认的 Frame,可以为null啊!
----------------解决方案--------------------------------------------------------
呵呵 ,谢谢千里斑竹的,就是那个问题
----------------解决方案--------------------------------------------------------