如何做一个主窗体和子窗体?
解决方案 »
- 怎么用批处理导入csv文件到sqlite中
- 子类已经覆盖了父类的静态方法,应该运行子类的静态方法才对呀?
- 关于数据类型的问题
- 请教:设计通用的ActionForm
- 老问题,最小化到托盘!
- JDK 6 javac编译的时候出现Note: Recompile with -Xlint:deprecation for details.
- java运行异常!急!
- 三个(java基础)问题
- 请教JDBC连MYSQL的问题?THANKS
- 哪儿有swing包的详细说明手册,要有关于每个控件的方法和属性的详细说明,并请告诉我下载地址?
- 请问怎么判断JTextField为空啊??
- 堆的内存和栈的内存游什么不同???
see:
http://java.sun.com/docs/books/tutorial/uiswing/components/internalframe.html
import javax.swing.JDesktopPane;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JMenuBar;
import javax.swing.JFrame;import java.awt.event.*;
import java.awt.*;public class InternalFrameDemo extends JFrame {
JDesktopPane desktop; public InternalFrameDemo() {
super("InternalFrameDemo"); //Make the big window be indented 50 pixels from each edge
//of the screen.
int inset = 50;
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
setBounds(inset, inset,
screenSize.width - inset*2,
screenSize.height-inset*2); //Quit this app when the big window closes.
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
}); //Set up the GUI.
desktop = new JDesktopPane(); //a specialized layered pane
createFrame(); //Create first window
setContentPane(desktop);
setJMenuBar(createMenuBar()); //Make dragging faster:
desktop.putClientProperty("JDesktopPane.dragMode", "outline");
} protected JMenuBar createMenuBar() {
JMenuBar menuBar = new JMenuBar(); JMenu menu = new JMenu("Document");
menu.setMnemonic(KeyEvent.VK_D);
JMenuItem menuItem = new JMenuItem("New");
menuItem.setMnemonic(KeyEvent.VK_N);
menuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
createFrame();
}
});
menu.add(menuItem);
menuBar.add(menu); return menuBar;
} protected void createFrame() {
MyInternalFrame frame = new MyInternalFrame();
frame.setVisible(true); //necessary as of 1.3; OK to use before
desktop.add(frame);
try {
frame.setSelected(true);
} catch (java.beans.PropertyVetoException e) {}
} public static void main(String[] args) {
InternalFrameDemo frame = new InternalFrameDemo();
frame.setVisible(true);
}
}//MyInternalFrame.javaimport javax.swing.JInternalFrame;import java.awt.event.*;
import java.awt.*;public class MyInternalFrame extends JInternalFrame {
static int openFrameCount = 0;
static final int xOffset = 30, yOffset = 30; public MyInternalFrame() {
super("Document #" + (++openFrameCount),
true, //resizable
true, //closable
true, //maximizable
true);//iconifiable //...Create the GUI and put it in the window... //...Then set the window size or call pack...
setSize(300,300); //Set the window's location.
setLocation(xOffset*openFrameCount, yOffset*openFrameCount);
}
}java tutorial 中的示例!