BrimiGui.java [Last ned]

/*
 *   Hovedmeny med valg for å åpne skjemaer
 *   for registrering av varer, kunder og bestillinger.
 *
 */
 
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
 
 
public class BrimiGui extends JFrame
  implements ActionListener, WindowListener {
 
 
  private JMenuBar      menylinje;
  private JMenu         mnuFil;
  private JMenuItem     mitLagre, mitAvslutt;
  private JButton       btnVarer, btnKunder, btnBestillinger;
 
 
  public BrimiGui() {
    setTitle("Brimi 100");
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    opprettGUI();
    pack();
    setLocationRelativeTo(null);
    setVisible(true);
  }
 
 
  public void actionPerformed(ActionEvent e) {
    if (e.getSource() == btnVarer)
      Brimi.vareGui.setVisible(true);
    else if (e.getSource() == btnKunder) {
      Brimi.kundeGui.setVisible(true);
    }
    if (e.getSource() == btnBestillinger) {
      Brimi.bestillingGui.setVisible(true);
    }
    else if (e.getSource() == mitLagre) {
      Brimi.skrivTilFil();
    }
    else if (e.getSource() == mitAvslutt) {
      Brimi.skrivTilFil();
      System.exit( 0 );
    }
  }
 
 
  public void windowClosing(WindowEvent e) {
    Brimi.skrivTilFil();
    System.exit( 0 );
  }
 
 
  public void windowIconified(WindowEvent e)   {}
  public void windowOpened(WindowEvent e)      {}
  public void windowClosed(WindowEvent e)      {}
  public void windowDeiconified(WindowEvent e) {}
  public void windowActivated(WindowEvent e)   {}
  public void windowDeactivated(WindowEvent e) {}
 
 
  private void opprettGUI() {
    mnuFil = new JMenu("Fil");
    mitLagre = new JMenuItem("Lagre");
    mitAvslutt = new JMenuItem("Avslutt");
    mnuFil.add(mitLagre);
    mnuFil.add(mitAvslutt);
    menylinje = new JMenuBar();
    menylinje.add(mnuFil);
    setJMenuBar(menylinje);
 
    FlowLayout layout = new FlowLayout();
    setLayout(layout);
    btnVarer = new JButton("Varer");
    btnKunder = new JButton("Kunder");
    btnBestillinger = new JButton("Bestillinger");
    add(btnVarer);
    add(btnKunder);
    add(btnBestillinger);
 
    btnVarer.addActionListener(this);
    btnKunder.addActionListener(this);
    btnBestillinger.addActionListener(this);
    mitLagre.addActionListener(this);
    mitAvslutt.addActionListener(this);
    addWindowListener(this);
  }
 
 
  public static void leggTilFelt(JPanel panel, String ledetekst, JTextField txt) {
    JLabel label = new JLabel(ledetekst);
    label.setHorizontalAlignment(JLabel.RIGHT);
    panel.add(label);
    panel.add(txt);
  }
 
}
 
Kildekode blir vist ved hjelp av GeSHi.