Witam pisze prosty notatnik w Javie juz wiekszosc mam za soba ale teraz utknełem na
zmianie koloru tła i tekstu (w programie mam klase rysujaca tak ze na menu mam obok wyboru koloru np kwadracik z danym kolorem)
wrzucam oczywiscie tylko istotne fragmenty kodu
public class Notepad extends JFrame implements ActionListener {
private Icon[] icons = { new IconA(Color.blue), new IconA(Color.yellow),new IconA(Color.orange)}
//elementy klasy rysujacej kolorowe kwadraciki
Notepad() {
JMenuBar menuBar = new JMenuBar();
setJMenuBar(menuBar);
List<JMenuItem> colors2 = createMenuColors(" Blue", "Yellow","Orange", ); background
List<JMenuItem> colors2 = createMenuColors(" Blue", "Yellow","Orange", ); foreground
for (JMenuItem mi : colors) {
mi.addActionListener(this);
foreground.add(mi);
}
for (JMenuItem m : colors2) {
//petle tworzace samo menu
m.addActionListener(this); //wyglada to tak np ze mamy options->background>wyborkoloru
background.add(m);
}
options.add(foreground);
options.add(background);
public void actionPerformed(ActionEvent e) {
**//Tu powinnna byc obsluga actionListnera **
}
private List<JMenuItem> createMenuColors(String... items) {
List<JMenuItem> list = new ArrayList<JMenuItem>();
int x = 0;
for (String s : items) {
JMenuItem a = new JMenuItem(s, icons[x]);
a.addActionListener(this);
list.add(a);
x++;
} //to metoda tworzaca menu+kolorowy kwadracik
return list;
Macie moze jakies pomysly jak napisac obsluge ActionListnera
Pewnie jest to wmiare proste ale chyba juz za dlugo siedze nad tym programem
z gory dzieki za wszelkie rady.