Sample program in Java Internal Frame

Senin, 19 Desember 2011

Here's an example of a simple program to create InternalFrame in Java. Internal Frame is an internal frame (inside the main frame). With this capability, we can make a lot of windows (multi-window) in one frame. To make use JInternalFrame class.

Here is an example looks:


 


Here is an example program:

001 import java.awt .*;002003 import java.awt.event .*;004005 import javax.swing .*;006007 public class extends JFrame {InternalFrameDemo008009 private JDesktopPane deskPane;010011 private JMenuBar bar;012013 private JMenu mnuFile;014015 private JMenuItem itemNew, itemClose;016017 public InternalFrameDemo () {018019 super ("Creating the Internal Frame");020021 JDesktopPane deskPane = new ();022023 getContentPane (). Add (deskPane);024025 bar = new JMenuBar ();026027 mnuFile = new JMenu ("File");028029 mnuFile.setMnemonic ('F');030031 itemNew = new JMenuItem ("New");032033 itemNew.setMnemonic ('N');034035 itemNew.setAccelerator (KeyStroke.getKeyStroke (KeyEvent.VK_N, ActionEvent.CTRL_MASK));036037 itemNew.addActionListener (038039 new ActionListener () {040041 private int count = 0;042043 public void actionPerformed (ActionEvent e) {044045 String title = "Internal Frame" + (+ + number);046047 Color bg = new Color ((float) Math.random (), (float) Math.random (), (float) Math.random ());048049 JInternalFrame iframe = new JInternalFrame (title, true, true, true, true);050051 / / (title, resizable, closable, maximizable, iconizable)052053 / / remove the title bar of an iframe054055 ((javax.swing.plaf.basic.BasicInternalFrameUI) iframe.getUI ()). SetNorthPane (null);056Iframe.setSize 057 (200.150);058059 iframe.setBackground (bg);060061 deskPane.add (iframe);062063 iframe.setVisible (true);064065}066067}068069);070071 itemClose = new JMenuItem ("Close");072ItemClose.setMnemonic 073 ('C');074075 itemClose.addActionListener (076077 new ActionListener () {078079 public void actionPerformed (ActionEvent e) {080081 System.exit (0);082083}084085}086087);088089 mnuFile.add (itemNew);090091 mnuFile.add (itemClose);092093 bar.add (mnuFile);094SetJMenuBar 095 (bar);096SetSize 097 (500.400);098099 setLocationRelativeTo (null);100101 setVisible (true);102103}104105 public static void main (String args []) {106107 InternalFrameDemo InternalFrameDemo test = new ();108109 test.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);110111}112113}
May be useful

0 komentar:

 
© Copyright 2010-2011 materials informatics All Rights Reserved.
Template Design by Moch Ramdhan | Published by Ramdhan Templates | Powered by Blogger.com.