Java - MATRIZ BOTONES JFRAME CINE BUTACA

 
Vista:

MATRIZ BOTONES JFRAME CINE BUTACA

Publicado por Carolina (2 intervenciones) el 15/08/2018 21:49:01
Hola! Tengo una grandisima duda, por què mi matriz de botones creada dentro del codigo del JFrame solo muestra las columnas y no las filas? Me urge saber! Este es mi codigo, la matriz esta insertada en un JPanel. Aqui esta el codigo y al final sale la imagen de lo que muestra, como ven, no se hacen las filas de la matriz, solo se hace una! AYUDA!!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package projectcinema;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javafx.scene.paint.Color;
import javax.swing.JButton;
import javax.swing.SwingUtilities;
public class Butacas extends javax.swing.JFrame {
 
    private  int FILAS=3;
    private  int COLUMNAS=3;
    JButton[][]ASIENTOS;
 
    public Butacas() {
     initComponents();
    setMatrix();
    }
 
    public void setMatrix(){
        ASIENTOS= new JButton[FILAS][COLUMNAS];
        int x=30;
        int y=10;
        int counter = 1;
        for (int i = 0; i < FILAS; i++) {
            for (int j = 0; j < COLUMNAS; j++) {
                ASIENTOS[i][j]=new JButton();
                ASIENTOS[i][j].setBackground(java.awt.Color.green);
                ASIENTOS[i][j].setBounds(x,y,60,30);
                ASIENTOS[i][j].setText((counter < 10 ? "0" : "") + counter++);{
                ControladordeBotones bt= new ControladordeBotones();
                ASIENTOS[i][j].addActionListener(bt);
                ASIENTOS[i][j].addMouseListener(bt);
                panelasientos.add(ASIENTOS[i][j]);
                x+=60;
 
    }}}
x=30;
y+=30;
y=30;
    }
 
    private class ControladordeBotones implements ActionListener,MouseListener{
 
        @Override
        public void actionPerformed(ActionEvent e) {
          for (int i = 0; i < FILAS; i++) {
            for (int j = 0; j < COLUMNAS; j++) {
                if(e.getSource().equals (ASIENTOS[i][j])){
                    ASIENTOS[i][j].setBackground(java.awt.Color.red);
                }
                    }}}
 
        @Override
        public void mouseClicked(MouseEvent e) {
            for (int i = 0; i < FILAS; i++) {
            for (int j = 0; j < COLUMNAS; j++) {
                if(SwingUtilities.isRightMouseButton(e)){
                    ASIENTOS[i][j].setBackground(java.awt.Color.green);
 
            }}}
        }
 
        @Override
        public void mousePressed(MouseEvent e) {
 
        }
 
        @Override
        public void mouseReleased(MouseEvent e) {
 
        }
 
        @Override
        public void mouseEntered(MouseEvent e) {
 
        }
 
        @Override
        public void mouseExited(MouseEvent e) {
 
        }
    }
    /**.
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {
 
        panelasientos = new java.awt.Panel();
        jLabel3 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
 
        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        getContentPane().setLayout(null);
 
        panelasientos.setBackground(new java.awt.Color(0, 0, 0));
 
        jLabel3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/LoginPics/giphy.gif"))); // NOI18N
 
        javax.swing.GroupLayout panelasientosLayout = new javax.swing.GroupLayout(panelasientos);
        panelasientos.setLayout(panelasientosLayout);
        panelasientosLayout.setHorizontalGroup(
            panelasientosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelasientosLayout.createSequentialGroup()
                .addContainerGap(161, Short.MAX_VALUE)
                .addComponent(jLabel3)
                .addGap(119, 119, 119))
        );
        panelasientosLayout.setVerticalGroup(
            panelasientosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelasientosLayout.createSequentialGroup()
                .addContainerGap(209, Short.MAX_VALUE)
                .addComponent(jLabel3)
                .addContainerGap())
        );
 
        getContentPane().add(panelasientos);
        panelasientos.setBounds(120, 120, 580, 360);
 
        jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/LoginPics/mdwtr6dsubtdat7mg5c6j7dsyndzdm.gif"))); // NOI18N
        getContentPane().add(jLabel2);
        jLabel2.setBounds(160, 0, 580, 120);
 
        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/LoginPics/cine_1.jpg"))); // NOI18N
        getContentPane().add(jLabel1);
        jLabel1.setBounds(120, 0, 700, 620);
 
        pack();
    }// </editor-fold>                        
 
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Butacas.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Butacas.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Butacas.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Butacas.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>
 
        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Butacas().setVisible(true);
            }
        });
    }
 
    // Variables declaration - do not modify                     
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private java.awt.Panel panelasientos;
    // End of variables declaration                   
 
 
 
    }
butt
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

MATRIZ BOTONES JFRAME CINE BUTACA

Publicado por Carolina (2 intervenciones) el 16/08/2018 13:41:25
Gracias Tom! Vieras que todo el dia hice otro codigo y esta perfecto solo que no se lograr una parte de registro
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar