Universität Paderborn - Home Universität Paderborn
Die Universität der Informationsgesellschaft

Grundlagen der Programmierung 2 SS 2005 - Datei SimpleEditor.java

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.GridLayout;

public class SimpleEditor extends JFrame
{

   String[] strFont = {"Arial", "Monospaced", "Times", "Times New Roman", "SansSerif", "Serif"};
   int intSize = 12;
   String strBuffer = "";

   //
   // GUI Elemente
   //

   JPanel btnPane = new JPanel(new FlowLayout(FlowLayout.LEFT));
   JButton btnNew = new JButton(new ImageIcon("new.gif"));
   JButton btnOpen = new JButton(new ImageIcon("open.gif"));
   JButton btnSave = new JButton(new ImageIcon("save.gif"));
   JLabel lblFont = new JLabel("Font:");
   JComboBox cobFont = new JComboBox(strFont);
   JLabel lblSize = new JLabel("Size:");
   JTextField tfSize = new JTextField(3);

   JPanel editPane = new JPanel(new GridLayout(4, 1));
   JButton btnCopy = new JButton("Copy");
   JButton btnCut = new JButton("Cut");
   JButton btnPaste = new JButton("Paste");
   JButton btnDel = new JButton("Del");

   JTextArea textArea = new JTextArea(30, 100);
   JScrollPane textPane = new JScrollPane(textArea,
         JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
         JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);

   JPanel blankPane = new JPanel();

   JPanel statusPane = new JPanel(new FlowLayout(FlowLayout.LEFT));
   JLabel lblStatus = new JLabel("Der SimpleEditor wurde gestartet.");

   JFileChooser fileChooser = new JFileChooser();

   //
   // Konstruktor erzeugt die Oberfläche
   //

   public SimpleEditor(String title)
   {
      super(title);

      this.setSize(640, 480);

      Container content = this.getContentPane();
      content.setLayout(new BorderLayout());

      content.add(btnPane, BorderLayout.NORTH);
      content.add(editPane, BorderLayout.WEST);
      content.add(textPane, BorderLayout.CENTER);
      content.add(blankPane, BorderLayout.EAST);
      content.add(statusPane, BorderLayout.SOUTH);

      btnPane.add(btnNew);
      btnPane.add(btnOpen);
      btnPane.add(btnSave);
      btnPane.add(lblFont);
      cobFont.setSelectedIndex(1);
      btnPane.add(cobFont);
      btnPane.add(lblSize);
      btnPane.add(tfSize);

      editPane.add(btnCut);
      editPane.add(btnCopy);
      editPane.add(btnPaste);
      editPane.add(btnDel);

      statusPane.add(lblStatus);

      setVisible(true);
   }

   //
   // Hauptprogramm
   //

   public static void main(String[] args)
   {
      SimpleEditor simpleEditor = new SimpleEditor("SimpleEditor");
   }
}

Generiert mit Camelot | Probleme mit Camelot? | Geändert am: 29.04.2005