BIODATA MAHASISWA
Kali ini kita membuat sebuah aplikasi dektop dengan judul Biodata Mahasiswa
adapun properti yang digunakan dalam perancangan formnya adalah :
1. Nama Mahasiswa —–> (Text Field)
2. Jenis Kelamin ——–> (Radio Button)
3. Agama ————> (ComboBox)
4. Alamat ———> (Text Area)
5.Hobby ———-> (Text Field)
6. email ———–> (Text Field )
7. No. Telp ——–> (Text Field)
8. Tombol Proses ——> (JButton)
9. Tombol Bersihkan ——> (JButton) untuk memberihkan teks
10. Tombol Keluar ——–> (JButton)
Pada tombol keluar ini dibuat konfirmasi apakah program ini ingin di keluarkan atau tidak.
bentuk formnya dapat dilihat pada gambar berikut :
Listing Program
Output Program
Kali ini kita membuat sebuah aplikasi dektop dengan judul Biodata Mahasiswa
adapun properti yang digunakan dalam perancangan formnya adalah :
1. Nama Mahasiswa —–> (Text Field)
2. Jenis Kelamin ——–> (Radio Button)
3. Agama ————> (ComboBox)
4. Alamat ———> (Text Area)
5.Hobby ———-> (Text Field)
6. email ———–> (Text Field )
7. No. Telp ——–> (Text Field)
8. Tombol Proses ——> (JButton)
9. Tombol Bersihkan ——> (JButton) untuk memberihkan teks
10. Tombol Keluar ——–> (JButton)
Pada tombol keluar ini dibuat konfirmasi apakah program ini ingin di keluarkan atau tidak.
bentuk formnya dapat dilihat pada gambar berikut :
Listing Program
001 | import javax.swing.ButtonGroup; |
002 | import javax.swing.JOptionPane; |
003 |
004 | /** |
005 | * |
006 | * @author Ade Akbar |
007 | */ |
008 | public class Program2 extends javax.swing.JFrame { |
009 | private ButtonGroup gabung; |
010 | /** Creates new form Program2 */ |
011 | public Program2() { |
012 |
013 | super ( "Biodata Mahasiswa" ); |
014 | initComponents(); |
015 | gabung= new ButtonGroup(); |
016 | gabung.add(btlaki); |
017 | gabung.add(btpr); |
018 |
019 | } |
020 |
021 | @SuppressWarnings ( "unchecked" ) |
022 | // |
023 | private void initComponents() { |
024 |
025 | panel1 = new javax.swing.JPanel(); |
026 | jLabel1 = new javax.swing.JLabel(); |
027 | txtnama = new javax.swing.JTextField(); |
028 | jLabel2 = new javax.swing.JLabel(); |
029 | btlaki = new javax.swing.JRadioButton(); |
030 | btpr = new javax.swing.JRadioButton(); |
031 | box = new javax.swing.JComboBox(); |
032 | jLabel3 = new javax.swing.JLabel(); |
033 | jLabel5 = new javax.swing.JLabel(); |
034 | jLabel7 = new javax.swing.JLabel(); |
035 | txtemail = new javax.swing.JTextField(); |
036 | jLabel6 = new javax.swing.JLabel(); |
037 | txthobi = new javax.swing.JTextField(); |
038 | jScrollPane1 = new javax.swing.JScrollPane(); |
039 | jTextArea1 = new javax.swing.JTextArea(); |
040 | jLabel8 = new javax.swing.JLabel(); |
041 | txtnotlp = new javax.swing.JTextField(); |
042 | jButton1 = new javax.swing.JButton(); |
043 | exit = new javax.swing.JButton(); |
044 | jButton2 = new javax.swing.JButton(); |
045 | jLabel4 = new javax.swing.JLabel(); |
046 | jPanel1 = new javax.swing.JPanel(); |
047 | jScrollPane2 = new javax.swing.JScrollPane(); |
048 | output1 = new javax.swing.JTextArea(); |
049 |
050 | setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); |
051 |
052 | panel1.setBorder(javax.swing.BorderFactory.createTitledBorder( "Data Mahasiswa" )); |
053 | panel1.setFont( new java.awt.Font( "Times New Roman" , 1 , 14 )); // NOI18N |
054 | panel1.setName( "panel1" ); // NOI18N |
055 |
056 | jLabel1.setFont( new java.awt.Font( "Tahoma" , 1 , 12 )); // NOI18N |
057 | jLabel1.setText( "Nama" ); |
058 | jLabel1.setName( "jLabel1" ); // NOI18N |
059 |
060 | txtnama.setName( "txtnama" ); // NOI18N |
061 |
062 | jLabel2.setFont( new java.awt.Font( "Tahoma" , 1 , 12 )); // NOI18N |
063 | jLabel2.setText( "Jenis Kelamin" ); |
064 | jLabel2.setName( "jLabel2" ); // NOI18N |
065 |
066 | btlaki.setFont( new java.awt.Font( "Tahoma" , 1 , 12 )); // NOI18N |
067 | btlaki.setText( "Laki" ); |
068 | btlaki.setName( "btlaki" ); // NOI18N |
069 |
070 | btpr.setFont( new java.awt.Font( "Tahoma" , 1 , 12 )); // NOI18N |
071 | btpr.setText( "Perempuan" ); |
072 | btpr.setName( "btpr" ); // NOI18N |
073 |
074 | box.setFont( new java.awt.Font( "Tahoma" , 1 , 12 )); // NOI18N |
075 | box.setModel( new javax.swing.DefaultComboBoxModel( new String[] { "Islam" , "KritenKhatolik" , "Kristen Protestan" , "Hindu" , "Budha" , "Konghucu" })); |
076 | box.setName( "box" ); // NOI18N |
077 |
078 | jLabel3.setFont( new java.awt.Font( "Tahoma" , 1 , 12 )); // NOI18N |
079 | jLabel3.setText( "Agama" ); |
080 | jLabel3.setName( "jLabel3" ); // NOI18N |
081 |
082 | jLabel5.setFont( new java.awt.Font( "Tahoma" , 1 , 12 )); // NOI18N |
083 | jLabel5.setText( "Alamat" ); |
084 | jLabel5.setName( "jLabel5" ); // NOI18N |
085 |
086 | jLabel7.setFont( new java.awt.Font( "Tahoma" , 1 , 12 )); // NOI18N |
087 | jLabel7.setText( "Email" ); |
088 | jLabel7.setName( "jLabel7" ); // NOI18N |
089 |
090 | txtemail.setName( "txtemail" ); // NOI18N |
091 |
092 | jLabel6.setFont( new java.awt.Font( "Tahoma" , 1 , 12 )); // NOI18N |
093 | jLabel6.setText( "Hobi" ); |
094 | jLabel6.setName( "jLabel6" ); // NOI18N |
095 |
096 | txthobi.setName( "txthobi" ); // NOI18N |
097 |
098 | jScrollPane1.setName( "jScrollPane1" ); // NOI18N |
099 |
100 | jTextArea1.setColumns( 20 ); |
101 | jTextArea1.setRows( 5 ); |
102 | jTextArea1.setName( "jTextArea1" ); // NOI18N |
103 | jScrollPane1.setViewportView(jTextArea1); |
104 |
105 | jLabel8.setFont( new java.awt.Font( "Tahoma" , 1 , 12 )); // NOI18N |
106 | jLabel8.setText( "No Telepon" ); |
107 | jLabel8.setName( "jLabel8" ); // NOI18N |
108 |
109 | txtnotlp.setName( "txtnotlp" ); // NOI18N |
110 |
111 | jButton1.setFont( new java.awt.Font( "Tahoma" , 1 , 14 )); // NOI18N |
112 | jButton1.setText( "PROSES" ); |
113 | jButton1.setName( "jButton1" ); // NOI18N |
114 | jButton1.addActionListener( new java.awt.event.ActionListener() { |
115 | public void actionPerformed(java.awt.event.ActionEvent evt) { |
116 | jButton1ActionPerformed(evt); |
117 | } |
118 | }); |
119 |
120 | exit.setFont( new java.awt.Font( "Tahoma" , 1 , 14 )); // NOI18N |
121 | exit.setText( "KELUAR" ); |
122 | exit.setName( "exit" ); // NOI18N |
123 | exit.addActionListener( new java.awt.event.ActionListener() { |
124 | public void actionPerformed(java.awt.event.ActionEvent evt) { |
125 | exitActionPerformed(evt); |
126 | } |
127 | }); |
128 |
129 | jButton2.setFont( new java.awt.Font( "Tahoma" , 1 , 14 )); // NOI18N |
130 | jButton2.setText( "Bersihkan" ); |
131 | jButton2.setName( "jButton2" ); // NOI18N |
132 | jButton2.addActionListener( new java.awt.event.ActionListener() { |
133 | public void actionPerformed(java.awt.event.ActionEvent evt) { |
134 | jButton2ActionPerformed(evt); |
135 | } |
136 | }); |
137 |
138 | javax.swing.GroupLayout panel1Layout = new javax.swing.GroupLayout(panel1); |
139 | panel1.setLayout(panel1Layout); |
140 | panel1Layout.setHorizontalGroup( |
141 | panel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) |
142 | .addGroup(panel1Layout.createSequentialGroup() |
143 | .addGroup(panel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) |
144 | .addComponent(jLabel1) |
145 | .addComponent(jLabel2) |
146 | .addComponent(jLabel5) |
147 | .addComponent(jLabel6) |
148 | .addComponent(jLabel3) |
149 | .addComponent(jLabel7) |
150 | .addComponent(jLabel8)) |
151 | .addGap( 18 , 18 , 18 ) |
152 | .addGroup(panel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) |
153 | .addGroup(panel1Layout.createSequentialGroup() |
154 | .addComponent(txthobi, javax.swing.GroupLayout.DEFAULT_SIZE, 539 , Short.MAX_VALUE) |
155 | .addContainerGap()) |
156 | .addComponent(box,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE) |
157 | .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 549 , Short.MAX_VALUE) |
158 | .addGroup(panel1Layout.createSequentialGroup() |
159 | .addComponent(btlaki) |
160 | .addGap( 18 , 18 , 18 ) |
161 | .addComponent(btpr)) |
162 | .addComponent(txtnama, javax.swing.GroupLayout.DEFAULT_SIZE, 549 , Short.MAX_VALUE) |
163 | .addGroup(panel1Layout.createSequentialGroup() |
164 | .addComponent(txtemail, javax.swing.GroupLayout.DEFAULT_SIZE, 539 , Short.MAX_VALUE) |
165 | .addContainerGap()) |
166 | .addGroup(panel1Layout.createSequentialGroup() |
167 | .addComponent(txtnotlp, javax.swing.GroupLayout.DEFAULT_SIZE, 539 , Short.MAX_VALUE) |
168 | .addContainerGap()))) |
169 | .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panel1Layout.createSequentialGroup() |
170 | .addContainerGap( 310 , Short.MAX_VALUE) |
171 | .addComponent(jButton1) |
172 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) |
173 | .addComponent(jButton2) |
174 | .addGap( 13 , 13 , 13 ) |
175 | .addComponent(exit) |
176 | .addGap( 36 , 36 , 36 )) |
177 | ); |
178 | panel1Layout.setVerticalGroup( |
179 | panel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) |
180 | .addGroup(panel1Layout.createSequentialGroup() |
181 | .addContainerGap() |
182 | .addGroup(panel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) |
183 | .addComponent(jLabel1) |
184 | .addComponent(txtnama,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)) |
185 | .addGap( 18 , 18 , 18 ) |
186 | .addGroup(panel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) |
187 | .addComponent(jLabel2) |
188 | .addComponent(btlaki) |
189 | .addComponent(btpr)) |
190 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) |
191 | .addGroup(panel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) |
192 | .addComponent(jLabel3) |
193 | .addComponent(box,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)) |
194 | .addGap( 12 , 12 , 12 ) |
195 | .addGroup(panel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) |
196 | .addComponent(jLabel5) |
197 | .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 61 , javax.swing.GroupLayout.PREFERRED_SIZE)) |
198 | .addGroup(panel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) |
199 | .addGroup(panel1Layout.createSequentialGroup() |
200 | .addGap( 11 , 11 , 11 ) |
201 | .addComponent(jLabel6)) |
202 | .addGroup(panel1Layout.createSequentialGroup() |
203 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) |
204 | .addComponent(txthobi,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))) |
205 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) |
206 | .addGroup(panel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) |
207 | .addComponent(txtemail,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE) |
208 | .addComponent(jLabel7)) |
209 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) |
210 | .addGroup(panel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) |
211 | .addComponent(txtnotlp,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE) |
212 | .addComponent(jLabel8)) |
213 | .addGap( 18 , 18 , 18 ) |
214 | .addGroup(panel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) |
215 | .addComponent(exit) |
216 | .addComponent(jButton1) |
217 | .addComponent(jButton2)) |
218 | .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) |
219 | ); |
220 |
221 | jLabel4.setFont( new java.awt.Font( "Tahoma" , 3 , 14 )); // NOI18N |
222 | jLabel4.setText( "FORM BIODATA" ); |
223 | jLabel4.setName( "jLabel4" ); // NOI18N |
224 |
225 | jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder( "output" )); |
226 | jPanel1.setFont( new java.awt.Font( "Tahoma" , 1 , 12 )); // NOI18N |
227 | jPanel1.setName( "jPanel1" ); // NOI18N |
228 |
229 | jScrollPane2.setName( "jScrollPane2" ); // NOI18N |
230 |
231 | output1.setColumns( 20 ); |
232 | output1.setRows( 5 ); |
233 | output1.setName( "output1" ); // NOI18N |
234 | jScrollPane2.setViewportView(output1); |
235 |
236 | javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); |
237 | jPanel1.setLayout(jPanel1Layout); |
238 | jPanel1Layout.setHorizontalGroup( |
239 | jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) |
240 | .addGroup(jPanel1Layout.createSequentialGroup() |
241 | .addContainerGap() |
242 | .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 542 , Short.MAX_VALUE) |
243 | .addContainerGap()) |
244 | ); |
245 | jPanel1Layout.setVerticalGroup( |
246 | jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) |
247 | .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 107 , Short.MAX_VALUE) |
248 | ); |
249 |
250 | javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); |
251 | getContentPane().setLayout(layout); |
252 | layout.setHorizontalGroup( |
253 | layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) |
254 | .addGroup(layout.createSequentialGroup() |
255 | .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) |
256 | .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) |
257 | .addComponent(jPanel1,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE) |
258 | .addComponent(panel1,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE) |
259 | .addComponent(jLabel4))) |
260 | ); |
261 | layout.setVerticalGroup( |
262 | layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) |
263 | .addGroup(layout.createSequentialGroup() |
264 | .addContainerGap( 16 , Short.MAX_VALUE) |
265 | .addComponent(jLabel4) |
266 | .addGap( 18 , 18 , 18 ) |
267 | .addComponent(panel1,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE) |
268 | .addGap( 18 , 18 , 18 ) |
269 | .addComponent(jPanel1,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)) |
270 | ); |
271 |
272 | jPanel1.getAccessibleContext().setAccessibleName( "" ); |
273 |
274 | pack(); |
275 | } // |
276 |
277 | private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { |
278 | // TODO add your handling code here: |
279 |
280 | String JK, agama; |
281 | if (btlaki.isSelected()) |
282 | { |
283 | JK = "Laki-laki" ; |
284 | } |
285 | else |
286 | { |
287 | JK= "Perempuan" ; |
288 |
289 | } |
290 | agama = box.getSelectedItem().toString(); |
291 |
292 | output1.setText( "Nama : " + txtnama.getText() + "\n" + "Jenis Kelamin :" + JK + "\n" + "Agama :" + agama + "\n" + "Alamat : " +jTextArea1.getText()+ "\n" |
293 | + "Hobi :" +txthobi.getText() + "\n" + "Email :" + txtemail.getText() + "\n" + "No Telepon :" +txtnotlp.getText()); |
294 | } |
295 |
296 | private void exitActionPerformed(java.awt.event.ActionEvent evt) { |
297 | // TODO add your handling code here: |
298 | int mesage=JOptionPane. showConfirmDialog( null , "Apakah Anda Yakin Keluar" ); |
299 | if (mesage==JOptionPane.OK_OPTION) |
300 | System.exit( 1 ); |
301 | } |
302 |
303 | private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) { |
304 | // TODO add your handling code here: |
305 | txtnama.setText( null ); |
306 | jTextArea1.setText( null ); |
307 | txthobi.setText( null ); |
308 | txtemail.setText( null ); |
309 | } |
310 | /** |
311 | * @param args the command line arguments |
312 | */ |
313 | public static void main(String args[]) { |
314 | /* Set the Nimbus look and feel */ |
315 | // |
316 | /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. |
317 | * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html |
318 | */ |
319 | try { |
320 | for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { |
321 | if ("Nimbus".equals(info.getName())) { |
322 | javax.swing.UIManager.setLookAndFeel(info.getClassName()); |
323 | break; |
324 | } |
325 | } |
326 | } catch (ClassNotFoundException ex) { |
327 | java.util.logging.Logger.getLogger(Program2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); |
328 | } catch (InstantiationException ex) { |
329 | java.util.logging.Logger.getLogger(Program2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); |
330 | } catch (IllegalAccessException ex) { |
331 | java.util.logging.Logger.getLogger(Program2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); |
332 | } catch (javax.swing.UnsupportedLookAndFeelException ex) { |
333 | java.util.logging.Logger.getLogger(Program2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); |
334 | } |
335 | // |
336 |
337 | /* Create and display the form */ |
338 | java.awt.EventQueue.invokeLater( new Runnable() { |
339 |
340 | public void run() { |
341 | new Program2().setVisible( true ); |
342 | } |
343 | }); |
344 | } |
345 | // Variables declaration - do not modify |
346 | private javax.swing.JComboBox box; |
347 | private javax.swing.JRadioButton btlaki; |
348 | private javax.swing.JRadioButton btpr; |
349 | private javax.swing.JButton exit; |
350 | private javax.swing.JButton jButton1; |
351 | private javax.swing.JButton jButton2; |
352 | private javax.swing.JLabel jLabel1; |
353 | private javax.swing.JLabel jLabel2; |
354 | private javax.swing.JLabel jLabel3; |
355 | private javax.swing.JLabel jLabel4; |
356 | private javax.swing.JLabel jLabel5; |
357 | private javax.swing.JLabel jLabel6; |
358 | private javax.swing.JLabel jLabel7; |
359 | private javax.swing.JLabel jLabel8; |
360 | private javax.swing.JPanel jPanel1; |
361 | private javax.swing.JScrollPane jScrollPane1; |
362 | private javax.swing.JScrollPane jScrollPane2; |
363 | private javax.swing.JTextArea jTextArea1; |
364 | private javax.swing.JTextArea output1; |
365 | private javax.swing.JPanel panel1; |
366 | private javax.swing.JTextField txtemail; |
367 | private javax.swing.JTextField txthobi; |
368 | private javax.swing.JTextField txtnama; |
369 | private javax.swing.JTextField txtnotlp; |
370 | // End of variables declaration |
371 | } |