Advertisement
Guest User

Untitled

a guest
Apr 19th, 2014
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.08 KB | None | 0 0
  1. import javax.swing.JInternalFrame;
  2. import javax.swing.JTextArea;
  3.  
  4. public class CloseWindow extends javax.swing.JFrame {
  5. JTextArea tx;
  6. int i=1;
  7. public CloseWindow() {
  8. initComponents();
  9. }
  10. @SuppressWarnings("unchecked")
  11. // <editor-fold defaultstate="collapsed" desc="Generated Code">
  12. private void initComponents() {
  13.  
  14. tPane = new javax.swing.JTabbedPane();
  15. jMenuBar1 = new javax.swing.JMenuBar();
  16. jMenu1 = new javax.swing.JMenu();
  17. Crete = new javax.swing.JMenuItem();
  18.  
  19. setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  20.  
  21. jMenu1.setText("File");
  22.  
  23. Crete.setText("Create");
  24. Crete.addActionListener(new java.awt.event.ActionListener() {
  25. public void actionPerformed(java.awt.event.ActionEvent evt) {
  26. CreteActionPerformed(evt);
  27. }
  28. });
  29. jMenu1.add(Crete);
  30.  
  31. jMenuBar1.add(jMenu1);
  32.  
  33. setJMenuBar(jMenuBar1);
  34.  
  35. javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  36. getContentPane().setLayout(layout);
  37. layout.setHorizontalGroup(
  38. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  39. .addComponent(tPane, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 427, Short.MAX_VALUE)
  40. );
  41. layout.setVerticalGroup(
  42. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  43. .addComponent(tPane, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 279, Short.MAX_VALUE)
  44. );
  45.  
  46. pack();
  47. }// </editor-fold>
  48.  
  49. private void CreteActionPerformed(java.awt.event.ActionEvent evt) {
  50. // TODO add your handling code here:
  51.  
  52. JInternalFrame internalFrame = new JInternalFrame();
  53. internalFrame.setName("Document"+i);
  54. internalFrame.setClosable(true);
  55. i++;
  56. internalFrame.setSize(700, 700);
  57. tx = new JTextArea();
  58. internalFrame.add(tx);
  59.  
  60. tPane.add(internalFrame);
  61. internalFrame.setSize(internalFrame.getMaximumSize());
  62. internalFrame.pack();
  63. internalFrame.setVisible(true);
  64.  
  65. }
  66.  
  67. public static void main(String args[]) {
  68. /* Set the Nimbus look and feel */
  69. //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  70. /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
  71. * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  72. */
  73. try {
  74. for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  75. if ("Nimbus".equals(info.getName())) {
  76. javax.swing.UIManager.setLookAndFeel(info.getClassName());
  77. break;
  78. }
  79. }
  80. } catch (ClassNotFoundException ex) {
  81. java.util.logging.Logger.getLogger(CloseWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  82. } catch (InstantiationException ex) {
  83. java.util.logging.Logger.getLogger(CloseWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  84. } catch (IllegalAccessException ex) {
  85. java.util.logging.Logger.getLogger(CloseWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  86. } catch (javax.swing.UnsupportedLookAndFeelException ex) {
  87. java.util.logging.Logger.getLogger(CloseWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  88. }
  89. //</editor-fold>
  90.  
  91. /* Create and display the form */
  92. java.awt.EventQueue.invokeLater(new Runnable() {
  93. public void run() {
  94. new CloseWindow().setVisible(true);
  95. }
  96. });
  97. }
  98. // Variables declaration - do not modify
  99. private javax.swing.JMenuItem Crete;
  100. private javax.swing.JMenu jMenu1;
  101. private javax.swing.JMenuBar jMenuBar1;
  102. private javax.swing.JTabbedPane tPane;
  103. // End of variables declaration
  104.  
  105. internalFrame.addInternalFrameListener(new InternalFrameAdapter() {
  106. @Override
  107. public void internalFrameClosing(InternalFrameEvent e) {
  108. tPane.remove(internalFrame);
  109. }
  110. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement