Category Archives: Open Universiteit

Diverse dingen gerelateerd aan de Informatica Bachelor aan de Open Universiteit.

Bibliotheek (6.16)

 
package bibliotheek;
 
import java.util.ArrayList;
 
import bibliotheek.Boek;
 
public class Bibliotheek {
  ArrayList<boek> boekenlijst = new ArrayList</boek><boek>();
 
  public Bibliotheek(){    
  }
 
  public ArrayList<string> geefTitels(){
    ArrayList</string><string> titels = new ArrayList</string><string>();
    for (Boek b: boekenlijst){
      titels.add(b.getTitel());
    }
    return titels;
  }
 
  public String geefAuteur(String titel){
    String auteur = null;
    for (Boek b: boekenlijst){
      if (b.getTitel().equals(titel)) {
        auteur = b.getAuteur();
      }
    }
    return auteur;
  }
 
  public void voegBoekToe(String titel, String auteur){
    Boek nieuwBoek = new Boek(titel, auteur);
    boekenlijst.add(nieuwBoek);
  }
}
</string></boek>

Dobbelsteen in Java (6.5)

package dobbelsteen;
 
import java.util.Random;
 
 
public class Dobbelsteen {
  private int getal = 0;
 
 
  public void Dobbelsteen(){
  }
 
  public int gooi(){
    Random rnd = new Random();
    return (rnd.nextInt(5) + 1);
  }
 
  public void setGetal(int getal){
    this.getal = getal;
  }
 
  public int getGetal(){
    return this.getal;
  }
 
  public static void main(String args[]) {
    Dobbelsteen d = new Dobbelsteen();
    int gegooid = d.gooi();
    d.setGetal(gegooid);
    System.out.println("Je gooide: " + d.getGetal());
  }
}

KnopAanKnopUit

 
import javax.swing.SwingUtilities;
import java.awt.BorderLayout;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.JButton;
import java.awt.Rectangle;
 
public class KnoppenFrame extends JFrame {
 
  private static final long serialVersionUID = 1L;
  private JPanel jContentPane = null;
  private JButton knopLinks = null;
  private JButton knopRechts = null;
 
  /**
   * This method initializes knopLinks	
   * 	
   * @return javax.swing.JButton	
   */
  private JButton getKnopLinks() {
    if (knopLinks == null) {
      knopLinks = new JButton();
      knopLinks.setBounds(new Rectangle(29, 30, 108, 124));
      knopLinks.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent e) {
          System.out.println("actionPerformed()"); 
          knopRechts.setVisible(true);
          knopLinks.setVisible(false);
          // TODO Auto-generated Event stub actionPerformed()
        }
      });
    }
    return knopLinks;
  }
 
  /**
   * This method initializes knopRechts	
   * 	
   * @return javax.swing.JButton	
   */
  private JButton getKnopRechts() {
    if (knopRechts == null) {
      knopRechts = new JButton();
      knopRechts.setBounds(new Rectangle(166, 30, 105, 124));
      knopRechts.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent e) {
          System.out.println("actionPerformed()"); 
          knopLinks.setVisible(true);
          knopRechts.setVisible(false);
        }
      });
    }
    return knopRechts;
  }
 
  /**
   * @param args
   */
  public static void main(String[] args) {
    // TODO Auto-generated method stub
 
    SwingUtilities.invokeLater(new Runnable() {
      public void run() {
        KnoppenFrame thisClass = new KnoppenFrame();
        thisClass.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        thisClass.setVisible(true);
      }
    });
  }
 
  /**
   * This is the default constructor
   */
  public KnoppenFrame() {
    super();
    initialize();
    this.knopRechts.setVisible(false);
  }
 
  /**
   * This method initializes this
   * 
   * @return void
   */
  private void initialize() {
    this.setSize(300, 200);
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    this.setContentPane(getJContentPane());
    this.setTitle("KnoppenAanUit");
  }
 
  /**
   * This method initializes jContentPane
   * 
   * @return javax.swing.JPanel
   */
  private JPanel getJContentPane() {
    if (jContentPane == null) {
      jContentPane = new JPanel();
      jContentPane.setLayout(null);
      jContentPane.add(getKnopLinks(), null);
      jContentPane.add(getKnopRechts(), null);
    }
    return jContentPane;
  }
 
}