N7Ved

Домик

Mar 6th, 2020
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.42 KB | None | 0 0
  1. package lab3;
  2.  
  3. import java.awt.Graphics;
  4.  
  5. import javax.swing.JPanel;
  6.  
  7. public class MyPanel extends JPanel {
  8.  
  9. private int figureType = 0;
  10.  
  11. public void setFigureType(int fType) {
  12. figureType = fType;
  13. repaint();
  14. }
  15.  
  16. public void paint(Graphics g) {
  17.  
  18. super.paint(g);
  19. if (figureType == 0) {
  20. g.drawRect(0+20, 20, 40, 40);
  21. g.drawLine(0+15, 20, 20+20, 0);
  22. g.drawLine(20+20, 00, 45+20, 20);
  23. g.drawLine(15, 20, 45+20, 20);
  24. g.drawLine(30+20, 8, 30+20, 00);
  25. g.drawLine(30+20, 00, 40+20, 00);
  26. g.drawLine(40+20, 00, 40+20, 16);
  27. } else {
  28. for(int i = 0,j = 0; i <= 100;i += 10,j += 10) {
  29. g.drawLine(20, 120-j, 200, 20+i);
  30. }
  31. }
  32.  
  33. }
  34. }
  35.  
  36.  
  37.  
  38.  
  39.  
  40. package lab3;
  41.  
  42. import java.awt.EventQueue;
  43.  
  44. import javax.swing.JFrame;
  45. import javax.swing.JPanel;
  46. import javax.swing.JButton;
  47. import javax.swing.border.BevelBorder;
  48. import java.awt.event.ActionListener;
  49. import java.awt.event.ActionEvent;
  50.  
  51. public class lab4 {
  52.  
  53. private JFrame frame;
  54.  
  55. /**
  56. * Launch the application.
  57. */
  58. public static void main(String[] args) {
  59. EventQueue.invokeLater(new Runnable() {
  60. public void run() {
  61. try {
  62. lab4 window = new lab4();
  63. window.frame.setVisible(true);
  64. } catch (Exception e) {
  65. e.printStackTrace();
  66. }
  67. }
  68. });
  69. }
  70.  
  71. /**
  72. * Create the application.
  73. */
  74. public lab4() {
  75. initialize();
  76. }
  77.  
  78. /**
  79. * Initialize the contents of the frame.
  80. */
  81. private void initialize() {
  82. frame = new JFrame();
  83. frame.setBounds(100, 100, 450, 300);
  84. frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  85. frame.getContentPane().setLayout(null);
  86.  
  87. MyPanel panel = new MyPanel();
  88. panel.setBorder(new BevelBorder(BevelBorder.LOWERED, null, null, null, null));
  89. panel.setBounds(0, 0, 316, 261);
  90. frame.getContentPane().add(panel);
  91.  
  92. JButton btnNewButton = new JButton("\u0414\u043E\u043C");
  93. btnNewButton.addActionListener(new ActionListener() {
  94. public void actionPerformed(ActionEvent e) {
  95. panel.setFigureType(0);
  96. }
  97. });
  98. btnNewButton.setBounds(335, 11, 89, 23);
  99. frame.getContentPane().add(btnNewButton);
  100.  
  101. JButton btnNewButton_1 = new JButton("\u041B\u0438\u043D\u0438\u0438");
  102. btnNewButton_1.addActionListener(new ActionListener() {
  103. public void actionPerformed(ActionEvent e) {
  104. panel.setFigureType(1);
  105. }
  106. });
  107. btnNewButton_1.setBounds(335, 56, 89, 23);
  108. frame.getContentPane().add(btnNewButton_1);
  109. }
  110.  
  111. }
Add Comment
Please, Sign In to add comment