/**
*@author Dannyboy, Mike T.
*/
import java.io.*;
import java.awt.*; // für Fenster
import java.awt.event.*; // Für Adapter
public class Mainframe extends Frame {
//******************************************************************************************//
// KONSTRUKTOREN
Mainframe(String title) {
this.f = new Frame();
f.setLayout(null);
f.setSize(clientWidth, clientHeight);
f.setTitle(title);
f.addWindowListener(new MyWindowAdapter());
setDesign();
myMouse = new MyMouseAdapter();
f.addMouseListener(myMouse);
f.show();
}
//******************************************************************************************//
public Frame f = null;
// ATTRIBUTE (KONSTANTEN)
final private int clientWidth = 750; // Breite des Clientbereichs
final private int clientHeight = 550; // Höhe des Clientbereichs
final private int leftAlign = 20; // Position der linken Zentrierung
final private int labelheight = 25; // Standardhöhe eines Labels
final private int buttonheight = 30; // Standardhöhe eines Buttons
final private int textfieldheight = buttonheight; // Standardhöhe eines textfeldes
// ATTRIBUTE (VARIABLEN)
// Textfelder
public TextField stdIn = null;
public TextField rCode = null;
// Textareas
public TextArea stdOut = null;
public TextArea stdErr = null;
// Labels
public Label stdIn_Lab = null;
public Label stdErr_Lab = null;
public Label stdOut_Lab = null;
public Label rCode_Lab = null;
// Buttons
public Button ok = null;
public Button cancel = null;
public Button snap = null;
public Button exit = null;
MyMouseAdapter myMouse = null;
//******************************************************************************************//
// Methode legt das komplette Design des Formulars fest.
private void setDesign() {
final int middleX = clientWidth / 2;
createLabel(stdIn_Lab, leftAlign, 25, 90, labelheight, "<Eingabe>");
createTextField(stdIn, leftAlign, 50, 275, textfieldheight, "");
createButton(ok, leftAlign, 90, 85, buttonheight, "OK");
createButton(snap, 115, 90, 85, buttonheight, "SNAP-MENU");
createButton(cancel, 210, 90, 85, buttonheight, "CANCEL");
createLabel(stdErr_Lab, leftAlign, 130, 100, labelheight, "<Standard Error>");
createTextArea(stdErr, leftAlign, 160, 290, 295, "<Dies ist Standard Error>");
createLabel(rCode_Lab, leftAlign, 465, 90, labelheight, "<return code>");
createTextField(rCode, leftAlign, 495, 275, textfieldheight, "");
createLabel(stdOut_Lab, middleX, 25, 90, labelheight, "<Standard Out>");
createTextArea(stdOut, middleX, 50, middleX - 20, 430, "<Dies ist Standard Out>");
createButton(exit, middleX, 495, middleX - 20, buttonheight, "Close Window");
}
//******************************************************************************************//
// GETTER
//******************************************************************************************//
// SETTER
//******************************************************************************************//
// Methode erstellt ein Textfeld (einzeilige Komponente)
private void createTextField(TextField instance, int x, int y, int width, int height, String s) {
instance = new TextField(s);
f.add(instance);
// instance.setBackground(bg);
instance.setBounds(x, y, width, height);
instance.show();
}
//******************************************************************************************//
// Methode erstellt eine Textarea (mehrzeilige Komponente)
private void createTextArea(TextArea instance, int x, int y, int width, int height, String s) {
instance = new TextArea(s);
f.add(instance);
// instance.setBackground(bg);
instance.setBounds(x, y, width, height);
instance.show();
}
//******************************************************************************************//
// Methode erstellt ein Label
private void createLabel(Label instance, int x, int y, int width, int height, String s) {
instance = new Label(s);
f.add(instance);
instance.setBounds(x, y, width, height);
instance.show();
}
//******************************************************************************************//
// Methode erstellt einen Button
private void createButton(Button instance, int x, int y, int width, int height, String s) {
instance = new Button(s);
f.add(instance);
instance.setBounds(x, y, width, height);
instance.addMouseListener(myMouse);
instance.show();
}
//******************************************************************************************//
//******************************************************************************************//
//******************************************************************************************//
// Unterklasse um Window-Events (
OOP-Ereignisse) zu steuern
public class MyWindowAdapter extends WindowAdapter {
public void windowClosing (WindowEvent e) {
System.exit(0);
}
}
//******************************************************************************************//
//******************************************************************************************//
//******************************************************************************************//
// Unterklasse um Mouse-Events (
OOP-Ereignisse) zu steuern
public class MyMouseAdapter extends MouseAdapter {
public void mousePressed(MouseEvent e) {
Object o = e.getSource();
if (o == ok)
ok_Pressed(e);
else if (o == cancel)
cancel_Pressed(e);
else if (o == snap)
snap_Pressed(e);
else if (o == exit)
exit_Pressed(e);
}
}
//******************************************************************************************//
//******************************************************************************************//
//******************************************************************************************//
// Mouse/Button Events
public void ok_Pressed(MouseEvent e){}
public void cancel_Pressed(MouseEvent e){
stdIn.setText("");
}
public void snap_Pressed(MouseEvent e){}
public void exit_Pressed(MouseEvent e){
System.exit(0);
}
//******************************************************************************************//
public static void main(String[] args) {
Mainframe testframe = new Mainframe("JAVIX 2.0");
}
}