Indholdet af en Choicebox fordobles!!!!!!!!!!!!
Jeg har problemmer med en choicebox.problemmet er at jeg i constructoren adder indholdt af et array til choiceboxen.
det virker også første gang.
men hver gang jeg lukker Framen og åbner den igen, bliver indholdet fordoblet!!!
Jeg har forsøgt at med removeAllElements() i vectoren, men det virker ikke??
Her er kildekoden:
import javax.swing. event.*;
import javax. swing.*;
import java.awt.event.*;
import java.awt.*;
import java.util.Vector;
import java.util.Arrays;
import java.rmi.*;
import java.rmi.server.*;
// Class Administrator
public class Administrator extends Frame
{
final int MenuBarHeight = 19;
// Component Declaration
private AdgangTilRemoteObjekt adgang = AdgangTilRemoteObjekt.adgang_instance();
public Panel genstand_panel;
public List genstand_list;
public Label genstand_label;
public Choice genstand_choice;
public Label help_label;
public Panel igang_auktion_panel;
public Label reg_nr_label;
public Label varenavn_label;
public Label beskrivelse_label;
public Label mindstepris_label;
public Label billedehelp_label;
public Label hoejst_bud_label;
public TextField hoejste_textfield;
public TextArea beskrivelse_textarea;
public TextField mindstepris_textfield;
public TextField varenr_textfield;
public TextField reg_nr_textfield;
public Label igang_label;
public Label dkr_label;
public Label dkr2_label;
public Panel funktioner_panel;
public Label fald_til_ro_label;
public TextField fald_til_ro_textfield;
public Label sekunder_label;
public Button luk_knap;
public Button opdater_knap;
public Label start_label;
public Label annuler_label;
public Label funktioner_label;
public Button start_knap;
public Button annuler_knap;
public TextArea status_textarea;
public Label status_label;
public MenuBar MenuBar1;
public Menu MenuBar1Filer0;
public Menu MenuBar1V_lg_Menu1;
public Menu MenuBar1Funktioner2;
public Menu MenuBar1Hj_lp3;
public Label visbillede_label;
private Vector vector = new Vector();
private String dkn = \"auktion\";
// End of Component Declaration
// Constructor
public Administrator()
{
// Frame Initialization
setForeground(Color.black);
setBackground(Color.lightGray);
setFont(new Font(\"Dialog\",Font.BOLD,12));
setTitle(\"ADMINISTRATOR\");
setLayout(null);
// End of Frame Initialization
// Component Initialization
genstand_panel = new Panel();
genstand_panel.setLayout(null);
genstand_panel.setForeground(Color.black);
genstand_panel.setBackground(Color.yellow);
genstand_panel.setFont(new Font(\"Dialog\",Font.BOLD,12));
genstand_list = new List();
genstand_list.setForeground(Color.black);
genstand_list.setBackground(Color.white);
genstand_list.setFont(new Font(\"Dialog\",Font.BOLD,12));
genstand_label = new Label(\"GENSTANDE PÅ AUKTION I DAG\",Label.CENTER);
genstand_label.setFont(new Font(\"Dialog\",Font.BOLD + Font.ITALIC,20));
genstand_choice = new Choice();
genstand_choice.setFont(new Font(\"Dialog\",Font.BOLD,12));
help_label = new Label(\"VIS AUKTIONLISTE FOR D.\",Label.LEFT);
help_label.setFont(new Font(\"Dialog\",Font.BOLD,12));
igang_auktion_panel = new Panel();
igang_auktion_panel.setLayout(null);
igang_auktion_panel.setForeground(Color.black);
igang_auktion_panel.setBackground(Color.yellow);
igang_auktion_panel.setFont(new Font(\"Dialog\",Font.BOLD,12));
reg_nr_label = new Label(\"REG. NR.\",Label.LEFT);
reg_nr_label.setFont(new Font(\"Dialog\",Font.BOLD,12));
varenavn_label = new Label(\"VARENAVN\",Label.LEFT);
varenavn_label.setFont(new Font(\"Dialog\",Font.BOLD,12));
beskrivelse_label = new Label(\"BESKRIVELSE\",Label.LEFT);
beskrivelse_label.setFont(new Font(\"Dialog\",Font.BOLD,12));
mindstepris_label = new Label(\"MINDSTE PRIS\",Label.LEFT);
mindstepris_label.setFont(new Font(\"Dialog\",Font.BOLD,12));
billedehelp_label = new Label(\"EVT. BILLEDE\",Label.LEFT);
billedehelp_label.setFont(new Font(\"Dialog\",Font.BOLD,12));
hoejst_bud_label = new Label(\"HØJSTE BUD\",Label.LEFT);
hoejst_bud_label.setFont(new Font(\"Dialog\",Font.BOLD,12));
hoejste_textfield = new TextField(\"\");
hoejste_textfield.setForeground(Color.black);
hoejste_textfield.setBackground(Color.white);
hoejste_textfield.setFont(new Font(\"Dialog\",Font.BOLD,12));
beskrivelse_textarea = new TextArea(\"\");
beskrivelse_textarea.setForeground(Color.black);
beskrivelse_textarea.setBackground(Color.white);
beskrivelse_textarea.setFont(new Font(\"Dialog\",Font.BOLD,12));
mindstepris_textfield = new TextField(\"\");
mindstepris_textfield.setForeground(Color.black);
mindstepris_textfield.setBackground(Color.white);
mindstepris_textfield.setFont(new Font(\"Dialog\",Font.BOLD,12));
varenr_textfield = new TextField(\"\");
varenr_textfield.setForeground(Color.black);
varenr_textfield.setBackground(Color.white);
varenr_textfield.setFont(new Font(\"Dialog\",Font.BOLD,12));
reg_nr_textfield = new TextField(\"\");
reg_nr_textfield.setForeground(Color.black);
reg_nr_textfield.setBackground(Color.white);
reg_nr_textfield.setFont(new Font(\"Dialog\",Font.BOLD,12));
igang_label = new Label(\"IGANGVÆRENDE AUKTION\",Label.CENTER);
igang_label.setFont(new Font(\"Dialog\",Font.BOLD + Font.ITALIC,20));
dkr_label = new Label(\"DKR\",Label.LEFT);
dkr_label.setFont(new Font(\"Dialog\",Font.BOLD,12));
dkr2_label = new Label(\"DKR\",Label.LEFT);
dkr2_label.setFont(new Font(\"Dialog\",Font.BOLD,12));
funktioner_panel = new Panel();
funktioner_panel.setLayout(null);
funktioner_panel.setForeground(Color.black);
funktioner_panel.setBackground(Color.yellow);
funktioner_panel.setFont(new Font(\"Dialog\",Font.BOLD,12));
fald_til_ro_label = new Label(\"FALD TIL RO TIDEN\",Label.LEFT);
fald_til_ro_label.setFont(new Font(\"Dialog\",Font.BOLD,12));
fald_til_ro_textfield = new TextField(\"\");
fald_til_ro_textfield.setForeground(Color.black);
fald_til_ro_textfield.setBackground(Color.white);
fald_til_ro_textfield.setFont(new Font(\"Dialog\",Font.BOLD,12));
sekunder_label = new Label(\"SEKUNDER\",Label.LEFT);
sekunder_label.setFont(new Font(\"Dialog\",Font.BOLD,12));
luk_knap = new Button(\"LUK\");
luk_knap.setFont(new Font(\"Dialog\",Font.BOLD,12));
opdater_knap = new Button(\"OPDATER\");
opdater_knap.setFont(new Font(\"Dialog\",Font.BOLD,12));
start_label = new Label(\"START NÆSTE AUKTION\",Label.LEFT);
start_label.setFont(new Font(\"Dialog\",Font.BOLD,12));
annuler_label = new Label(\"ANULLER IGANGVÆRENDE AUKTION\",Label.LEFT);
annuler_label.setFont(new Font(\"Dialog\",Font.BOLD,12));
funktioner_label = new Label(\"FUNKTIONER\",Label.CENTER);
funktioner_label.setFont(new Font(\"Dialog\",Font.BOLD + Font.ITALIC,20));
start_knap = new Button(\"START\");
start_knap.setFont(new Font(\"Dialog\",Font.BOLD,12));
annuler_knap = new Button(\"ANNULER\");
annuler_knap.setFont(new Font(\"Dialog\",Font.BOLD,12));
reg_nr_textfield.enable(false);
varenr_textfield.enable(false);
beskrivelse_textarea.enable(false);
mindstepris_textfield.enable(false);
hoejste_textfield.enable(false);
status_textarea = new TextArea(\"\");
status_textarea.setForeground(Color.black);
status_textarea.setBackground(Color.white);
status_textarea.setFont(new Font(\"Dialog\",Font.BOLD,12));
status_label = new Label(\"STATUS\",Label.LEFT);
status_label.setFont(new Font(\"Dialog\",Font.BOLD,12));
MenuBar1 = new MenuBar();
MenuBar1Filer0 = new Menu(\"Filer\");
MenuBar1.add(MenuBar1Filer0);
MenuBar1V_lg_Menu1 = new Menu(\"Vælg Menu\");
MenuBar1.add(MenuBar1V_lg_Menu1);
MenuBar1Funktioner2 = new Menu(\"Funktioner\");
MenuBar1.add(MenuBar1Funktioner2);
MenuBar1Hj_lp3 = new Menu(\"Hjælp\");
MenuBar1.add(MenuBar1Hj_lp3);
setMenuBar(MenuBar1);
visbillede_label = new Label(\"\",Label.LEFT);
visbillede_label.setFont(new Font(\"Dialog\",Font.BOLD,12));
status_textarea.enable(false);
// End of Component Initialization
// Add()s
igang_auktion_panel.add(visbillede_label);
igang_auktion_panel.add(status_label);
igang_auktion_panel.add(status_textarea);
funktioner_panel.add(annuler_knap);
funktioner_panel.add(start_knap);
funktioner_panel.add(funktioner_label);
funktioner_panel.add(annuler_label);
funktioner_panel.add(start_label);
funktioner_panel.add(opdater_knap);
add(luk_knap);
funktioner_panel.add(sekunder_label);
funktioner_panel.add(fald_til_ro_textfield);
funktioner_panel.add(fald_til_ro_label);
add(funktioner_panel);
igang_auktion_panel.add(dkr2_label);
igang_auktion_panel.add(dkr_label);
igang_auktion_panel.add(igang_label);
igang_auktion_panel.add(reg_nr_textfield);
igang_auktion_panel.add(varenr_textfield);
igang_auktion_panel.add(mindstepris_textfield);
igang_auktion_panel.add(beskrivelse_textarea);
igang_auktion_panel.add(hoejste_textfield);
igang_auktion_panel.add(hoejst_bud_label);
igang_auktion_panel.add(billedehelp_label);
igang_auktion_panel.add(mindstepris_label);
igang_auktion_panel.add(beskrivelse_label);
igang_auktion_panel.add(varenavn_label);
igang_auktion_panel.add(reg_nr_label);
add(igang_auktion_panel);
genstand_panel.add(help_label);
genstand_panel.add(genstand_choice);
genstand_panel.add(genstand_label);
genstand_panel.add(genstand_list);
add(genstand_panel);
// End of Add()s
InitialPositionSet();
ActionListener knapAktiv = new DirectionListener();
luk_knap.addActionListener(knapAktiv);
opdater_knap.addActionListener(knapAktiv);
genstand_list.addActionListener(knapAktiv);
// genstand_choice.addItemListener(this);
vector.removeAllElements();
genstand_list.clear();
//******************************************************************************
//her kalder jeg metoden Fyldlistbox(), og udskriver indholdet af vectoren, og det virker fint,
//den udsriver det den skal.
//***********************************************************************************
try
{
vector = adgang.admini.Fyld_Listebox();
}
catch (Exception re)
{
}
System.out.println(vector);
System.out.println(\"\\n\");
//***********************************************************************************
//men her går det galt!!!
//jeg laver et array og smider indholdet af vectoren over i arrayet.
//så kører jeg en forlykke og add indholdet af arrayet til choiceboxen,
//men hver gang jeg lukker og åbner skærmbilledet igen, bliver indholdet i choiceboxen fordoblet!!!!!
//*********************************************************************************
String [] visDatoArray = new String[vector.size()];
vector.copyInto(visDatoArray);
for(int i=0;i<visDatoArray.length;i++)
{
genstand_choice.add(visDatoArray[i]);
}
}
public void InitialPositionSet()
{
// InitialPositionSet()
reshape(37,2,949,736);
genstand_panel.reshape(7,32+MenuBarHeight,511,387);
genstand_list.reshape(86,53,332,264);
genstand_label.reshape(33,8,446,28);
genstand_choice.reshape(315,340,100,27);
help_label.reshape(98,344,217,18);
igang_auktion_panel.reshape(531,32+MenuBarHeight,406,644);
reg_nr_label.reshape(66,72,82,19);
varenavn_label.reshape(66,114,101,19);
beskrivelse_label.reshape(63,180,113,19);
mindstepris_label.reshape(65,286,123,19);
billedehelp_label.reshape(69,374,120,19);
hoejst_bud_label.reshape(69,468,109,19);
hoejste_textfield.reshape(193,464,84,27);
beskrivelse_textarea.reshape(185,150,185,89);
mindstepris_textfield.reshape(193,282,84,27);
varenr_textfield.reshape(185,111,184,27);
reg_nr_textfield.reshape(185,70,183,27);
igang_label.reshape(16,11,379,29);
dkr_label.reshape(280,286,42,19);
dkr2_label.reshape(285,468,43,19);
funktioner_panel.reshape(7,432+MenuBarHeight,512,244);
fald_til_ro_label.reshape(13,59,161,19);
fald_til_ro_textfield.reshape(182,57,73,27);
sekunder_label.reshape(261,60,95,19);
luk_knap.reshape(822,680+MenuBarHeight,114,30);
opdater_knap.reshape(361,54,114,30);
start_label.reshape(15,120,199,19);
annuler_label.reshape(17,169,300,19);
funktioner_label.reshape(159,2,191,29);
start_knap.reshape(362,113,114,30);
annuler_knap.reshape(362,167,114,30);
status_textarea.reshape(194,518,185,89);
status_label.reshape(71,547,62,19);
visbillede_label.reshape(191,333,173,113);
// End of InitialPositionSet()
}
public boolean handleEvent(Event evt)
{
// handleEvent()
if (evt.id == Event.WINDOW_DESTROY && evt.target == this) Administrator_WindowDestroy(evt.target);
// End of handleEvent()
return super.handleEvent(evt);
}
public void paint(Graphics g)
{
// paint()
// End of paint()
}
// main()
public static void main(String args[])
{
Administrator Administrator = new Administrator();
Administrator.show();
} // End of main()
// Event Handling Routines
public void Administrator_WindowDestroy(Object target)
{
System.exit(0);
}
private class DirectionListener implements ActionListener
{ public void actionPerformed(ActionEvent e)
{ Object knap = e.getSource();
if (knap == luk_knap)
{
System.exit(0);
}
else if ( knap == opdater_knap)
{
}
else if(knap == genstand_list)
{
}
}
}
// End of Event Handling Routines
} // End of Class Administrator
