import java.awt.*; public class GrafiskeKomponenter extends Frame { // opret alle komponenterne og husk dem i nogle objektvariabler Button button1 = new Button(); Checkbox checkbox1 = new Checkbox(); Checkbox checkbox2 = new Checkbox(); Checkbox checkbox3 = new Checkbox(); Checkbox checkbox4 = new Checkbox(); Checkbox checkbox5 = new Checkbox(); CheckboxGroup checkboxGroup1 = new CheckboxGroup(); Choice choice1 = new Choice(); TextField textField1 = new TextField(); TextArea textArea1 = new TextArea(); List list1 = new List(); Label label1 = new Label(); FlowLayout flowLayout1 = new FlowLayout(); // layout-manager (se senere) public GrafiskeKomponenter() { try { jbInit(); } catch(Exception e) { e.printStackTrace(); } } private void jbInit() throws Exception { button1.setLabel("OK"); checkbox1.setLabel("En"); // Sæt afkrydsningsfelternes navne checkbox2.setLabel("To"); checkbox3.setLabel("Tre"); checkbox4.setLabel("Radio1"); // Sæt radioknappernes navne og checkbox5.setLabel("Radio2"); checkbox4.setCheckboxGroup(checkboxGroup1); // gruppen de tilhører checkbox5.setCheckboxGroup(checkboxGroup1); checkboxGroup1.setSelectedCheckbox(checkbox4); choice1.add("Choice Rød"); choice1.add("Choice Grøn"); choice1.add("Choice Blå"); textField1.setColumns(10); textField1.setText("Et TextField"); textArea1.setColumns(15); textArea1.setRows(5); textArea1.setText("Et TextArea"); label1.setText("En Label"); list1.add("List Rød"); list1.add("List Grøn"); list1.add("List Blå"); this.setLayout(flowLayout1);// sæt layout-manager (se senere) this.add(button1, null); // til sidst skal komponenterne føjes this.add(checkbox1, null); // til containeren (se senere) this.add(checkbox2, null); this.add(checkbox3, null); this.add(checkbox4, null); this.add(checkbox5, null); this.add(choice1, null); this.add(textArea1, null); this.add(textField1, null); this.add(label1, null); this.add(list1, null); } }