-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNewApplication.java
331 lines (265 loc) · 11.5 KB
/
NewApplication.java
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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
/*
* 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.
*/
/**
*
* @author abel
*/
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.*;
import java.util.ArrayList;
public class NewApplication extends javax.swing.JFrame {
/**
* Creates new form NewApplication
*/
Arbol a;
Arbol cursor;
public void actualiza(){
jPanel1.removeAll();
ArrayList aux=a.inOrden();
for(int i=0;i<aux.size();i++)
{ Nodo n=(Nodo)aux.get(i);
Arbol w=new Arbol(n);
JButton t=(JButton)w.raiz.valor;
t.setVisible(true);
jPanel1.add(t, new org.netbeans.lib.awtextra.AbsoluteConstraints(i*100,w.nivel()*100, 50, 30));
}
aux=a.inOrden();
for(int i=0;i<aux.size();i++)
{ Nodo n=(Nodo)aux.get(i);
JButton b1=(JButton)n.valor;
for(int j=0;j<n.hijos.size();j++)
{Nodo m=(Nodo)n.hijos.get(j);
JButton b2=(JButton)m.valor;
jPanel1.getGraphics().drawLine(b1.getLocation().x,b1.getLocation().y,
b2.getLocation().x,b2.getLocation().y);
}
}
eshoja.setText(cursor.eshoja()+"");
altura.setText(cursor.altura()+"");
peso.setText(cursor.peso()+"");
ancho.setText(cursor.ancho()+"");
nivel.setText(cursor.nivel()+"");
raiz.setText(((JButton)cursor.raiz.valor).getText());
}
public NewApplication() {
initComponents();
JButton x=new JButton();
cursor=a=new Arbol(x);
x.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
ActionPerformed(evt);
}
});
actualiza();
}
/**
* 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">//GEN-BEGIN:initComponents
private void initComponents() {
jScrollPane1 = new javax.swing.JScrollPane();
jPanel1 = new javax.swing.JPanel();
jPanel4 = new javax.swing.JPanel();
jPanel3 = new javax.swing.JPanel();
jButton1 = new javax.swing.JButton();
valor = new javax.swing.JTextField();
jButton2 = new javax.swing.JButton();
addhijo = new javax.swing.JTextField();
jButton3 = new javax.swing.JButton();
podarhijo = new javax.swing.JTextField();
jPanel2 = new javax.swing.JPanel();
jLabel5 = new javax.swing.JLabel();
raiz = new javax.swing.JLabel();
jLabel1 = new javax.swing.JLabel();
eshoja = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
altura = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
peso = new javax.swing.JLabel();
jLabel8 = new javax.swing.JLabel();
ancho = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
nivel = new javax.swing.JLabel();
jPanel5 = new javax.swing.JPanel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
jPanel1.addMouseListener(new java.awt.event.MouseAdapter() {
public void mousePressed(java.awt.event.MouseEvent evt) {
jPanel1MousePressed(evt);
}
});
jPanel1.addComponentListener(new java.awt.event.ComponentAdapter() {
public void componentResized(java.awt.event.ComponentEvent evt) {
jPanel1ComponentResized(evt);
}
});
jPanel1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
jScrollPane1.setViewportView(jPanel1);
getContentPane().add(jScrollPane1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 450, 540));
jPanel4.setLayout(new java.awt.BorderLayout());
jPanel3.setLayout(new java.awt.GridLayout(3, 2));
jButton1.setText("addValor(x)");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jPanel3.add(jButton1);
jPanel3.add(valor);
jButton2.setText("addHijo(x)");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
jPanel3.add(jButton2);
jPanel3.add(addhijo);
jButton3.setText("podarHijo(x)");
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton3ActionPerformed(evt);
}
});
jPanel3.add(jButton3);
jPanel3.add(podarhijo);
jPanel4.add(jPanel3, java.awt.BorderLayout.PAGE_START);
jPanel2.setLayout(new java.awt.GridLayout(6, 2, 3, 3));
jLabel5.setText("raiz");
jPanel2.add(jLabel5);
jPanel2.add(raiz);
jLabel1.setText("esHoja()");
jPanel2.add(jLabel1);
jPanel2.add(eshoja);
jLabel2.setText("altura()");
jPanel2.add(jLabel2);
jPanel2.add(altura);
jLabel3.setText("peso()");
jPanel2.add(jLabel3);
jPanel2.add(peso);
jLabel8.setText("ancho()");
jPanel2.add(jLabel8);
jPanel2.add(ancho);
jLabel4.setText("nivel()");
jPanel2.add(jLabel4);
jPanel2.add(nivel);
jPanel4.add(jPanel2, java.awt.BorderLayout.CENTER);
getContentPane().add(jPanel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(450, 0, 200, 300));
javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
jPanel5.setLayout(jPanel5Layout);
jPanel5Layout.setHorizontalGroup(
jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 200, Short.MAX_VALUE)
);
jPanel5Layout.setVerticalGroup(
jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 240, Short.MAX_VALUE)
);
getContentPane().add(jPanel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(450, 300, 200, 240));
pack();
}// </editor-fold>//GEN-END:initComponents
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
((JButton)cursor.raiz.valor).setText(valor.getText());
raiz.setText(valor.getText());
// TODO add your handling code here:
}//GEN-LAST:event_jButton1ActionPerformed
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
JButton X=new JButton(addhijo.getText());
X.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
ActionPerformed(evt);
}
});
cursor.addHijo(new Arbol(X));
actualiza();
// TODO add your handling code here:
}//GEN-LAST:event_jButton2ActionPerformed
private void jPanel1MousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jPanel1MousePressed
actualiza();
// TODO add your handling code here:
}//GEN-LAST:event_jPanel1MousePressed
private void jPanel1ComponentResized(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_jPanel1ComponentResized
actualiza();
// TODO add your handling code here:
}//GEN-LAST:event_jPanel1ComponentResized
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
a.podarHijo(cursor);
for(int i=0;i<a.raiz.hijos.size();i++)
new Arbol((Nodo)a.raiz.hijos.get(i)).podarHijo(cursor);
cursor=a;
jPanel1.repaint();
actualiza();
// TODO add your handling code here:
}//GEN-LAST:event_jButton3ActionPerformed
public void ActionPerformed(java.awt.event.ActionEvent evt)
{JButton b=((JButton)evt.getSource());
Nodo n=a.buscar(new Arbol(b));
cursor=new Arbol(n);
actualiza();
}
/**
* @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(NewApplication.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(NewApplication.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(NewApplication.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(NewApplication.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 NewApplication().setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JTextField addhijo;
private javax.swing.JLabel altura;
private javax.swing.JLabel ancho;
private javax.swing.JLabel eshoja;
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel8;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JPanel jPanel3;
private javax.swing.JPanel jPanel4;
private javax.swing.JPanel jPanel5;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JLabel nivel;
private javax.swing.JLabel peso;
private javax.swing.JTextField podarhijo;
private javax.swing.JLabel raiz;
private javax.swing.JTextField valor;
// End of variables declaration//GEN-END:variables
}