Java - Leer Base de Datos a un ComboBox y Mostrarlo

 
Vista:

Leer Base de Datos a un ComboBox y Mostrarlo

Publicado por luis cesar rojas chavez (2 intervenciones) el 08/11/2011 19:26:08
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
import java.io.File;
import java.io.FileWriter;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
import javax.swing.event.InternalFrameEvent;
import javax.swing.event.InternalFrameListener;
 
public class ESPECIALIDAD extends javax.swing.JInternalFrame implements InternalFrameListener {
    public static int cont=1;
    public ESPECIALIDAD() {
        initComponents();
        setLocation(20,15);
        setFrameIcon(new ImageIcon("img/especialidad.png"));
        //setSize(200, 200);
        addInternalFrameListener(this);
    }
 
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {
 
        jLabel1 = new javax.swing.JLabel();
        txt_codigo_curso = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        txt_nombre_especialidad = new javax.swing.JTextField();
        agregar = new javax.swing.JButton();
 
        setClosable(true);
        setIconifiable(true);
        setTitle("Especialidad");
 
        jLabel1.setText("Codigo");
 
        jLabel2.setText("Descripcion");
 
        agregar.setText("Agregar");
        agregar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                agregarActionPerformed(evt);
            }
        });
 
        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(35, 35, 35)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(agregar)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel1)
                            .addComponent(jLabel2))
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(27, 27, 27)
                                .addComponent(txt_nombre_especialidad, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addGap(27, 27, 27)
                                .addComponent(txt_codigo_curso, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                .addContainerGap(49, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txt_codigo_curso, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(txt_nombre_especialidad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(agregar)
                .addContainerGap(59, Short.MAX_VALUE))
        );
 
        pack();
    }// </editor-fold>                        
 
    void EscribirEspecialidad(String cod,String descr)
    {
        File f=new File("archivos/ESPECIALIDAD.txt");
        FileWriter fw=null;
 
        try {
            fw=new FileWriter(f,true);
            fw.write(cod+":"+descr+"\n");
 
        } catch (Exception e) {
            System.out.println("algo pasa, veamos ¿q es??");
        }finally{
            try {
                 fw.close();
            } catch (Exception e) {
                System.out.println("No ce cerro el archivo");
            }
        }
    }
    private void agregarActionPerformed(java.awt.event.ActionEvent evt) {
        String cod=txt_codigo_curso.getText();
        String descr=txt_nombre_especialidad.getText();
 
        EscribirEspecialidad(cod, descr);
        Limpiar();
    }
    void Limpiar()
    {
        JOptionPane.showMessageDialog(null,"Se agrego  "+cont+"°  Registro más");
        txt_codigo_curso.setText("");
        txt_nombre_especialidad.setText("");
        txt_codigo_curso.requestFocus();
        cont++;
    }
 
 
 
    // Variables declaration - do not modify                     
    private javax.swing.JButton agregar;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JTextField txt_codigo_curso;
    private javax.swing.JTextField txt_nombre_especialidad;
    // End of variables declaration                   
 
    @Override
    public void internalFrameOpened(InternalFrameEvent e) {}
 
    @Override
    public void internalFrameClosing(InternalFrameEvent e) {}
 
    @Override
    public void internalFrameClosed(InternalFrameEvent e)
    {
        BOOLEANO a=new BOOLEANO();
        a.setA(true);
 
    }
@Override
    public void internalFrameIconified(InternalFrameEvent e) {}
 
    @Override
    public void internalFrameDeiconified(InternalFrameEvent e) {}
    @Override
    public void internalFrameActivated(InternalFrameEvent e) {}
 
    @Override
    public void internalFrameDeactivated(InternalFrameEvent e) {}
}


Este es mi idea.. pero lo que tambien quiero es asignarle un precio a cada Item.
como aria esto? por favor alguien ayudeme con un ejemplo.
que se usando las paletas/diseño en java.
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