Quelltext

// Für das Projektstudium im SS1997 an der FH-Wedel
// von Timo Gronwald

import java.applet.Applet;
import java.awt.*;

public class komp extends Applet
{
	Frame Fenster;
	MenuBar myMenuBar;
	Menu fileMenu, optionMenu, languageMenu;
	MenuItem saveItem;
	CheckboxMenuItem autosave;

	// Application start
	public static void main(String args[])
	{
		Frame Fenster = new Frame("Frame mit Komponenten en masse");
		Fenster.add("Center",new CPanel(""));
		Fenster.resize(500,400);
		Fenster.show();
	}

	// Applet start
	public void init()
	{
		Fenster = new Frame("Frame mit Komponenten en masse");
		Fenster.add("Center",new CPanel(""));
		Fenster.resize(500,400);

		// Menu Defintion usw.
		fileMenu = new Menu("Datei");
		fileMenu.add("open");
		saveItem = new MenuItem("Go save - speichern");
		saveItem.disable();
		fileMenu.add(saveItem);
		fileMenu.add("Speichern unter");
		autosave = new CheckboxMenuItem("Automatisch");
		autosave.setState(true);
		fileMenu.add(autosave);
		fileMenu.addSeparator();
		fileMenu.add(new MenuItem("Ente"));
		languageMenu = new Menu("Sprache");
		languageMenu.add("Java");
		languageMenu.add("C++");
		languageMenu.add("Delphi");
		optionMenu = new Menu("Optionen");
		optionMenu.add("Umgebung");
		optionMenu.add(languageMenu);
		myMenuBar = new MenuBar();
		myMenuBar.add(fileMenu);
		myMenuBar.add(optionMenu);
		Fenster.setMenuBar(myMenuBar);
	}
	
	public void start()
	{
		Fenster.show();
	}

	public void stop()
	{
		Fenster.dispose();
	}
}

// Komponenten auf das Panel plazieren
class CPanel extends Panel 
{
	// Definieren
	List myList;
	Choice myChoice;
	CheckboxGroup myCheckboxGroup;
	Checkbox box1,box2,box3;
	Checkbox groupBox1, groupBox2, groupBox3;
	TextArea myTextArea;
	TextField myTextField;
	Scrollbar slider;

	public CPanel(String text)
	{			
		// Initialisierung
		myList = new List(3,false);
		myChoice = new Choice();
		myCheckboxGroup = new CheckboxGroup();
		groupBox1 = new Checkbox("'CheckBoxGroup' in Java", myCheckboxGroup, true);
		groupBox2 = new Checkbox("Drueck mich", myCheckboxGroup, true);
		groupBox3 = new Checkbox("Push me !", myCheckboxGroup, true);
		box1 = new Checkbox("'normale Checkbox'");
		box1.setState(true);
		box2 = new Checkbox("Will auch");
		box2.setState(true);
		box3 = new Checkbox();
		box3.setLabel("gedrueckt werden!");
		myTextArea = new TextArea(10, 20);
		myTextArea.setText("'TextArea' in Java");
		myTextArea.select(5,9);
		myTextField = new TextField(20);
		myTextField.setText(myTextArea.getSelectedText());
		slider = new Scrollbar(Scrollbar.HORIZONTAL);
		slider.setValues(50, 100, 0, 200);

		//Hinzufügen von Einträgen
		myList.addItem("'ListBox'");
		myList.addItem("Java");
		myList.addItem("or");
		myList.addItem("not");
		myList.addItem("Java");
		myChoice.addItem("'Choice Box' in Java");
		myChoice.addItem("Coke");
		myChoice.addItem("O-Saft");
		myChoice.addItem("Bier");
		
		//Der Oberfläche hinzufügen
		setLayout(new FlowLayout());
		add(groupBox1);
		add(groupBox2);
		add(groupBox3);
		add(box1);
		add(box2);
		add(box3);
		add(myList);
		add(myChoice);
		add(new Button("'Button' in Hallo Welt!"));
		add(new Label("Do you like 'Labels' in Java?"));
		add(myTextField);
		add(myTextArea);
		add(slider);
	}
}

 

zurück