Java - JFrame JTextField y matrices en java

 
Vista:
sin imagen de perfil

JFrame JTextField y matrices en java

Publicado por walter (1 intervención) el 13/11/2015 21:11:39
no puedo leer y usar un valor en JTextField para dimensionar una matriz (con eclipse)

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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
package corte;
 
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.EventQueue;
import java.awt.GridLayout;
import java.awt.Rectangle;
 
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.Border;
import javax.swing.border.EmptyBorder;
import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
 
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
 
import javax.swing.BorderFactory;
import javax.swing.JTabbedPane;
import javax.swing.JLayeredPane;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.JButton;
 
public class CorteVinos extends JFrame {
 
	private JPanel contentPane;
//	private JTextField textField;
	private JLabel[] rotulo;
//	private JTextField[] texto;
	private JTextField litroscorte;
	private JTextField piletas;
	private int cantpiletas = 0;
	private JTextField[][] vectordatos;
 
 
 
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					CorteVinos frame = new CorteVinos();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}
 
	/**
	 * Create the frame.
	 */
	public CorteVinos() {
 
 
		setTitle("Cortes de Vinos");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 900, 500);
 
		//diseño de los menus del tablero
		JMenuBar menuBar = new JMenuBar();
		setJMenuBar(menuBar);
 
		JMenu MenuGral = new JMenu("Menu");
		menuBar.add(MenuGral);
 
		// menu salir accion de salida
		JMenuItem MenuItemSalir = new JMenuItem("Salir");
		MenuItemSalir.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				System.exit(0);
			}
		});
		MenuGral.add(MenuItemSalir);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
 
		JLabel LabelCorte = new JLabel("Corte en cm3");
		LabelCorte.setBounds(43, 44, 73, 14);
		contentPane.add(LabelCorte);
 
		litroscorte = new JTextField();
		litroscorte.setHorizontalAlignment(SwingConstants.RIGHT);
		litroscorte.setText("4800");
		litroscorte.setBounds(140, 41, 51, 20);
		contentPane.add(litroscorte);
		litroscorte.setColumns(10);
 
		JLabel CantidadDePiletas = new JLabel("Cantidad de Piletas");
		CantidadDePiletas.setBounds(314, 41, 110, 14);
		contentPane.add(CantidadDePiletas);
 
		piletas = new JTextField();
		piletas.setText("2");//------------este valor es el indice de mis filas en la matriz
		piletas.setHorizontalAlignment(SwingConstants.RIGHT);
		piletas.setColumns(10);
		piletas.setBounds(451, 38, 29, 20);
		contentPane.add(piletas);
 
		JButton btnCargarPiletas = new JButton("Cargar Piletas");
		btnCargarPiletas.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
 
 
				cantpiletas =Integer.parseInt(piletas.getText());// -------- aqui lo transformo en entero
				vectordatos = new JTextField[cantpiletas][11];//  ---------- aqui doy dimension a la matriz				
 
				for (int i = 0; i < cantpiletas; i++){   //  --------------------- y aqui es donde no funciona jeje
					for (int j = 0; j < vectordatos.length; j++){
						vectordatos[i][j] = new JTextField();
					}
				}
 
				for (int i = 0; i < cantpiletas ; i++){
					for (int j = 0; j < vectordatos.length; j++){
 
						vectordatos[i][j].setBounds(new Rectangle((j+1)*70, ((i+1)*133)-(110*(i)), 60, 20));
						contentPane.add(vectordatos[i][j]);
					}
				}
 
			}
		});
		btnCargarPiletas.setBounds(490, 35, 110, 23);
		contentPane.add(btnCargarPiletas);
 
 
//		cantpiletas =Integer.parseInt(piletas.getText());
//		vectordatos = new JTextField[11][11];				
//		
//		for (int i = 0; i < cantpiletas; i++){
//			for (int j = 0; j < vectordatos.length; j++){
//				vectordatos[i][j] = new JTextField();
//			}
//		}			
//
//
//		for (int i = 0; i < cantpiletas ; i++){
//			for (int j = 0; j < vectordatos.length; j++){
//
//				vectordatos[i][j].setBounds(new Rectangle((j+1)*70, ((i+1)*133)-(110*(i)), 60, 20));
//				contentPane.add(vectordatos[i][j]);
//			}
//		}
 
		// hacemos la pantalla
 
 
		rotulo = new JLabel[11];			//Declaración del array de etiquetas
//		texto = new JTextField[11];		//Declaración del array de cajas de texto
		rotulo[0] = new JLabel("N° Pileta");
		rotulo[1] = new JLabel(" Litros  ");
		rotulo[2] = new JLabel(" Alcohol ");
		rotulo[3] = new JLabel(" Alc Res ");
		rotulo[4] = new JLabel(" Ac Tot  ");
		rotulo[5] = new JLabel("Ac T Res ");
		rotulo[6] = new JLabel(" Volatil ");
		rotulo[7] = new JLabel("Vol T Res");
		rotulo[8] = new JLabel("   PH    ");
		rotulo[9] = new JLabel(" PH Tot  ");
		rotulo[10] = new JLabel("  Corte  ");
 
		for(int i = 0; i < rotulo.length; i++) {
			rotulo[i].setBounds(new Rectangle((i+1)*70, 113, 80, 14));
			contentPane.add(rotulo[i]);
		}
        //(7) ADICION DE LOS CONTROLES AL CONTENEDOR
 
 
		Border border = BorderFactory.createLineBorder(Color.blue, 1);
		Border border1 = BorderFactory.createLineBorder(Color.red, 1);
//
//
//		JLabel lblCorteEnCm = new JLabel("Corte en Cm3");
//		lblCorteEnCm.setBounds(10, 11, 80, 14);
////		Lblanco.add(lblCorteEnCm);
//
//		textField = new JTextField();
//		textField.setHorizontalAlignment(SwingConstants.TRAILING);
//		textField.setBounds(113, 8, 86, 20);
////		Lblanco.add(textField);
//		textField.setColumns(10);
//		// diseño del tablero
//		JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
//		tabbedPane.setBounds(10, 11, 864, 415);
//		contentPane.add(tabbedPane);
//
//		JLayeredPane Lblanco = new JLayeredPane();
//		tabbedPane.addTab("Blancos", null, Lblanco, null);
//
//		JLayeredPane Lrosado = new JLayeredPane();
//		tabbedPane.addTab("Rosados", null, Lrosado, null);
//
//		JLayeredPane Ltinto = new JLayeredPane();
//		tabbedPane.addTab("Tintos", null, Ltinto, null);
//
//		JLayeredPane Lmosto = new JLayeredPane();
//		tabbedPane.addTab("Mostos", null, Lmosto, null);
		  //rotulo[i].setBounds(new Rectangle((i+1)*70,113,  86, 20));
//      Lblanco.add(rotulo[i]);
//      Lblanco.add(texto[i]);
 
 
      //(6) PROPIEDADES DE LOS CONTROLES 
 
//      rotulo[i].setText("Dato "+(i+1));
 
 
 
 
      //rotulo[i].setBorder(border);
      //rotulo[i].setHorizontalAlignment(SwingConstants.CENTER);                
      //rotulo[i].setBounds(new Rectangle((i+1)*60,113,  86, 20));
      //rotulo[i].setBorder(border1);
	}
}
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