Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package PredvaritelnoAdvanced.Tesove;
- import javax.swing.*;
- import java.awt.*;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- public class ivan {
- private static String firstName;
- private static String secondName;
- private static JFrame jFrame;
- private static String finalText;
- private static void setFinalText(String finalText) {
- ivan.finalText = finalText;
- }
- private static String getFinalText() {
- return finalText;
- }
- private static String getFirstName() {
- return firstName;
- }
- private static JFrame getjFrame() {
- return jFrame;
- }
- private static void setjFrame(JFrame jFrame) {
- ivan.jFrame = jFrame;
- }
- private static void setFirstName(String firstName) {
- ivan.firstName = firstName;
- }
- private static String getSecondName() {
- return secondName;
- }
- private static void setSecondName(String secondName) {
- ivan.secondName = secondName;
- }
- private void displayMain() {
- setjFrame(new JFrame());
- JTextField secondNameInput = new JTextField();
- JLabel secondNameLabel = new JLabel();
- JTextField firstNameInput = new JTextField();
- JLabel firstNameLabel = new JLabel();
- JButton confirmButton = new JButton();
- jFrame.setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
- secondNameInput.setFont(new java.awt.Font("Arial Black", Font.BOLD, 18));
- secondNameLabel.setFont(new java.awt.Font("Arial Black", Font.BOLD, 18));
- secondNameLabel.setText("Second Name");
- firstNameInput.setFont(new java.awt.Font("Arial Black", Font.BOLD, 18));
- firstNameLabel.setFont(new java.awt.Font("Arial Black", Font.BOLD, 18));
- firstNameLabel.setText("First Name");
- confirmButton.setBackground(new java.awt.Color(255, 0, 204));
- confirmButton.setFont(new java.awt.Font("Arial Black", Font.BOLD, 24));
- confirmButton.setText("Confirm");
- confirmButton.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent evt) {
- setFirstName(firstNameInput.getText());
- setSecondName(secondNameInput.getText());
- confirmButton();
- }
- });
- javax.swing.GroupLayout layout = new javax.swing.GroupLayout(jFrame.getContentPane());
- jFrame.getContentPane().setLayout(layout);
- layout.setHorizontalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
- .addContainerGap(45, Short.MAX_VALUE)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(secondNameLabel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 156, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(firstNameLabel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 134, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(firstNameInput, javax.swing.GroupLayout.PREFERRED_SIZE, 442, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(secondNameInput, javax.swing.GroupLayout.PREFERRED_SIZE, 442, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addGroup(layout.createSequentialGroup()
- .addGap(70, 70, 70)
- .addComponent(confirmButton, javax.swing.GroupLayout.PREFERRED_SIZE, 179, javax.swing.GroupLayout.PREFERRED_SIZE)))
- .addGap(89, 89, 89))
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addGap(123, 123, 123)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(firstNameInput, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(firstNameLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGap(18, 18, 18)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(secondNameInput, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(secondNameLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 64, Short.MAX_VALUE)
- .addComponent(confirmButton, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addGap(25, 25, 25))
- );
- jFrame.pack();
- jFrame.setLocationRelativeTo(null);
- jFrame.setVisible(true);
- }
- private void confirmButton() {
- boolean isCorrect = false;
- char heart = '♥';
- System.out.println(heart);
- try {
- if (!getFirstName().equals("") && !getSecondName().equals("")) {
- Double.parseDouble(getFirstName());
- Double.parseDouble(getSecondName());
- }
- JOptionPane.showMessageDialog(null, "Enter correct information");
- } catch (Exception igonred) {
- isCorrect = true;
- }
- if (isCorrect) {
- ivan.setFinalText(String.format("%s + %s = %c", getFirstName(), getSecondName(), heart));
- getjFrame().hide();
- new ivan().displayViewSecond();
- }
- }
- private void displayViewSecond() {
- JLabel label = new JLabel();
- JFrame jFrame = new JFrame();
- jFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
- label.setBackground(new Color(51, 255, 255));
- label.setFont(new Font("Arial Black", Font.BOLD, 48));
- label.setLabelFor(label);
- label.setText(getFinalText());
- GroupLayout layout = new GroupLayout(jFrame.getContentPane());
- jFrame.getContentPane().setLayout(layout);
- layout.setHorizontalGroup(
- layout.createParallelGroup(GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addContainerGap()
- .addComponent(label, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addContainerGap())
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(GroupLayout.Alignment.LEADING)
- .addGroup(GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
- .addContainerGap(115, Short.MAX_VALUE)
- .addComponent(label, GroupLayout.PREFERRED_SIZE, 251, GroupLayout.PREFERRED_SIZE)
- .addGap(94, 94, 94))
- );
- jFrame.pack();
- jFrame.setVisible(true);
- jFrame.setLocationRelativeTo(null);
- }
- public static void main(String[] args) {
- try {
- for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
- if ("Nimbus".equals(info.getName())) {
- javax.swing.UIManager.setLookAndFeel(info.getClassName());
- break;
- }
- }
- } catch (ClassNotFoundException | UnsupportedLookAndFeelException | IllegalAccessException | InstantiationException ex) {
- java.util.logging.Logger.getLogger(ivan.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- }
- java.awt.EventQueue.invokeLater(new Runnable() {
- public void run() {
- new ivan().displayMain();
- }
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement