Biblioteca Java - Blame information for rev 32
Subversion Repositories:
Rev | Author | Line No. | Line |
---|---|---|---|
32 | mihai | 1 | /* |
2 | * To change this license header, choose License Headers in Project Properties. | ||
3 | * To change this template file, choose Tools | Templates | ||
4 | * and open the template in the editor. | ||
5 | */ | ||
6 | package guidemo; | ||
7 | |||
8 | import java.awt.*; | ||
9 | import java.awt.event.*; | ||
10 | import javax.swing.*; | ||
11 | |||
12 | class CheckboxTest extends JFrame implements ItemListener { | ||
13 | |||
14 | private JLabel label1, label2; | ||
15 | private JCheckBox cbx1, cbx2, cbx3; | ||
16 | |||
17 | public CheckboxTest(String titlu) { | ||
18 | super(titlu); | ||
19 | initializare(); | ||
20 | setVisible(true); | ||
21 | |||
22 | } | ||
23 | |||
24 | public void initializare() { | ||
25 | setLayout(new GridLayout(5, 1)); | ||
26 | label1 = new JLabel("Componente :"); | ||
27 | label2 = new JLabel(""); | ||
28 | cbx1 = new JCheckBox("componenta 1"); | ||
29 | cbx2 = new JCheckBox("componenta 2"); | ||
30 | cbx3 = new JCheckBox("componenta 3"); | ||
31 | |||
32 | add(label1); | ||
33 | add(label2); | ||
34 | add(cbx1); | ||
35 | add(cbx2); | ||
36 | add(cbx3); | ||
37 | pack(); | ||
38 | setSize(200, 200); | ||
39 | |||
40 | cbx1.addItemListener(this); | ||
41 | cbx2.addItemListener(this); | ||
42 | cbx3.addItemListener(this); | ||
43 | } | ||
44 | |||
45 | //metoda interfetei ItemListener | ||
46 | public void itemStateChanged(ItemEvent e) { | ||
47 | StringBuffer ingrediente = new StringBuffer(); | ||
48 | if (cbx1.isSelected() == true) { | ||
49 | ingrediente.append(" componenta 1"); | ||
50 | } | ||
51 | if (cbx2.isSelected() == true) { | ||
52 | ingrediente.append(" componenta 2 "); | ||
53 | } | ||
54 | if (cbx3.isSelected() == true) { | ||
55 | ingrediente.append(" componenta 3 "); | ||
56 | } | ||
57 | label2.setText(ingrediente.toString()); | ||
58 | } | ||
59 | |||
60 | public static void main(String[] args) { | ||
61 | new CheckboxTest("titlu"); | ||
62 | } | ||
63 | } |