Advertisement
bobo_bobkata

Untitled

Jun 1st, 2019
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.72 KB | None | 0 0
  1. package PredvaritelnoAdvanced.Tesove;
  2.  
  3. import javax.swing.*;
  4. import java.awt.*;
  5. import java.awt.event.ActionEvent;
  6. import java.awt.event.ActionListener;
  7.  
  8. public class ivan {
  9.  
  10. private static String firstName;
  11. private static String secondName;
  12. private static JFrame jFrame;
  13. private static String finalText;
  14.  
  15. private static void setFinalText(String finalText) {
  16. ivan.finalText = finalText;
  17. }
  18.  
  19. private static String getFinalText() {
  20. return finalText;
  21. }
  22.  
  23. private static String getFirstName() {
  24. return firstName;
  25. }
  26.  
  27. private static JFrame getjFrame() {
  28. return jFrame;
  29. }
  30.  
  31. private static void setjFrame(JFrame jFrame) {
  32. ivan.jFrame = jFrame;
  33. }
  34.  
  35. private static void setFirstName(String firstName) {
  36. ivan.firstName = firstName;
  37. }
  38.  
  39. private static String getSecondName() {
  40. return secondName;
  41. }
  42.  
  43. private static void setSecondName(String secondName) {
  44. ivan.secondName = secondName;
  45. }
  46.  
  47. private void displayMain() {
  48. setjFrame(new JFrame());
  49. JTextField secondNameInput = new JTextField();
  50. JLabel secondNameLabel = new JLabel();
  51. JTextField firstNameInput = new JTextField();
  52. JLabel firstNameLabel = new JLabel();
  53. JButton confirmButton = new JButton();
  54.  
  55.  
  56. jFrame.setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  57.  
  58. secondNameInput.setFont(new java.awt.Font("Arial Black", Font.BOLD, 18));
  59.  
  60. secondNameLabel.setFont(new java.awt.Font("Arial Black", Font.BOLD, 18));
  61. secondNameLabel.setText("Second Name");
  62.  
  63. firstNameInput.setFont(new java.awt.Font("Arial Black", Font.BOLD, 18));
  64.  
  65. firstNameLabel.setFont(new java.awt.Font("Arial Black", Font.BOLD, 18));
  66. firstNameLabel.setText("First Name");
  67.  
  68. confirmButton.setBackground(new java.awt.Color(255, 0, 204));
  69. confirmButton.setFont(new java.awt.Font("Arial Black", Font.BOLD, 24));
  70. confirmButton.setText("Confirm");
  71. confirmButton.addActionListener(new ActionListener() {
  72. public void actionPerformed(ActionEvent evt) {
  73. setFirstName(firstNameInput.getText());
  74. setSecondName(secondNameInput.getText());
  75. confirmButton();
  76. }
  77. });
  78. javax.swing.GroupLayout layout = new javax.swing.GroupLayout(jFrame.getContentPane());
  79. jFrame.getContentPane().setLayout(layout);
  80. layout.setHorizontalGroup(
  81. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  82. .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
  83. .addContainerGap(45, Short.MAX_VALUE)
  84. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  85. .addComponent(secondNameLabel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 156, javax.swing.GroupLayout.PREFERRED_SIZE)
  86. .addComponent(firstNameLabel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 134, javax.swing.GroupLayout.PREFERRED_SIZE))
  87. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  88. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  89. .addComponent(firstNameInput, javax.swing.GroupLayout.PREFERRED_SIZE, 442, javax.swing.GroupLayout.PREFERRED_SIZE)
  90. .addComponent(secondNameInput, javax.swing.GroupLayout.PREFERRED_SIZE, 442, javax.swing.GroupLayout.PREFERRED_SIZE)
  91. .addGroup(layout.createSequentialGroup()
  92. .addGap(70, 70, 70)
  93. .addComponent(confirmButton, javax.swing.GroupLayout.PREFERRED_SIZE, 179, javax.swing.GroupLayout.PREFERRED_SIZE)))
  94. .addGap(89, 89, 89))
  95. );
  96. layout.setVerticalGroup(
  97. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  98. .addGroup(layout.createSequentialGroup()
  99. .addGap(123, 123, 123)
  100. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  101. .addComponent(firstNameInput, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
  102. .addComponent(firstNameLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE))
  103. .addGap(18, 18, 18)
  104. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  105. .addComponent(secondNameInput, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
  106. .addComponent(secondNameLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE))
  107. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 64, Short.MAX_VALUE)
  108. .addComponent(confirmButton, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
  109. .addGap(25, 25, 25))
  110. );
  111.  
  112. jFrame.pack();
  113. jFrame.setLocationRelativeTo(null);
  114. jFrame.setVisible(true);
  115. }
  116.  
  117. private void confirmButton() {
  118. boolean isCorrect = false;
  119. char heart = '♥';
  120. System.out.println(heart);
  121. try {
  122. if (!getFirstName().equals("") && !getSecondName().equals("")) {
  123. Double.parseDouble(getFirstName());
  124. Double.parseDouble(getSecondName());
  125. }
  126. JOptionPane.showMessageDialog(null, "Enter correct information");
  127. } catch (Exception igonred) {
  128. isCorrect = true;
  129. }
  130. if (isCorrect) {
  131. ivan.setFinalText(String.format("%s + %s = %c", getFirstName(), getSecondName(), heart));
  132. getjFrame().hide();
  133. new ivan().displayViewSecond();
  134. }
  135. }
  136.  
  137. private void displayViewSecond() {
  138. JLabel label = new JLabel();
  139. JFrame jFrame = new JFrame();
  140.  
  141. jFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
  142.  
  143. label.setBackground(new Color(51, 255, 255));
  144. label.setFont(new Font("Arial Black", Font.BOLD, 48));
  145. label.setLabelFor(label);
  146. label.setText(getFinalText());
  147.  
  148. GroupLayout layout = new GroupLayout(jFrame.getContentPane());
  149. jFrame.getContentPane().setLayout(layout);
  150. layout.setHorizontalGroup(
  151. layout.createParallelGroup(GroupLayout.Alignment.LEADING)
  152. .addGroup(layout.createSequentialGroup()
  153. .addContainerGap()
  154. .addComponent(label, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  155. .addContainerGap())
  156. );
  157. layout.setVerticalGroup(
  158. layout.createParallelGroup(GroupLayout.Alignment.LEADING)
  159. .addGroup(GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
  160. .addContainerGap(115, Short.MAX_VALUE)
  161. .addComponent(label, GroupLayout.PREFERRED_SIZE, 251, GroupLayout.PREFERRED_SIZE)
  162. .addGap(94, 94, 94))
  163. );
  164.  
  165. jFrame.pack();
  166. jFrame.setVisible(true);
  167. jFrame.setLocationRelativeTo(null);
  168. }
  169.  
  170. public static void main(String[] args) {
  171. try {
  172. for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  173. if ("Nimbus".equals(info.getName())) {
  174. javax.swing.UIManager.setLookAndFeel(info.getClassName());
  175. break;
  176. }
  177. }
  178. } catch (ClassNotFoundException | UnsupportedLookAndFeelException | IllegalAccessException | InstantiationException ex) {
  179. java.util.logging.Logger.getLogger(ivan.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  180. }
  181. java.awt.EventQueue.invokeLater(new Runnable() {
  182. public void run() {
  183. new ivan().displayMain();
  184. }
  185. });
  186. }
  187. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement