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
| import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.DefaultListModel;
/**
* Created by x on 17.01.17.
*/
public class GuiForm extends JFrame{
private JList lstTaches;
private JPanel panel1;
private JButton btnAjouter;
private JTextArea textSaisie;
private JButton btnSupprimer;
private DefaultListModel<String> model;
public GuiForm() {
model = new DefaultListModel<>();
lstTaches.setModel(model);
btnAjouter.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (!textSaisie.getText().isEmpty()){
model.addElement(textSaisie.getText());
textSaisie.setText("");
}
}
});
btnSupprimer.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (METHODE QUI DIT QUE SI J'AI SELECTIONNE QUELQUE CHOSE DANS LA JLIST,
ALORS JE PEUX CLIQUER SUR SUPPRIMER'){
METHODE QUI SUPPRIME LA TACHE DE LA JLIST;
}
}
}
});
}
public static void main(String[] args) {
JFrame frame = new JFrame("GuiForm");
GuiForm gf= new GuiForm();
frame.setContentPane(gf.panel1);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}
@Override
protected void frameInit() {
super.frameInit();
}
} |