import java.io.*; import java.awt.*; import java.awt.event.*; class HalloWeltG extends Frame{ // Version & Autor private static final String VersionsDatum = "28.9.2004"; private static final String Autor = "Manfred Sommer"; private static String Titel = "HalloWeltGrafisch"; // Fonts private static final Font FontMono = new Font("Monospaced", Font.PLAIN, 18); private static final Font FontSansSerif = new Font("SansSerif", Font.PLAIN, 14); private static final Font BigItalicSansSerif = new Font("SansSerif", Font.ITALIC, 16); // Haupt - Fenstergrösse private static int XMax = 1000; private static int YMax = 700; // Fenstergrösse für Meldungen private static int XMeld0 = 20; private static int YMeld0 = 60; private static int XMeldW = 900; private static int YMeldH = 600; // Fenster für Meldungen private static TextArea Meldungen = new TextArea(); // Beginn Menü private static MenuBar MainMenuBar = new MenuBar(); private static Menu DateiMenu = new Menu("Datei"); private static MenuItem DateiOpen = new MenuItem("Öffnen..."); private static Menu BearbeitenMenu = new Menu("Bearbeiten"); private static MenuItem HalloWeltMenu = new MenuItem("Hallo Welt"); private static MenuItem LoeMenu = new MenuItem("Fenster löschen"); private static MenuItem Beenden = new MenuItem("Exit"); private static Menu HelpMenu = new Menu("Hilfe"); private static MenuItem AboutBox = new MenuItem("About"); // End Menü //// Konstruktor. HalloWeltG () { super(Titel); // Fonts für Menüs setFont(FontMono); DateiMenu.setFont(FontSansSerif); DateiOpen.setFont(FontSansSerif); BearbeitenMenu.setFont(FontSansSerif); HalloWeltMenu.setFont(FontSansSerif); LoeMenu.setFont(FontSansSerif); Beenden.setFont(FontSansSerif); HelpMenu.setFont(FontSansSerif); AboutBox.setFont(FontSansSerif); // Font für Text Bereich setFont(new Font("Monospaced", Font.PLAIN, 18)); setLayout(null); setMenuBar(MainMenuBar); MainMenuBar.add(DateiMenu); DateiMenu.add(DateiOpen); DateiMenu.add(Beenden); MainMenuBar.add(BearbeitenMenu); BearbeitenMenu.add(HalloWeltMenu); BearbeitenMenu.add(LoeMenu); MainMenuBar.add(HelpMenu); HelpMenu.add(AboutBox); Meldungen.setBounds(XMeld0,YMeld0,XMeldW,YMeldH); Meldungen.setEditable(false); add(Meldungen); DateiOpen.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ doOpenFile();} }); HalloWeltMenu.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ doHalloWelt();} }); LoeMenu.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ doLoe();} }); Beenden.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ FensterBeenden(); } }); AboutBox.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ showAboutBox(); } }); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { FensterBeenden(); } }); setBackground(Color.lightGray); setSize(XMax, YMax); setVisible(true); } void FensterBeenden() { dispose(); System.exit(0); } // show about box void showAboutBox(){ final Frame f = new Frame("About Box"); final Button Ok = new Button("Ok"); f.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { f.dispose(); } }); Ok.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { f.dispose(); } }); f.setFont (BigItalicSansSerif); f.setLayout (new GridLayout(0, 1)); f.add(new Label(" ", Label.CENTER)); f.add(new Label("Test von Hallo Welt - Grafikversion", Label.CENTER)); f.add(new Label("Datum der letzten Änderung: " + VersionsDatum, Label.CENTER)); f.add(new Label("Autor: Manfred Sommer", Label.CENTER)); f.add(new Label(" ", Label.CENTER)); f.add(Ok); f.pack(); f.setVisible(true); } void doOpenFile(){ Meldungen.append("Dummy für: Datei - öffnen.\n"); } void doHalloWelt(){ Meldungen.append("Hallo 42. Welt!\n"); } void doLoe(){ Meldungen.setText(""); } public static void main(String args[]) { new HalloWeltG(); } }