当前位置: 技术问答>java相关
jbuilder4里面多窗口编程(大家一起来讨论)
来源: 互联网 发布时间:2015-01-24
本文导语: 我要用jbuilder4编一个程序,我现在想让application有子窗口,因为我要用这个程序来monitor多个设备,对应每个设备开一个窗口,并且在窗口里面可以画曲线,还要包含按钮,但是不知道怎么实现(动态生成)。 ...
我要用jbuilder4编一个程序,我现在想让application有子窗口,因为我要用这个程序来monitor多个设备,对应每个设备开一个窗口,并且在窗口里面可以画曲线,还要包含按钮,但是不知道怎么实现(动态生成)。
我现在用jTabbedPane来实现,但是碰到了很多困难,请各位高手来帮帮忙,到底用什么方法来实现比较好。最好能有相关资料提供,不论英文、中文都可以。
谢谢了。
我现在用jTabbedPane来实现,但是碰到了很多困难,请各位高手来帮帮忙,到底用什么方法来实现比较好。最好能有相关资料提供,不论英文、中文都可以。
谢谢了。
|
import javax.swing.JInternalFrame;
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 kestrel
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);
}
}
////////////////
import 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);
}
}
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 kestrel
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);
}
}
////////////////
import 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);
}
}
|
to see the sample program: swingset!
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。