这是一个简单的窗体,但运行时不能显示内部窗体,并报空指针异常,这是怎么回事啊...求指教...
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class swing窗体
{ public static void main(String args[])
{ Mywindow win=new Mywindow();
win.validate();
}
}
class Mywindow extends JFrame
{ JButton button1,button2;
JTextArea text;
JScrollPane scroll;
JInternalFrame interframe;
JSplitPane splitOne,splitTwo;
Mywindow()
{ setSize(300,300);
setVisible(true);
Container con=getContentPane();
con.setLayout(new GridLayout(1,2));
button1=new JButton("button1");
button2=new JButton("button2");
text=new JTextArea(6,12);
scroll=new JScrollPane(text);
splitOne=new JSplitPane(JSplitPane.VERTICAL_SPLIT,true,button1,button2);
splitTwo=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,true,splitOne,scroll);
interframe.setSize(200,200);
interframe.setVisible(true);
Container interCon=interframe.getContentPane();
interCon.setLayout(new FlowLayout());
interCon.add(splitTwo);
JDesktopPane desk=new JDesktopPane();
desk.add(interframe);
getContentPane().add(desk);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class swing窗体
{ public static void main(String args[])
{ Mywindow win=new Mywindow();
win.validate();
}
}
class Mywindow extends JFrame
{ JButton button1,button2;
JTextArea text;
JScrollPane scroll;
JInternalFrame interframe;
JSplitPane splitOne,splitTwo;
Mywindow()
{ setSize(300,300);
setVisible(true);
Container con=getContentPane();
con.setLayout(new GridLayout(1,2));
button1=new JButton("button1");
button2=new JButton("button2");
text=new JTextArea(6,12);
scroll=new JScrollPane(text);
splitOne=new JSplitPane(JSplitPane.VERTICAL_SPLIT,true,button1,button2);
splitTwo=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,true,splitOne,scroll);
interframe.setSize(200,200);
interframe.setVisible(true);
Container interCon=interframe.getContentPane();
interCon.setLayout(new FlowLayout());
interCon.add(splitTwo);
JDesktopPane desk=new JDesktopPane();
desk.add(interframe);
getContentPane().add(desk);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
解决方案 »
- JTable的revalidate有什么用,附小源码。。。
- 如何让url重定向的文件被直接下载,而不被ie打开?
- 容器问题
- 看过在网上由shhgs翻译发布并流传的中文电子版java编程思想第三版的进来下
- 动态转换类问题,请高手指点!!!!!!!!!!!!!!!!
- 为什么子类不能用实例方法去重构父类的static?子类的static可以重构父类的static方法,但不能重构父类的实例方法?
- tomcat中关于multiple occurrences of language的问题
- 如何在java applet里读本地的文件(我是从delphi大富翁来得,听说这里也不错,事实怎么样?)
- 关于泛型反射的一个疑问
- 与socket = serverSocket.accept();同一个class下引用其他gui类总是显示白屏
- 请教一下读取大文本的好方法,要求省内存一点。。
- 一个关于java Socket 的问题。
Mywindow() {
setSize(300, 300);
setVisible(true);
Container con = getContentPane();
con.setLayout(new GridLayout(1, 2));
button1 = new JButton("button1");
button2 = new JButton("button2");
text = new JTextArea(6, 12);
scroll = new JScrollPane(text);
splitOne = new JSplitPane(JSplitPane.VERTICAL_SPLIT, true, button1,
button2);
splitTwo = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true, splitOne,
scroll);
interframe = new JInternalFrame("Remember to init"); 《======= 这里啊
interframe.setSize(200, 200);
interframe.setVisible(true);
Container interCon = interframe.getContentPane();
interCon.setLayout(new FlowLayout());
interCon.add(splitTwo);
JDesktopPane desk = new JDesktopPane();
desk.add(interframe);
getContentPane().add(desk);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
import java.awt.Container;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridLayout;import javax.swing.JButton;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTextArea;
public class swingFrame {
public static void main(String args[]) {
Mywindow win = new Mywindow();
win.validate();
}
}class Mywindow extends JFrame {
JButton button1, button2; JTextArea text; JScrollPane scroll; JInternalFrame interframe = new JInternalFrame();//没有初始化 对三楼无话可说了 JSplitPane splitOne, splitTwo; Mywindow() {
setSize(300, 300);
setVisible(true);
Container con = getContentPane();
con.setLayout(new GridLayout(1, 2));
button1 = new JButton("button1");
button2 = new JButton("button2");
text = new JTextArea(6, 12);
scroll = new JScrollPane(text);
splitOne = new JSplitPane(JSplitPane.VERTICAL_SPLIT, true, button1,
button2);
splitTwo = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true, splitOne,
scroll);
interframe.setSize(new Dimension(200, 200));
interframe.setVisible(true);
Container interCon = interframe.getContentPane();
interCon.setLayout(new FlowLayout());
interCon.add(splitTwo);
JDesktopPane desk = new JDesktopPane();
desk.add(interframe);
getContentPane().add(desk);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}