Toon posts:

[JAVA] combobox

Pagina: 1
Acties:
  • 48 views sinds 30-01-2008

Verwijderd

Topicstarter
Ik heb het volgende:
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
combobox = new JComboBox();
combobox.addItem(v1="/Program Files/Winword.exe");
combobox.addItem(v2="/Program Files/Powerpnt.exe");
combobox.setBounds(110, 140, 250, 25);
c.add(combobox);

private class ButtonHandler  implements ActionListener {
     public void actionPerformed( ActionEvent e )
     {
     try
         {
         Runtime.getRuntime().exec(v1);
         }
         catch (java.io.IOException a) {}
        }
      }

Hoe spreek ik de inhoud van een combobox aan?
En ja ik weet dat ik nou alleen de string v1 aanspreek maar nu wil ik dus de geselecteerde string uit de combobox aanspreken.

Alvast bedankt

De Nutcase, :7

  • Alarmnummer
  • Registratie: Juli 2001
  • Laatst online: 09-07-2024

Alarmnummer

-= Tja =-

http://java.sun.com/j2se/1.4/docs/api/

en dan even bij de getSelectedXXX kijken.. daar vind je je antwoord op je vraag.

opm1:
deze constructie is vrij ongebruikelijk:

combobox.addItem(v1="/Program Files/Winword.exe");

je kan beter dit doen:
String v1 = "/Program Files/Winword.exe";
comboBox.addItem(v1);

opm2:
Hou er nu rekening mee dat je working dir c:\ moet zijn anders krijg je die relatieve file verwijzing niet goed
"\Program Files\Winword.exe"

[edit] foutje verwijderd :z

opm3:

een lege catch is not done!!!

catch (java.io.IOException a) {}

doe dan ff:
catch (java.io.IOException a) {
a.printStackTrace();
}

Dan weer je of er iets fout gaat..

Verwijderd

Topicstarter
Ik weet a dat ik iets verkeerd doe anders had ie al gewerkt :)

  • D2k
  • Registratie: Januari 2001
  • Laatst online: 31-08 10:19

D2k

dubbelpost

Doet iets met Cloud (MS/IBM)


Dit topic is gesloten.