Advertisement
Guest User

Untitled

a guest
Dec 25th, 2012
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.81 KB | None | 0 0
  1. /*
  2. * To change this template, choose Tools | Templates
  3. * and open the template in the editor.
  4. */
  5. package javaapplication9;
  6.  
  7. import javax.swing.JOptionPane;
  8.  
  9. /**
  10. *
  11. * @author Renter
  12. */
  13. public class NewJFrame extends javax.swing.JFrame {
  14.  
  15. /**
  16. * Creates new form NewJFrame
  17. */
  18. public NewJFrame() {
  19. initComponents();
  20. }
  21.  
  22. /**
  23. * This method is called from within the constructor to initialize the form.
  24. * WARNING: Do NOT modify this code. The content of this method is always
  25. * regenerated by the Form Editor.
  26. */
  27. @SuppressWarnings("unchecked")
  28. // <editor-fold defaultstate="collapsed" desc="Generated Code">
  29. private void initComponents() {
  30.  
  31. inputText = new javax.swing.JTextField();
  32. submitButton = new javax.swing.JButton();
  33.  
  34. setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  35.  
  36. submitButton.setText("Submit");
  37. submitButton.addActionListener(new java.awt.event.ActionListener() {
  38. public void actionPerformed(java.awt.event.ActionEvent evt) {
  39. submitButtonActionPerformed(evt);
  40. }
  41. });
  42.  
  43. javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  44. getContentPane().setLayout(layout);
  45. layout.setHorizontalGroup(
  46. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  47. .addGroup(layout.createSequentialGroup()
  48. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  49. .addGroup(layout.createSequentialGroup()
  50. .addContainerGap()
  51. .addComponent(inputText, javax.swing.GroupLayout.PREFERRED_SIZE, 240, javax.swing.GroupLayout.PREFERRED_SIZE))
  52. .addGroup(layout.createSequentialGroup()
  53. .addGap(84, 84, 84)
  54. .addComponent(submitButton)))
  55. .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  56. );
  57. layout.setVerticalGroup(
  58. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  59. .addGroup(layout.createSequentialGroup()
  60. .addContainerGap()
  61. .addComponent(inputText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  62. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  63. .addComponent(submitButton)
  64. .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  65. );
  66.  
  67. pack();
  68. }// </editor-fold>
  69.  
  70. private void submitButtonActionPerformed(java.awt.event.ActionEvent evt) {
  71. String textFromField = inputText.getText();
  72. JOptionPane.showMessageDialog(this, textFromField, "Echo of string", JOptionPane.PLAIN_MESSAGE);
  73. }
  74.  
  75. /**
  76. * @param args the command line arguments
  77. */
  78. public static void main(String args[]) {
  79. /* Set the Nimbus look and feel */
  80. //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  81. /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
  82. * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  83. */
  84. try {
  85. for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  86. if ("Nimbus".equals(info.getName())) {
  87. javax.swing.UIManager.setLookAndFeel(info.getClassName());
  88. break;
  89. }
  90. }
  91. } catch (ClassNotFoundException ex) {
  92. java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  93. } catch (InstantiationException ex) {
  94. java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  95. } catch (IllegalAccessException ex) {
  96. java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  97. } catch (javax.swing.UnsupportedLookAndFeelException ex) {
  98. java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  99. }
  100. //</editor-fold>
  101.  
  102. /* Create and display the form */
  103. java.awt.EventQueue.invokeLater(new Runnable() {
  104. public void run() {
  105. new NewJFrame().setVisible(true);
  106. }
  107. });
  108. }
  109. // Variables declaration - do not modify
  110. private javax.swing.JTextField inputText;
  111. private javax.swing.JButton submitButton;
  112. // End of variables declaration
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement