1. Java / Говнокод #23609

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    import javax.swing.*;
    import javax.swing.event.ListSelectionEvent;
    import javax.swing.event.ListSelectionListener;
    import java.awt.*;
    import java.awt.event.*;
    
    
    public class Experiment5 implements ActionListener{
        JFrame frame;
        JList list;
        JTextField text;
        public static void main(String[] args) {
            Experiment5 experiment5 = new Experiment5();
            experiment5.go();
        }
    
        public void go(){
            frame = new JFrame();
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    
            JPanel panel = new JPanel();
    
            JButton button = new JButton("Click me");
            button.addActionListener(this);
    
            text = new JTextField();
    
            String[] listEntries = {"Java", "C++", "Perl", "Python", "JavaScript", "PHP", "C#"};
            list = new JList(listEntries);
            list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
            list.addListSelectionListener(new SelectionOne());
    
            MyDrawPanel1 panel1 = new MyDrawPanel1();
    
            frame.getContentPane().add(BorderLayout.SOUTH, button);
            frame.getContentPane().add(BorderLayout.NORTH, text);
            frame.getContentPane().add(BorderLayout.EAST, list);
            frame.getContentPane().add(BorderLayout.CENTER, panel1);
            frame.setSize(500, 300);
            frame.setVisible(true);
        }
    
        public void actionPerformed(ActionEvent event){
            int ran = (int) (Math.random() * 255);
            text.setText("New random - " + ran);
            frame.repaint();
        }
    
        class SelectionOne implements ListSelectionListener {
            public void valueChanged(ListSelectionEvent lse) {
                if(!lse.getValueIsAdjusting()){
                    String selection = (String) list.getSelectedValue();
                    System.out.println(selection);
                }
            }
        }
    }
    class MyDrawPanel1 extends JPanel{
        public void paintComponent(Graphics g){
    
            int one = (int)(Math.random() * 255);
            int two = (int)(Math.random() * 255);
            int three = (int)(Math.random() * 255);
    
            Color color = new Color(one, two, three);
            g.setColor(color);
            g.fillOval(110, 10, 200, 200);
        }
    }

    SWING!!! Jlist, JTextField, JPanel !!! КАК УЛУЧШИТЬ ЭТОТ ПОНОС???

    Запостил: babushkaAntona, 21 Декабря 2017

    Комментарии (2) RSS

    Добавить комментарий