Hier zijn al mijn classes
Application.java - Hier begint alles
public class Application {
public static void main(String[] args) {
new GUI();
}
}
GUI.java - het eerste wat je ziet van de gui
import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class GUI extends WindowBasics implements ActionListener {
private JButton zoekButton = null;
private JButton toevoegButton = null;
private JButton aanpasButton = null;
private JButton verwijderButton = null;
String[] columnNames = null;
public GUI() {
// JPanel
JPanel options = new JPanel();
options.setLayout(new GridLayout(1, 4, 5, 5));
options.add(zoekButton = new JButton("zoeken"));
zoekButton.addActionListener(this);
options.add(toevoegButton = new JButton("Toevoegen"));
toevoegButton.addActionListener(this);
options.add(aanpasButton = new JButton("Aanpassen"));
aanpasButton.addActionListener(this);
options.add(verwijderButton = new JButton("Verwijderen"));
verwijderButton.addActionListener(this);
add(options, BorderLayout.NORTH);
// JPanel
JPanel center = new JPanel();
center.setLayout(new GridLayout(2, 1, 5, 5));
String[] columnNames = new String[4];
columnNames[0] = "hoi0";
columnNames[1] = "hoi1";
columnNames[2] = "hoi2";
columnNames[3] = "hoi3";
// JPanel
JPanel columns = new JPanel();
columns.setLayout(new GridLayout(1, columnNames.length, 5, 5));
// Add columns
for (int i = 0; i < columnNames.length; i++) {
columns.add(new JLabel(columnNames[i]));
}
center.add(columns);
// JPanel
JPanel gegevens = new JPanel();
gegevens.setLayout(new GridLayout(1, columnNames.length, 5, 5));
gegevens.add(new JLabel("test:"));
gegevens.add(new JLabel("test2:"));
gegevens.add(new JLabel("test3:"));
gegevens.add(new JLabel("test4:"));
center.add(gegevens);
add(center, BorderLayout.CENTER);
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if (e.getSource().equals(zoekButton)) {
new SearchWindow();
System.out.print("zoek?\n");
}
if (e.getSource().equals(toevoegButton)) {
}
if (e.getSource().equals(aanpasButton)) {
System.out.print("aanpas\n");
}
if (e.getSource().equals(verwijderButton)) {
System.out.print("verwijder\n");
}
}
}
SearchWindow.java - zoek venster van de gui
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class SearchWindow extends WindowBasics implements ActionListener {
private JButton searchButton = null;
private JTextField searchJtf = null;
public SearchWindow() {
// JPanel
JPanel searchValue = new JPanel();
searchValue.setLayout(new FlowLayout());
searchValue.add(new JLabel("Zoek: "));
searchValue.add(searchJtf = new JTextField(25));
add(searchValue, BorderLayout.CENTER);
// JPanel
JPanel searchUserButton = new JPanel();
searchUserButton.setLayout(new FlowLayout());
searchUserButton.add(searchButton = new JButton("Zoek"));
searchButton.addActionListener(this);
add(searchUserButton, BorderLayout.SOUTH);
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if (e.getSource().equals(searchButton)) {
}
}
}
WindowBasics.java - de extend
import java.awt.Dimension;
import java.awt.Toolkit;
import javax.swing.JFrame;
public class WindowBasics extends JFrame {
public WindowBasics() {
setTitle("SQl Test");
//setLocationRelativeTo(null); // Center the frame
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(800, 600);
setVisible(true);
// Start center the JFrame
// Get the size of the screen
Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
// Determine the new location of the window
int width = getSize().width;
int height = getSize().height;
int x = (dim.width - width) / 2;
int y = (dim.height - height) / 2;
// Move the window
setLocation(x, y);
// End center the JFrame
}
}
Dit is te compileren. Ik heb all het onnodige eruit gehaald dus mischien lijkt de code soms wat raar. Ik hoop dat het je lukt, alvast bedankt voor de moeite.