Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.awt.*;
- import java.awt.event.*;
- import javax.swing.*;
- public class Main extends JFrame
- {
- JTextField smallField;
- JButton button1;
- JButton button2;
- JButton button3;
- JButton button4;
- public Main(){
- button1=new JButton("first");
- button2=new JButton("second");
- button3=new JButton("third");
- button4=new JButton("fourth");
- button1.addActionListener((e)-> onButtonPressed(0));
- button2.addActionListener((e)-> onButtonPressed(1));
- button3.addActionListener((e)-> onButtonPressed(2));
- button4.addActionListener((e)-> onButtonPressed(3));
- setDefaultCloseOperation(EXIT_ON_CLOSE);
- smallField = new JTextField(15);
- smallField.setToolTipText("Короткое поле");
- JPanel contents = new JPanel();
- contents.add(button1);
- contents.add(button2);
- contents.add(button3);
- contents.add(button4);
- //contents.setLayout(new BorderLayout());
- //contents.add(smallField);
- /*button[0] = new JButton("это текст");
- contents.remove(0);
- contents.add(button[0]);
- label = new JLabel("ЭТО ЛЕЙБОЛ");
- contents.add(label);
- smallField.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- String text = smallField.getText();
- text = text.replaceAll(".(?!$)", "$0 ");
- label.setText(text);
- }
- });*/
- setContentPane(contents);
- setSize(600, 500);
- setVisible(true);
- }
- String text;
- public void onButtonPressed(int i){
- switch(i){
- case 0:
- text = button2.getText();
- button2.setText(button1.getText());
- button1.setText(button4.getText());
- button4.setText(button3.getText());
- button3.setText(text);
- break;
- case 1:
- text = button2.getText();
- button2.setText(button1.getText());
- button1.setText(button4.getText());
- button4.setText(button3.getText());
- button3.setText(text);
- break;
- case 2:
- text = button2.getText();
- button2.setText(button1.getText());
- button1.setText(button4.getText());
- button4.setText(button3.getText());
- button3.setText(text);
- break;
- case 3:
- text = button2.getText();
- button2.setText(button1.getText());
- button1.setText(button4.getText());
- button4.setText(button3.getText());
- button3.setText(text);
- break;
- case 4:
- text = button2.getText();
- button2.setText(button1.getText());
- button1.setText(button4.getText());
- button4.setText(button3.getText());
- button3.setText(text);
- break;
- }
- }
- public static void main(String[] args) {
- new Main();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement