daily pastebin goal
3%
SHARE
TWEET

Untitled

a guest May 23rd, 2018 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package janelas;
  2.  
  3. public class desktop extends javax.swing.JFrame {
  4.     private frameInterno register;
  5.  
  6.     public desktop() {
  7.         initComponents();
  8.     }
  9.  
  10.     private void initComponents() {
  11.  
  12.         painelDesktop = new javax.swing.JDesktopPane();
  13.         btnAbrirFrame = new javax.swing.JButton();
  14.  
  15.         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  16.  
  17.         javax.swing.GroupLayout painelDesktopLayout = new javax.swing.GroupLayout(painelDesktop);
  18.         painelDesktop.setLayout(painelDesktopLayout);
  19.         painelDesktopLayout.setHorizontalGroup(
  20.             painelDesktopLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  21.             .addGap(0, 0, Short.MAX_VALUE)
  22.         );
  23.         painelDesktopLayout.setVerticalGroup(
  24.             painelDesktopLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  25.             .addGap(0, 260, Short.MAX_VALUE)
  26.         );
  27.  
  28.         btnAbrirFrame.setText("Abrir Frame");
  29.         btnAbrirFrame.addActionListener(new java.awt.event.ActionListener() {
  30.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  31.                 btnAbrirFrameActionPerformed(evt);
  32.             }
  33.         });
  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(painelDesktop)
  40.             .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
  41.                 .addContainerGap(301, Short.MAX_VALUE)
  42.                 .addComponent(btnAbrirFrame)
  43.                 .addContainerGap())
  44.         );
  45.         layout.setVerticalGroup(
  46.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  47.             .addGroup(layout.createSequentialGroup()
  48.                 .addComponent(painelDesktop, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  49.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  50.                 .addComponent(btnAbrirFrame)
  51.                 .addGap(0, 11, Short.MAX_VALUE))
  52.         );
  53.  
  54.         pack();
  55.     }
  56.  
  57.     private void btnAbrirFrameActionPerformed(java.awt.event.ActionEvent evt) {                                              
  58.         if (register == null) {
  59.             register = new frameInterno();
  60.         }
  61.  
  62.         if (!register.isVisible()) {
  63.             painelDesktop.add(register);
  64.             register.setVisible(true);
  65.         }
  66.         register.toFront();
  67.     }                                            
  68.  
  69.     public static void main(String args[]) {
  70.         java.awt.EventQueue.invokeLater(new Runnable() {
  71.             public void run() {
  72.                 new desktop().setVisible(true);
  73.             }
  74.         });
  75.     }
  76.  
  77.     private javax.swing.JButton btnAbrirFrame;
  78.     private javax.swing.JDesktopPane painelDesktop;
  79.  
  80. }
  81.    
  82. package janelas;
  83.  
  84. public class frameInterno extends javax.swing.JInternalFrame {
  85.  
  86.     public frameInterno() {
  87.         initComponents();
  88.     }
  89.  
  90.     private void initComponents() {
  91.  
  92.         btnSair = new javax.swing.JButton();
  93.  
  94.         btnSair.setText("Sair");
  95.         btnSair.addActionListener(new java.awt.event.ActionListener() {
  96.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  97.                 btnSairActionPerformed(evt);
  98.             }
  99.         });
  100.  
  101.         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  102.         getContentPane().setLayout(layout);
  103.         layout.setHorizontalGroup(
  104.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  105.             .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
  106.                 .addContainerGap(300, Short.MAX_VALUE)
  107.                 .addComponent(btnSair)
  108.                 .addContainerGap())
  109.         );
  110.         layout.setVerticalGroup(
  111.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  112.             .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
  113.                 .addContainerGap(200, Short.MAX_VALUE)
  114.                 .addComponent(btnSair)
  115.                 .addContainerGap())
  116.         );
  117.  
  118.         pack();
  119.     }
  120.  
  121.     private void btnSairActionPerformed(java.awt.event.ActionEvent evt) {                                        
  122.         this.dispose();
  123.     }
  124.  
  125.     private javax.swing.JButton btnSair;
  126. }
  127.    
  128. Exception in thread "AWT-EventQueue-0"
  129. java.lang.IllegalArgumentException: illegal component position  at
  130. java.awt.Container.addImpl(Container.java:1100)     at
  131. javax.swing.JLayeredPane.addImpl(JLayeredPane.java:231)     at
  132. javax.swing.JDesktopPane.addImpl(JDesktopPane.java:484)     at
  133. java.awt.Container.add(Container.java:417)  at
  134. janelas.desktop.btnAbrirFrameActionPerformed(desktop.java:63)   at
  135. janelas.desktop.access$000(desktop.java:3)  at
  136. janelas.desktop$1.actionPerformed(desktop.java:31)  at
  137. javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)    at
  138. javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2348)    at
  139. javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)     at
  140. javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)  at
  141. javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)  at
  142. java.awt.Component.processMouseEvent(Component.java:6533)   at
  143. javax.swing.JComponent.processMouseEvent(JComponent.java:3324)  at
  144. java.awt.Component.processEvent(Component.java:6298)    at
  145. java.awt.Container.processEvent(Container.java:2236)    at
  146. java.awt.Component.dispatchEventImpl(Component.java:4889)   at
  147. java.awt.Container.dispatchEventImpl(Container.java:2294)   at
  148. java.awt.Component.dispatchEvent(Component.java:4711)   at
  149. java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4888)  at
  150. java.awt.LightweightDispatcher.processMouseEvent(Container.java:4525)   at
  151. java.awt.LightweightDispatcher.dispatchEvent(Container.java:4466)   at
  152. java.awt.Container.dispatchEventImpl(Container.java:2280)   at
  153. java.awt.Window.dispatchEventImpl(Window.java:2746)     at
  154. java.awt.Component.dispatchEvent(Component.java:4711)   at
  155. java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)  at
  156. java.awt.EventQueue.access$500(EventQueue.java:97)  at
  157. java.awt.EventQueue$3.run(EventQueue.java:709)  at
  158. java.awt.EventQueue$3.run(EventQueue.java:703)  at
  159. java.security.AccessController.doPrivileged(Native Method)  at
  160. java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)     at
  161. java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:90)     at
  162. java.awt.EventQueue$4.run(EventQueue.java:731)  at
  163. java.awt.EventQueue$4.run(EventQueue.java:729)  at
  164. java.security.AccessController.doPrivileged(Native Method)  at
  165. java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)     at
  166. java.awt.EventQueue.dispatchEvent(EventQueue.java:728)  at
  167. java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)   at
  168. java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)  at
  169. java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)   at
  170. java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)   at
  171. java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)    at
  172. java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
  173.    
  174. private void btnSairActionPerformed(java.awt.event.ActionEvent evt) {  
  175.     this.setVisible(false);
  176. }
  177.    
  178. private void btnAbrirFrameActionPerformed(java.awt.event.ActionEvent evt) {                                          
  179.     if (register == null) {
  180.         register = new frameInterno();
  181.         painelDesktop.add(register);    
  182.     }
  183.  
  184.     if (!register.isVisible()) {
  185.         register.setVisible(true);
  186.     }
  187.     register.toFront();
  188. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top