2.2 Programma kodi
244.
public class NewJFrame extends javax.swing.JFrame {
245.
246.
public NewJFrame() {
247.
initComponents();
248.
}
249.
250.
/**
251.
* This method is called from within the constructor to initialize the form.
252.
* WARNING: Do NOT modify this code. The content of this method is always
253.
* regenerated by the Form Editor.
254.
*/
255.
@SuppressWarnings("unchecked")
256.
//
257.
private void initComponents() {
258.
259.
jScrollPane1 = new javax.swing.JScrollPane();
260.
jList1 = new javax.swing.JList();
261.
jButton1 = new javax.swing.JButton();
262.
263.
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
264.
265.
jScrollPane1.setFont(new java.awt.Font("Dialog", 0, 18)); // NOI18N
266.
267.
jList1.setModel(new javax.swing.AbstractListModel() {
268.
String[] strings = { "Englberg","Nokia","Samsung", "Apple", "Xiomi", "Oppo", "Huawey" };
269.
public int getSize() { return strings.length; }
270.
public Object getElementAt(int i) { return strings[i]; }
271.
});
272.
jScrollPane1.setViewportView(jList1);
273.
274.
jButton1.setText("Your selection: ");
275.
jButton1.addActionListener(new java.awt.event.ActionListener() {
276.
public void actionPerformed(java.awt.event.ActionEvent evt) {
277.
jButton1ActionPerformed(evt);
278.
}
279.
});
280.
281.
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
282.
getContentPane().setLayout(layout);
283.
layout.setHorizontalGroup(
284.
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
285.
.addGroup(layout.createSequentialGroup()
286.
.addGap(35, 35, 35)
287.
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 73,
javax.swing.GroupLayout.PREFERRED_SIZE)
288.
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 48,
Short.MAX_VALUE)
289.
.addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 218,
javax.swing.GroupLayout.PREFERRED_SIZE)
290.
.addGap(26, 26, 26))
291.
);
292.
layout.setVerticalGroup(
293.
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
294.
.addGroup(layout.createSequentialGroup()
295.
.addGap(57, 57, 57)
296.
.addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 36,
javax.swing.GroupLayout.PREFERRED_SIZE)
297.
.addGap(0, 44, Short.MAX_VALUE))
298.
.addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING)
299.
);
300.
301.
pack();
302.
}//
303.
304.
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
305.
jButton1.setText("Your selection: " + jList1.getSelectedValue());
306.
}
307.
308.
/**
309.
* @param args
the command line arguments
310.
*/
311.
public static void main(String args[]) {
312.
/* Set the Nimbus look and feel */
313.
//
314.
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
315.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
316.
*/
317.
try {
318.
for (javax.swing.UIManager.LookAndFeelInfo info :
javax.swing.UIManager.getInstalledLookAndFeels()) {
319.
if ("Nimbus".equals(info.getName())) {
320.
javax.swing.UIManager.setLookAndFeel(info.getClassName());
321.
break;
322.
}
323.
}
324.
} catch (ClassNotFoundException ex) {
325.
java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
326.
} catch (InstantiationException ex) {
327.
java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
328.
} catch (IllegalAccessException ex) {
329.
java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
330.
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
331.
java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
332.
}
333.
//
334.
335.
/* Create and display the form */
336.
java.awt.EventQueue.invokeLater(new Runnable() {
337.
public void run() {
338.
new NewJFrame().setVisible(true);
339.
}
340.
});
341.
}
342.
343.
// Variables declaration - do not
modify
344.
private javax.swing.JButton jButton1;
345.
private javax.swing.JList jList1;
346.
private javax.swing.JScrollPane jScrollPane1;
347.
// End of variables declaration
348.
}
2.2 Programma aynasinan screenshotlar: