Okay. I am supposed to write the code for a button that will add a word to some sort of collection. The demands is that the word can only be saved in the collection if the word is unique. Also if the user tries to add more than 10 words there will be thrown an exception "CollectionFullException". I dont need to write the code for the exception just show how i use it.
This is what i got, how much does it suck?
public class JFrameFormTest extends javax.swing.JFrame {
DefaultListModel listModel = new DefaultListModel();
/**
* Creates new form JFrameFormTest
*/
public JFrameFormTest() {
initComponents();
initWordList();
}
private void initWordList() {
lstWords.setModel(listModel);
private void btnAddActionPerformed(java.awt.event.ActionEvent evt) {
List l = new List();
l.setWord(txt.Word.getText();
int index = listModel.getSize();
if (index > 10) {
.
listModel.addElement(s.toString());
} else {
JOptionPane.showMessageDialog(null, "List full");
}
from Newest questions tagged java - Stack Overflow http://ift.tt/1Lytlvo
via IFTTT
Aucun commentaire:
Enregistrer un commentaire