Advertisement
Guest User

Untitled

a guest
May 21st, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.23 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.awt.*;
  4. import java.awt.event.*;
  5. import javax.swing.*;
  6.  
  7.  
  8. public class Main extends JFrame
  9. {
  10.     JTextField smallField;
  11.     JButton button1;
  12.     JButton button2;
  13.     JButton button3;
  14.     JButton button4;
  15.  
  16.  
  17.     public Main(){
  18.         button1=new JButton("first");
  19.         button2=new JButton("second");
  20.         button3=new JButton("third");
  21.         button4=new JButton("fourth");
  22.         button1.addActionListener((e)-> onButtonPressed(0));
  23.         button2.addActionListener((e)-> onButtonPressed(1));
  24.         button3.addActionListener((e)-> onButtonPressed(2));
  25.         button4.addActionListener((e)-> onButtonPressed(3));
  26.         setDefaultCloseOperation(EXIT_ON_CLOSE);
  27.         smallField = new JTextField(15);
  28.         smallField.setToolTipText("Короткое поле");
  29.         JPanel contents = new JPanel();
  30.         contents.add(button1);
  31.         contents.add(button2);
  32.         contents.add(button3);
  33.         contents.add(button4);
  34.         //contents.setLayout(new BorderLayout());
  35.         //contents.add(smallField);
  36.         /*button[0] = new JButton("это текст");
  37.         contents.remove(0);
  38.         contents.add(button[0]);
  39.         label = new JLabel("ЭТО ЛЕЙБОЛ");
  40.         contents.add(label);
  41.         smallField.addActionListener(new ActionListener() {
  42.             public void actionPerformed(ActionEvent e) {
  43.                 String text = smallField.getText();
  44.                 text = text.replaceAll(".(?!$)", "$0 ");
  45.                 label.setText(text);
  46.             }
  47.         });*/
  48.         setContentPane(contents);
  49.         setSize(600, 500);
  50.         setVisible(true);
  51.     }
  52.  
  53.     String text;
  54.     public void onButtonPressed(int i){
  55.         switch(i){
  56.             case 0:
  57.                 text = button2.getText();
  58.                 button2.setText(button1.getText());
  59.                 button1.setText(button4.getText());
  60.                 button4.setText(button3.getText());
  61.                 button3.setText(text);
  62.                 break;
  63.             case 1:
  64.                 text = button2.getText();
  65.                 button2.setText(button1.getText());
  66.                 button1.setText(button4.getText());
  67.                 button4.setText(button3.getText());
  68.                 button3.setText(text);
  69.                 break;
  70.             case 2:
  71.                 text = button2.getText();
  72.                 button2.setText(button1.getText());
  73.                 button1.setText(button4.getText());
  74.                 button4.setText(button3.getText());
  75.                 button3.setText(text);
  76.                 break;
  77.             case 3:
  78.                 text = button2.getText();
  79.                 button2.setText(button1.getText());
  80.                 button1.setText(button4.getText());
  81.                 button4.setText(button3.getText());
  82.                 button3.setText(text);
  83.                 break;
  84.             case 4:
  85.                 text = button2.getText();
  86.                 button2.setText(button1.getText());
  87.                 button1.setText(button4.getText());
  88.                 button4.setText(button3.getText());
  89.                 button3.setText(text);
  90.                 break;
  91.  
  92.         }
  93.     }
  94.  
  95.     public static void main(String[] args) {
  96.         new Main();
  97.     }
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement