Advertisement
Guest User

Untitled

a guest
Nov 16th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 KB | None | 0 0
  1. import java.awt.BorderLayout;
  2. import java.awt.Color;
  3. import java.awt.FlowLayout;
  4. import java.awt.Graphics;
  5. import java.awt.GridLayout;
  6. import java.awt.event.ActionEvent;
  7. import java.awt.event.ActionListener;
  8.  
  9. import javax.swing.*;
  10.  
  11. public class DotsFrame extends JFrame {
  12.  
  13. //////////////////////////////
  14.  
  15. private JButton[][] buttonArray;
  16.  
  17. ///////////////////////////////
  18.  
  19. //////////////////////////////
  20.  
  21. public DotsFrame() {
  22. super("Точки");
  23. setSize(550, 650);
  24. setDefaultCloseOperation(EXIT_ON_CLOSE);
  25.  
  26. buttonArray = new JButton[19][19];
  27. for (int i = 0; i < 19; i++) {
  28. for (int j = 0; j < 19; j++) {
  29. buttonArray[i][j] = new JButton("" + (i + 1));
  30. }
  31. }
  32.  
  33. for (int i = 0; i < 19; i++) {
  34. for (int j = 0; j < 19; j++) {
  35. buttonArray[i][j].setBounds(12 + 25 * (i + 1), 90 + 25 * (j + 1), 10, 10);
  36. //buttonArray[i][j].setVisible(true);
  37. buttonArray[i][j].setActionCommand(i + ":" + j);
  38. buttonArray[i][j].addActionListener(new ButtonEventListener());
  39. add(buttonArray[i][j]);
  40. }
  41. }
  42. }
  43.  
  44. class ButtonEventListener implements ActionListener {
  45.  
  46. @Override
  47. public void actionPerformed(ActionEvent e) {
  48. String com = e.getActionCommand();
  49. String comA = "";
  50. String comB = "";
  51. boolean flag = false;
  52. int i = 0;
  53. int j = 0;
  54. for (int ii = 0; ii < com.length() - 1; ii++) {
  55. if (com.charAt(ii) == ':') {
  56. flag = true;
  57. }
  58. if (flag) {
  59. comB += com.charAt(ii + 1);
  60. } else {
  61. comA += com.charAt(ii);
  62. }
  63. }
  64. i = Integer.valueOf(comA);
  65. j = Integer.valueOf(comB);
  66.  
  67. System.out.println(i + ":" + j);
  68. buttonArray[i][j].setBackground(Color.blue);
  69. }
  70. }
  71.  
  72. //////////////////////////////
  73.  
  74. //////////////////////////////
  75.  
  76.  
  77. public void paint(Graphics g) { for (int i = 0; i < 19; i++) {
  78. g.drawLine(25 + 25 * (i + 1), 150, 25 + 25 * (i + 1), 600);
  79. g.drawLine(50, 125 + 25 * (i + 1), 500, 125 + 25 * (i + 1)); } }
  80.  
  81.  
  82. //////////////////////////////
  83.  
  84. public static void main(String[] args) {
  85. DotsFrame application = new DotsFrame();
  86. application.setLayout(null);
  87. application.setVisible(true);
  88. }
  89.  
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement