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 ChoiceTest extends JFrame implements ItemListener { | ||
13 | private JLabel label; | ||
14 | private JComboBox culori; | ||
15 | |||
16 | public ChoiceTest(String titlu) { | ||
17 | super(titlu); | ||
18 | initializare(); | ||
19 | setVisible(true); | ||
20 | } | ||
21 | |||
22 | public void initializare() { | ||
23 | setLayout(new GridLayout(4, 1)); | ||
24 | |||
25 | label = new JLabel("Alegeti culoarea"); | ||
26 | label.setOpaque(true); | ||
27 | label.setBackground(Color.red); | ||
28 | |||
29 | culori = new JComboBox(); | ||
30 | culori.addItem("Rosu"); | ||
31 | culori.addItem("Verde"); | ||
32 | culori.addItem("Albastru"); | ||
33 | culori.setSelectedIndex(0); | ||
34 | |||
35 | add(label); | ||
36 | add(culori); | ||
37 | pack(); | ||
38 | setSize(200, 100); | ||
39 | |||
40 | culori.addItemListener(this); | ||
41 | } | ||
42 | |||
43 | //metoda interfetei ItemListener | ||
44 | public void itemStateChanged(ItemEvent e) { | ||
45 | switch (culori.getSelectedIndex()) { | ||
46 | case 0: | ||
47 | label.setBackground(Color.red); | ||
48 | break; | ||
49 | case 1: | ||
50 | label.setBackground(Color.green); | ||
51 | break; | ||
52 | case 2: | ||
53 | label.setBackground(Color.blue); | ||
54 | } | ||
55 | } | ||
56 | |||
57 | public static void main(String[] args) { | ||
58 | new ChoiceTest("test"); | ||
59 | } | ||
60 | } |