Card Layout
jeg er stødt ind i følgende problem:Jeg skal putte mit Panel ind i et Card Layout.
Dette volder mig imidlertid visse kvaler og jeg er ikke i stand til at lokalisere, HVOR det går galt eller HVORFOR...Der Compiles uden fejl...
Det er en applet. Browseren viser kun gråt. Altså finder den ikke panelerne(?)...
import java.awt.*;
import java.applet.Applet;
public class CardClass extends Applet implements Runnable
{
CardLayout card = new CardLayout();
int current = 0;
Panel arr[] = new Panel[2];
Panel Pan0 = new Panel();
Panel Pan1 = new Panel();
GridBagLayout gridbag = new GridBagLayout();
GridBagConstraints constraints = new GridBagConstraints();
Thread runner;
public void start()
{
if (runner == null)
{
runner = new Thread(this);
runner.start();
}
}
public boolean action(Event evt, Object arg)
{
if(evt.target instanceof Event)
{
run();
return true;
}return false;
}
public void init()
{
arr[0] = Pan0;
arr[1] = Pan1;
setLayout(card);
for(int i = 0; i < 2; i++)
{
add("Card " + i, arr[i]);
current = i;
card.show(this, "Card " + i); //initialiser skærmbillede
}
}
public void run()
{
if(current == 0)
{
current = 1;
card.show(this, "Card 0");
}
else
{
current = 0;
card.show(this, "Card 1");
}
}
public void stop()
{
runner = null;
}
public void kunde()
{
Pan0.setLayout(gridbag);
//Første kolonne
//Label m. kunde-nummer
buildConstraints(constraints, 0, 0, 1, 1, 33, 0);
constraints.fill = GridBagConstraints.BOTH;
constraints.anchor = GridBagConstraints.WEST;
Label label01 = new Label("Kundenummer*", Label.LEFT);
gridbag.setConstraints(label01, constraints);
//Tekstfelt til kunde-nummer (Skal udfyldes)
buildConstraints(constraints, 0, 1, 1, 1, 0, 0);
constraints.fill = GridBagConstraints.NONE;
TextField tfKundeNr = new TextField(20);
gridbag.setConstraints(tfKundeNr, constraints);
//Label m. Firmanavn
buildConstraints(constraints, 0, 2, 1, 1, 0, 0);
constraints.fill = GridBagConstraints.BOTH;
constraints.anchor = GridBagConstraints.WEST;
Label label02 = new Label("Firmanavn*", Label.LEFT);
gridbag.setConstraints(label02, constraints);
//Tekstfelt til Firmanavn (Skal udfyldes)
buildConstraints(constraints, 0, 3, 1, 1, 0, 0);
constraints.fill = GridBagConstraints.NONE;
TextField tfFrmNvn = new TextField(20);
gridbag.setConstraints(tfFrmNvn, constraints);
//Label m. Adresse
buildConstraints(constraints, 0, 4, 1, 1, 0, 0);
constraints.fill = GridBagConstraints.BOTH;
constraints.anchor = GridBagConstraints.WEST;
Label label03 = new Label("Adresse*", Label.LEFT);
gridbag.setConstraints(label03, constraints);
//Tekstfelt til Adresse (Skal udfyldes)
buildConstraints(constraints, 0, 5, 1, 1, 0, 0);
constraints.fill = GridBagConstraints.NONE;
TextField tfAdr = new TextField(20);
gridbag.setConstraints(tfAdr, constraints);
//Label m. PostNr
buildConstraints(constraints, 0, 6, 1, 1, 0, 0);
constraints.fill = GridBagConstraints.BOTH;
constraints.anchor = GridBagConstraints.WEST;
Label label04 = new Label("Postnummer", Label.LEFT);
gridbag.setConstraints(label04, constraints);
//Tekstfelt til PostNr
buildConstraints(constraints, 0, 7, 1, 1, 0, 0);
constraints.fill = GridBagConstraints.NONE;
TextField tfPstNr = new TextField(10);
gridbag.setConstraints(tfPstNr, constraints);
//Label m. Bynavn
buildConstraints(constraints, 0, 8, 1, 1, 0, 0);
constraints.fill = GridBagConstraints.BOTH;
constraints.anchor = GridBagConstraints.WEST;
Label label13 = new Label("By", Label.LEFT);
gridbag.setConstraints(label13, constraints);
//Tekstfelt til Bynavn
buildConstraints(constraints, 0, 9, 1, 1, 0, 0);
constraints.fill = GridBagConstraints.NONE;
TextField tfByNavn = new TextField(20);
gridbag.setConstraints(tfByNavn, constraints);
//Label m. Telefonnummer
buildConstraints(constraints, 0, 10, 1, 1, 0, 0);
constraints.fill = GridBagConstraints.BOTH;
constraints.anchor = GridBagConstraints.WEST;
Label label05 = new Label("Telefon", Label.LEFT);
gridbag.setConstraints(label05, constraints);
//Tekstfelt til Telefonnummer
buildConstraints(constraints, 0, 11, 1, 1, 0, 0);
constraints.fill = GridBagConstraints.NONE;
TextField tfTlfNr = new TextField(10);
gridbag.setConstraints(tfTlfNr, constraints);
//Label m. TelefaxNr
buildConstraints(constraints, 0, 12, 1, 1, 0, 0);
constraints.fill = GridBagConstraints.BOTH;
constraints.anchor = GridBagConstraints.WEST;
Label label06 = new Label("Telefax", Label.LEFT);
gridbag.setConstraints(label06, constraints);
//Tekstfelt til TelefaxNr
buildConstraints(constraints, 0, 13, 1, 5, 0, 0);
constraints.fill = GridBagConstraints.NONE;
TextField tfTlfaxNr = new TextField(10);
gridbag.setConstraints(tfTlfaxNr, constraints);
//Anden kolonne
//Label m. Kontaktperson
buildConstraints(constraints, 1, 0, 1, 1, 33, 0);
constraints.fill = GridBagConstraints.BOTH;
constraints.anchor = GridBagConstraints.WEST;
Label label08 = new Label("Kontaktperson*", Label.LEFT);
gridbag.setConstraints(label08, constraints);
//Tekstfelt til Kontaktperson
buildConstraints(constraints, 1, 1, 1, 1, 0, 0);
constraints.fill = GridBagConstraints.NONE;
TextField tfKntPers = new TextField(20);
gridbag.setConstraints(tfKntPers, constraints);
//Label m. Direkte telefon-nummer
buildConstraints(constraints, 1, 2, 1, 1, 0, 0);
constraints.fill = GridBagConstraints.BOTH;
constraints.anchor = GridBagConstraints.WEST;
Label label10 = new Label("Direkte tlf", Label.LEFT);
gridbag.setConstraints(label10, constraints);
//Tekstfelt til Direkte telefon-nummer
buildConstraints(constraints, 1, 3, 1, 1, 0, 0);
constraints.fill = GridBagConstraints.NONE;
TextField tfDirTlf = new TextField(10);
gridbag.setConstraints(tfDirTlf, constraints);
//Label m. Email
buildConstraints(constraints, 1, 4, 1, 1, 0, 0);
constraints.fill = GridBagConstraints.BOTH;
constraints.anchor = GridBagConstraints.WEST;
Label label14 = new Label("E-mail", Label.LEFT);
gridbag.setConstraints(label14, constraints);
//Tekstfelt til Email
buildConstraints(constraints, 1, 5, 1, 1, 0, 0);
constraints.fill = GridBagConstraints.NONE;
TextField tfEmail = new TextField(20);
gridbag.setConstraints(tfEmail, constraints);
//Label m. Hjemmeside
buildConstraints(constraints, 1, 6, 1, 1, 0, 0);
constraints.fill = GridBagConstraints.BOTH;
constraints.anchor = GridBagConstraints.WEST;
Label label15 = new Label("Hjemmeside", Label.LEFT);
gridbag.setConstraints(label15, constraints);
//Tekstfelt til Hjemmeside
buildConstraints(constraints, 1, 7, 1, 1, 0, 0);
constraints.fill = GridBagConstraints.NONE;
TextField tfwww = new TextField("http://", 20);
gridbag.setConstraints(tfwww, constraints);
//Label blank (fylder 6 felter)
buildConstraints(constraints, 1, 8, 1, 10, 0, 0);
constraints.fill = GridBagConstraints.BOTH;
constraints.anchor = GridBagConstraints.WEST;
Label label11 = new Label("", Label.LEFT);
gridbag.setConstraints(label11, constraints);
//Tredje kolonne
//Label m. KundeNr og FirmaNavn
buildConstraints(constraints, 2, 0, 1, 1, 33, 0);
constraints.fill = GridBagConstraints.BOTH;
constraints.anchor = GridBagConstraints.WEST;
Label label12 = new Label(" Kundenummer Firmanavn", Label.LEFT);
gridbag.setConstraints(label12, constraints);
//Tekst-area med KundeNr og FirmaNavn
buildConstraints(constraints, 2, 1, 1, 17, 0, 0);
TextArea taBox1 = new TextArea(20, 20);
gridbag.setConstraints(taBox1, constraints);
Pan0.add(label01);
Pan0.add(label02);
Pan0.add(label03);
Pan0.add(label04);
Pan0.add(label05);
Pan0.add(label06);
//Pan0.add(label07);
Pan0.add(label08);
//Pan0.add(label09);
Pan0.add(label10);
Pan0.add(label11);
Pan0.add(label12);
Pan0.add(label13);
Pan0.add(label14);
Pan0.add(label15);
Pan0.add(tfKundeNr);
Pan0.add(tfFrmNvn);
Pan0.add(tfAdr);
Pan0.add(tfPstNr);
Pan0.add(tfByNavn);
Pan0.add(tfTlfNr);
Pan0.add(tfTlfaxNr);
Pan0.add(tfKntPers);
Pan0.add(tfDirTlf);
Pan0.add(tfEmail);
Pan0.add(tfwww);
Pan0.add(taBox1);
}
public void rapporten()
{
Pan1.setLayout(gridbag);
//Første kolonne
//Label m. kunde-nummer
buildConstraints(constraints, 0, 0, 1, 1, 33, 0);
constraints.fill = GridBagConstraints.BOTH;
constraints.anchor = GridBagConstraints.WEST;
Label label01 = new Label("Kundenummer", Label.LEFT);
gridbag.setConstraints(label01, constraints);
//Tekstfelt til kunde-nummer
buildConstraints(constraints, 0, 1, 1, 1, 0, 0);
constraints.fill = GridBagConstraints.NONE;
TextField tfKundeNr = new TextField(20);
gridbag.setConstraints(tfKundeNr, constraints);
//Label m. Firma navn
buildConstraints(constraints, 0, 2, 1, 1, 0, 0);
constraints.fill = GridBagConstraints.BOTH;
constraints.anchor = GridBagConstraints.WEST;
Label label02 = new Label("Firma navn", Label.LEFT);
gridbag.setConstraints(label02, constraints);
//Tekstfelt til Firma navn
buildConstraints(constraints, 0, 3, 1, 1, 0, 0);
constraints.fill = GridBagConstraints.NONE;
TextField tfFrmNvn = new TextField(20);
gridbag.setConstraints(tfFrmNvn, constraints);
//Label modtagers initialer
buildConstraints(constraints, 0, 4, 1, 1, 0, 0);
constraints.fill = GridBagConstraints.BOTH;
constraints.anchor = GridBagConstraints.WEST;
Label label03 = new Label("Modtagers initialer", Label.LEFT);
gridbag.setConstraints(label03, constraints);
//Tekstfelt til modtagers initialer
buildConstraints(constraints, 0, 5, 1, 1, 0, 0);
constraints.fill = GridBagConstraints.NONE;
TextField tfModtIni = new TextField(20);
gridbag.setConstraints(tfModtIni, constraints);
//Label modtagers Fejlbeskrivelse
buildConstraints(constraints, 0, 6, 1, 1, 0, 0);
constraints.fill = GridBagConstraints.BOTH;
constraints.anchor = GridBagConstraints.WEST;
Label label04 = new Label("Fejlbeskrivelse", Label.LEFT);
gridbag.setConstraints(label04, constraints);
//Tekst-area med fejlbeskrivelse (fylder 7 celler)
buildConstraints(constraints, 0, 7, 1, 7, 33, 0);
TextArea taBox1 = new TextArea(3, 7);
gridbag.setConstraints(taBox1, constraints);
//Label Leveringstidspunkter
buildConstraints(constraints, 0, 14, 1, 1, 0, 0);
constraints.fill = GridBagConstraints.BOTH;
constraints.anchor = GridBagConstraints.WEST;
Label label05 = new Label("Leveringstidspunkter", Label.LEFT);
gridbag.setConstraints(label05, constraints);
//Tekstfelt til Leveringstidspunkter
buildConstraints(constraints, 0, 15, 1, 1, 0, 0);
constraints.fill = GridBagConstraints.NONE;
TextField tfLevTid = new TextField(20);
gridbag.setConstraints(tfLevTid, constraints);
//Label Ønsket afhentning
buildConstraints(constraints, 0, 16, 1, 1, 0, 0);
constraints.fill = GridBagConstraints.BOTH;
constraints.anchor = GridBagConstraints.WEST;
Label label06 = new Label("Ønsket afhentning", Label.LEFT);
gridbag.setConstraints(label06, constraints);
//Tekstfelt til Ønsket afhentning
buildConstraints(constraints, 0, 17, 1, 1, 0, 0);
constraints.fill = GridBagConstraints.NONE;
TextField tfOenAfh = new TextField(20);
gridbag.setConstraints(tfOenAfh, constraints);
//Anden kolonne
//Label Tilføj PC-serie-nr.
buildConstraints(constraints, 1, 0, 1, 1, 33, 0);
constraints.fill = GridBagConstraints.BOTH;
constraints.anchor = GridBagConstraints.WEST;
Label label07 = new Label("Tilføj PC-serie-nr.", Label.LEFT);
gridbag.setConstraints(label07, constraints);
//Tekstfelt til Tilføj PC-serie-nr.
buildConstraints(constraints, 1, 1, 1, 1, 0, 0);
constraints.fill = GridBagConstraints.NONE;
TextField tfPcSeNr = new TextField(20);
gridbag.setConstraints(tfPcSeNr, constraints);
//Label Serie-nr. liste
buildConstraints(constraints, 1, 2, 1, 1, 0, 0);
constraints.fill = GridBagConstraints.BOTH;
constraints.anchor = GridBagConstraints.WEST;
Label label08 = new Label("Serie-nr. liste", Label.LEFT);
gridbag.setConstraints(label08, constraints);
//Tekst-area med Serie-nr. liste (fylder 3 celler)
buildConstraints(constraints, 1, 3, 1, 3, 0, 0);
TextArea taBox2 = new TextArea(3, 7);
gridbag.setConstraints(taBox2, constraints);
//Label Udført arbejde
buildConstraints(constraints, 1, 6, 1, 1, 0, 0);
constraints.fill = GridBagConstraints.BOTH;
constraints.anchor = GridBagConstraints.WEST;
Label label09 = new Label("Udført arbejde", Label.LEFT);
gridbag.setConstraints(label09, constraints);
//Tekst-area med Udført arbejde (fylder 3 celler)
buildConstraints(constraints, 1, 7, 1, 3, 0, 0);
TextArea taBox3 = new TextArea(3, 7);
gridbag.setConstraints(taBox3, constraints);
//Label Materiale forbrug
buildConstraints(constraints, 1, 10, 1, 1, 0, 0);
constraints.fill = GridBagConstraints.BOTH;
constraints.anchor = GridBagConstraints.WEST;
Label label10 = new Label("Materiale forbrug", Label.LEFT);
gridbag.setConstraints(label10, constraints);
//Tekst-area med Materiale forbrug(fylder 3 celler)
buildConstraints(constraints, 1, 11, 1, 3, 0, 0);
TextArea taBox4 = new TextArea(3, 7);
gridbag.setConstraints(taBox4, constraints);
//Label tom01 (Fylder 4 celler)
buildConstraints(constraints, 1, 14, 1, 4, 0, 0);
constraints.fill = GridBagConstraints.BOTH;
constraints.anchor = GridBagConstraints.WEST;
Label label11 = new Label(" Fill Me Up! :-)", Label.LEFT);
gridbag.setConstraints(label11, constraints);
//Tredje kolonne
//Label Dato og reparatør
buildConstraints(constraints, 2, 0, 1, 1, 33, 0);
constraints.fill = GridBagConstraints.BOTH;
constraints.anchor = GridBagConstraints.WEST;
Label label12 = new Label(" Dato reparatør", Label.LEFT);
gridbag.setConstraints(label12, constraints);
//Tekst-area med Dato og reparatør (fylder 16 celler)
buildConstraints(constraints, 2, 1, 1, 17, 0, 0);
TextArea taBox5 = new TextArea(3, 7);
gridbag.setConstraints(taBox5, constraints);
Pan1.add(label01);
Pan1.add(label02);
Pan1.add(label03);
Pan1.add(label04);
Pan1.add(label05);
Pan1.add(label06);
Pan1.add(label07);
Pan1.add(label08);
Pan1.add(label09);
Pan1.add(label10);
Pan1.add(label11);
Pan1.add(label12);
Pan1.add(tfKundeNr);
Pan1.add(tfFrmNvn);
Pan1.add(tfModtIni);
Pan1.add(taBox1);
Pan1.add(tfLevTid);
Pan1.add(tfOenAfh);
Pan1.add(tfPcSeNr);
Pan1.add(taBox2);
Pan1.add(taBox3);
Pan1.add(taBox4);
Pan1.add(taBox5);
}
void buildConstraints(GridBagConstraints gbc, int gx, int gy, int gw, int gh, int wx, int wy)
{
gbc.gridx = gx;
gbc.gridy = gy;
gbc.gridwidth = gw;
gbc.gridheight = gh;
gbc.weightx = wx;
gbc.weighty = wy;
//gbc.ipadx = ix;
//gbc.ipady = iy;
}
}