thespeedracer38

Button Hello World!

Jun 12th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.43 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6.  
  7. /**
  8.  *
  9.  * @author Ranajoy
  10.  */
  11. public class UI extends javax.swing.JFrame {
  12.  
  13.     /**
  14.      * Creates new form UI
  15.      */
  16.     public UI() {
  17.         initComponents();
  18.         this.setLocationRelativeTo(null);
  19.     }
  20.  
  21.     /**
  22.      * This method is called from within the constructor to initialize the form.
  23.      * WARNING: Do NOT modify this code. The content of this method is always
  24.      * regenerated by the Form Editor.
  25.      */
  26.     @SuppressWarnings("unchecked")
  27.     // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  28.     private void initComponents() {
  29.  
  30.         jPanel1 = new javax.swing.JPanel();
  31.         printHelloWorld = new javax.swing.JButton();
  32.  
  33.         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  34.         setTitle("HelloButton");
  35.  
  36.         jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Button Panel", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 14))); // NOI18N
  37.  
  38.         printHelloWorld.setText("Click to print \"Hello, World!\"");
  39.         printHelloWorld.addActionListener(new java.awt.event.ActionListener() {
  40.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  41.                 printHelloWorldActionPerformed(evt);
  42.             }
  43.         });
  44.  
  45.         javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
  46.         jPanel1.setLayout(jPanel1Layout);
  47.         jPanel1Layout.setHorizontalGroup(
  48.             jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  49.             .addGroup(jPanel1Layout.createSequentialGroup()
  50.                 .addGap(98, 98, 98)
  51.                 .addComponent(printHelloWorld)
  52.                 .addContainerGap(105, Short.MAX_VALUE))
  53.         );
  54.         jPanel1Layout.setVerticalGroup(
  55.             jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  56.             .addGroup(jPanel1Layout.createSequentialGroup()
  57.                 .addGap(107, 107, 107)
  58.                 .addComponent(printHelloWorld)
  59.                 .addContainerGap(122, Short.MAX_VALUE))
  60.         );
  61.  
  62.         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  63.         getContentPane().setLayout(layout);
  64.         layout.setHorizontalGroup(
  65.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  66.             .addGroup(layout.createSequentialGroup()
  67.                 .addContainerGap()
  68.                 .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  69.                 .addContainerGap())
  70.         );
  71.         layout.setVerticalGroup(
  72.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  73.             .addGroup(layout.createSequentialGroup()
  74.                 .addContainerGap()
  75.                 .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  76.                 .addContainerGap())
  77.         );
  78.  
  79.         pack();
  80.     }// </editor-fold>//GEN-END:initComponents
  81.  
  82.     private void printHelloWorldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_printHelloWorldActionPerformed
  83.         System.out.println("Hello, World!");
  84.     }//GEN-LAST:event_printHelloWorldActionPerformed
  85.  
  86.     /**
  87.      * @param args the command line arguments
  88.      */
  89.     public static void main(String args[]) {
  90.         /* Set the Nimbus look and feel */
  91.         //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  92.         /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
  93.          * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  94.          */
  95.         try {
  96.             for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  97.                 if ("Windows".equals(info.getName())) {
  98.                     javax.swing.UIManager.setLookAndFeel(info.getClassName());
  99.                     break;
  100.                 }
  101.             }
  102.         } catch (ClassNotFoundException ex) {
  103.             java.util.logging.Logger.getLogger(UI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  104.         } catch (InstantiationException ex) {
  105.             java.util.logging.Logger.getLogger(UI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  106.         } catch (IllegalAccessException ex) {
  107.             java.util.logging.Logger.getLogger(UI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  108.         } catch (javax.swing.UnsupportedLookAndFeelException ex) {
  109.             java.util.logging.Logger.getLogger(UI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  110.         }
  111.         //</editor-fold>
  112.  
  113.         /* Create and display the form */
  114.         java.awt.EventQueue.invokeLater(new Runnable() {
  115.             public void run() {
  116.                 new UI().setVisible(true);
  117.             }
  118.         });
  119.     }
  120.  
  121.     // Variables declaration - do not modify//GEN-BEGIN:variables
  122.     private javax.swing.JPanel jPanel1;
  123.     private javax.swing.JButton printHelloWorld;
  124.     // End of variables declaration//GEN-END:variables
  125. }
Add Comment
Please, Sign In to add comment