Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.*;
- import java.awt.*;
- import java.awt.event.*;
- public class NaamLijstPaneel extends JPanel {
- private JButton voegToe, toonNaam, zoekNaam;
- private JTextField naamTxt, voornaamTxt, zoekNaamTxt;
- private String[][] namen = new String[20][2];
- private int eerstVrijeIndex = 0;
- public NaamLijstPaneel() {
- setLayout(new GridLayout(4, 3, 5, 10));
- voegToe = new JButton("Voeg Naam en Voornaam Toe");
- voegToe.addActionListener(new VoegToeKnopHandler());
- toonNaam = new JButton("Toon Naam");
- toonNaam.addActionListener(new ToonNaamKnopHandler());
- zoekNaam = new JButton("Zoek Naam");
- zoekNaam.addActionListener(new ZoekNaamKnopHandler());
- naamTxt = new JTextField(20);
- voornaamTxt = new JTextField(20);
- zoekNaamTxt = new JTextField(20);
- add(new JLabel("Naam:"));
- add(naamTxt);
- add(new JLabel(""));
- add(new JLabel("Voornaam:"));
- add(voornaamTxt);
- add(new JLabel(""));
- add(new JLabel("Zoek naam :"));
- add(zoekNaamTxt);
- add(new JLabel(""));
- add(voegToe);
- add(toonNaam);
- add(zoekNaam);
- }
- public class ZoekNaamKnopHandler implements ActionListener {
- public void actionPerformed(ActionEvent e) {
- Boolean gevonden = false;
- String gezocht = zoekNaamTxt.getText();
- String s = "";
- for (int i = 0; i < eerstVrijeIndex; i++) {
- for (int j = 0; j < 2; j++) {
- if (gezocht.equalsIgnoreCase(namen[i][0])) {
- s += namen[i][0] +" "+ namen[i][1] + "\n";
- gevonden = true;
- } else if (gezocht.equalsIgnoreCase(namen[i][1])) {
- s += namen[i][0] +" "+ namen[i][1] + "\n";
- gevonden = true;
- System.out.println(gevonden);
- }
- }
- }
- if (gevonden == true) {
- JOptionPane.showMessageDialog(null, s + " is gevonden");
- } else if (gevonden == false) {
- JOptionPane.showMessageDialog(null, gezocht + " is niet gevonden");
- }
- }
- }
- public class ToonNaamKnopHandler implements ActionListener {
- public void actionPerformed(ActionEvent e) {
- String s = "";
- for (int i = 0; i < eerstVrijeIndex; i++) {
- for (int j = 0; j < 2; j++) {
- s += "" + namen[i][j] + " ";
- }
- s += "\n";
- }
- JOptionPane.showMessageDialog(null, s);
- }
- }
- public class VoegToeKnopHandler implements ActionListener {
- public void actionPerformed(ActionEvent arg0) {
- String naam = naamTxt.getText();
- System.out.println(naam);
- String voornaam = voornaamTxt.getText();
- System.out.println(voornaam);
- for (int i = 0; i <= eerstVrijeIndex; i++) {
- if (naam.length() > 0 && voornaam.length() > 0) {
- namen[eerstVrijeIndex][0] = naam;
- namen[eerstVrijeIndex][1] = voornaam;
- }
- }
- eerstVrijeIndex++;
- naamTxt.setText("");
- voornaamTxt.setText("");
- }
- }
- }
Add Comment
Please, Sign In to add comment