Guest User

Untitled

a guest
Jul 19th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.54 KB | None | 0 0
  1. package com.javadesktop.aula10;
  2.  
  3. import java.awt.EventQueue;
  4.  
  5. import javax.swing.JFrame;
  6. import javax.swing.JOptionPane;
  7. import javax.swing.JButton;
  8. import java.awt.event.ActionListener;
  9. import java.awt.event.ActionEvent;
  10. import javax.swing.JTextField;
  11. import javax.swing.JLabel;
  12. import javax.swing.JTextArea;
  13. import javax.swing.JRadioButton;
  14. import javax.swing.JComboBox;
  15.  
  16.  
  17. public class JavaSwingFormExample {
  18.  
  19. private JFrame frame;
  20. private JTextField textField;
  21. private JTextField textField_1;
  22. private JTextField textField_2;
  23.  
  24. /**
  25. * Launch the application.
  26. */
  27. public static void main(String[] args) {
  28. EventQueue.invokeLater(new Runnable() {
  29. public void run() {
  30. try {
  31. JavaSwingFormExample window = new JavaSwingFormExample();
  32. window.frame.setVisible(true);
  33. } catch (Exception e) {
  34. e.printStackTrace();
  35. }
  36. }
  37. });
  38. }
  39.  
  40. /**
  41. * Create the application.
  42. */
  43. public JavaSwingFormExample() {
  44. initialize();
  45. }
  46.  
  47. /**
  48. * Initialize the contents of the frame.
  49. */
  50. private void initialize() {
  51. frame = new JFrame();
  52. frame.setBounds(100, 100, 730, 489);
  53. frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  54. frame.getContentPane().setLayout(null);
  55.  
  56. textField = new JTextField();
  57. textField.setBounds(128, 28, 86, 20);
  58. frame.getContentPane().add(textField);
  59. textField.setColumns(10);
  60.  
  61. JLabel lblName = new JLabel("Name");
  62. lblName.setBounds(80, 31, 46, 14);
  63. frame.getContentPane().add(lblName);
  64.  
  65. JLabel lblPhone = new JLabel("Phone");
  66. lblPhone.setBounds(80, 68, 46, 14);
  67. frame.getContentPane().add(lblPhone);
  68.  
  69. textField_1 = new JTextField();
  70. textField_1.setBounds(128, 65, 86, 20);
  71. frame.getContentPane().add(textField_1);
  72. textField_1.setColumns(10);
  73.  
  74. JLabel lblEmailId = new JLabel("Email");
  75. lblEmailId.setBounds(80, 115, 46, 14);
  76. frame.getContentPane().add(lblEmailId);
  77.  
  78. textField_2 = new JTextField();
  79. textField_2.setBounds(128, 112, 247, 17);
  80. frame.getContentPane().add(textField_2);
  81. textField_2.setColumns(10);
  82.  
  83. JLabel lblAddress = new JLabel("Address");
  84. lblAddress.setBounds(65, 162, 90, 14);
  85. frame.getContentPane().add(lblAddress);
  86.  
  87. JTextArea textArea_1 = new JTextArea();
  88. textArea_1.setBounds(126, 157, 212, 40);
  89. frame.getContentPane().add(textArea_1);
  90.  
  91.  
  92.  
  93. JButton btnClear = new JButton("Clear");
  94.  
  95. btnClear.setBounds(312, 387, 89, 23);
  96. frame.getContentPane().add(btnClear);
  97.  
  98. JLabel lblSex = new JLabel("Sex");
  99. lblSex.setBounds(65, 228, 46, 14);
  100. frame.getContentPane().add(lblSex);
  101.  
  102. JLabel lblMale = new JLabel("Male");
  103. lblMale.setBounds(128, 228, 46, 14);
  104. frame.getContentPane().add(lblMale);
  105.  
  106. JLabel lblFemale = new JLabel("Female");
  107. lblFemale.setBounds(292, 228, 80, 14);
  108. frame.getContentPane().add(lblFemale);
  109.  
  110. JRadioButton radioButton = new JRadioButton("");
  111. radioButton.setBounds(341, 224, 109, 23);
  112. frame.getContentPane().add(radioButton);
  113.  
  114. JRadioButton radioButton_1 = new JRadioButton("");
  115. radioButton_1.setBounds(160, 224, 109, 23);
  116. frame.getContentPane().add(radioButton_1);
  117.  
  118. JLabel lblOccupation = new JLabel("Occupation");
  119. lblOccupation.setBounds(65, 288, 90, 14);
  120. frame.getContentPane().add(lblOccupation);
  121.  
  122. JComboBox<String> comboBox = new JComboBox<String>();
  123. comboBox.addItem("Select");
  124. comboBox.addItem("Business");
  125. comboBox.addItem("Engineer");
  126. comboBox.addItem("Doctor");
  127. comboBox.addItem("Student");
  128. comboBox.addItem("Others");
  129. comboBox.addActionListener(new ActionListener() {
  130. public void actionPerformed(ActionEvent arg0) {
  131. }
  132. });
  133. comboBox.setBounds(180, 285, 91, 20);
  134. frame.getContentPane().add(comboBox);
  135.  
  136.  
  137. JButton btnSubmit = new JButton("Submit");
  138.  
  139.  
  140. btnSubmit.setBounds(65, 387, 89, 23);
  141. frame.getContentPane().add(btnSubmit);
  142.  
  143.  
  144. btnSubmit.addActionListener(new ActionListener() {
  145. public void actionPerformed(ActionEvent arg0) {
  146. if(textField.getText().isEmpty()||(textField_1.getText().isEmpty())||(textField_2.getText().isEmpty())||(textArea_1.getText().isEmpty())||((radioButton_1.isSelected())&&(radioButton.isSelected()))||(comboBox.getSelectedItem().equals("Select")))
  147. JOptionPane.showMessageDialog(null, "Data Missing");
  148. else
  149. JOptionPane.showMessageDialog(null, "Data Submitted");
  150. }
  151. });
  152.  
  153. btnClear.addActionListener(new ActionListener() {
  154. public void actionPerformed(ActionEvent e) {
  155. textField_1.setText(null);
  156. textField_2.setText(null);
  157. textField.setText(null);
  158. textArea_1.setText(null);
  159. radioButton.setSelected(false);
  160. radioButton_1.setSelected(false);
  161. comboBox.setSelectedItem("Select");
  162.  
  163.  
  164. }
  165. });
  166.  
  167. }
  168. }
Add Comment
Please, Sign In to add comment