Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.BorderLayout;
- import java.awt.Color;
- import java.awt.FlowLayout;
- import java.awt.Graphics;
- import java.awt.GridLayout;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import javax.swing.*;
- public class DotsFrame extends JFrame {
- //////////////////////////////
- private JButton[][] buttonArray;
- ///////////////////////////////
- //////////////////////////////
- public DotsFrame() {
- super("Точки");
- setSize(550, 650);
- setDefaultCloseOperation(EXIT_ON_CLOSE);
- buttonArray = new JButton[19][19];
- for (int i = 0; i < 19; i++) {
- for (int j = 0; j < 19; j++) {
- buttonArray[i][j] = new JButton("" + (i + 1));
- }
- }
- for (int i = 0; i < 19; i++) {
- for (int j = 0; j < 19; j++) {
- buttonArray[i][j].setBounds(12 + 25 * (i + 1), 90 + 25 * (j + 1), 10, 10);
- //buttonArray[i][j].setVisible(true);
- buttonArray[i][j].setActionCommand(i + ":" + j);
- buttonArray[i][j].addActionListener(new ButtonEventListener());
- add(buttonArray[i][j]);
- }
- }
- }
- class ButtonEventListener implements ActionListener {
- @Override
- public void actionPerformed(ActionEvent e) {
- String com = e.getActionCommand();
- String comA = "";
- String comB = "";
- boolean flag = false;
- int i = 0;
- int j = 0;
- for (int ii = 0; ii < com.length() - 1; ii++) {
- if (com.charAt(ii) == ':') {
- flag = true;
- }
- if (flag) {
- comB += com.charAt(ii + 1);
- } else {
- comA += com.charAt(ii);
- }
- }
- i = Integer.valueOf(comA);
- j = Integer.valueOf(comB);
- System.out.println(i + ":" + j);
- buttonArray[i][j].setBackground(Color.blue);
- }
- }
- //////////////////////////////
- //////////////////////////////
- public void paint(Graphics g) { for (int i = 0; i < 19; i++) {
- g.drawLine(25 + 25 * (i + 1), 150, 25 + 25 * (i + 1), 600);
- g.drawLine(50, 125 + 25 * (i + 1), 500, 125 + 25 * (i + 1)); } }
- //////////////////////////////
- public static void main(String[] args) {
- DotsFrame application = new DotsFrame();
- application.setLayout(null);
- application.setVisible(true);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement