Haupt GUI:
package Arzt;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.List;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Vector;
import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDesktopPane;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.ListModel;
import javax.swing.WindowConstants;
import javax.swing.SwingUtilities;
import Arzt.gui;
/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit
http://www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class GUI_Arzt extends javax.swing.JFrame implements ActionListener {
public static Component JScrollPaneTabelle;
private JDesktopPane jDesktopPane1;
private JMenu jMenuDatei;
private JMenu jMenuDatenbank1;
private JMenuItem jMenuItemDatenbank;
private JButton jButtonSuchen;
private JList jListDatenbank;
private JMenuItem jMenuItemBeenden;
private JMenuBar jMenuBar;
private JTextField jTextFieldEingabe;
private JLabel jLabel1;
private JLabel jLabelBild;
private JComboBox jComboBoxAuswahl;
private JLabel jLabelUeberschrift;
gui PoPUp1;
/**
* Auto-generated main method to display this JFrame
*/
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
GUI_Arzt inst = new GUI_Arzt();
inst.setLocationRelativeTo(null);
inst.setVisible(true);
}
});
}
public GUI_Arzt() {
super();
initGUI();
}
private void initGUI() {
try {
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
this.setTitle("Arztprogramm");
this.setPreferredSize(new java.awt.Dimension(750, 360));
this.setMinimumSize(new java.awt.Dimension(820, 360));
this.setMaximumSize(new java.awt.Dimension(820, 360));
this.setResizable(false);
{
jMenuBar = new JMenuBar();
setJMenuBar(jMenuBar);
{
jMenuDatei = new JMenu();
jMenuBar.add(jMenuDatei);
jMenuDatei.setText("Datei");
{
jMenuItemBeenden = new JMenuItem();
jMenuDatei.add(jMenuItemBeenden);
jMenuItemBeenden.setText("Beenden");
jMenuItemBeenden.addActionListener(this);
}
{
jMenuDatenbank1 = new JMenu();
jMenuBar.add(jMenuDatenbank1);
jMenuDatenbank1.setText("Datenbank");
{
jMenuItemDatenbank = new JMenuItem();
jMenuDatenbank1.add(jMenuItemDatenbank);
jMenuItemDatenbank.setText("Datenbank");
jMenuItemDatenbank.addActionListener(this);
}
}
}
}
{
jDesktopPane1 = new JDesktopPane();
getContentPane().add(jDesktopPane1, BorderLayout.CENTER);
jDesktopPane1.setBackground(new java.awt.Color(192,192,192));
{
jLabelUeberschrift = new JLabel();
jDesktopPane1.add(jLabelUeberschrift);
jLabelUeberschrift.setText("Patientendatenbank:");
jLabelUeberschrift.setBounds(5, 6, 152, 20);
jLabelUeberschrift.setFont(new java.awt.Font("Segoe UI",1,14));
jLabelUeberschrift.setBackground(new java.awt.Color(0,0,0));
}
{
ComboBoxModel jComboBoxAuswahlModel =
new DefaultComboBoxModel(
new String[] { "nach Name", "nach Datum" });
jComboBoxAuswahl = new JComboBox();
jDesktopPane1.add(jComboBoxAuswahl);
jComboBoxAuswahl.setModel(jComboBoxAuswahlModel);
jComboBoxAuswahl.setBounds(105, 40, 100, 19);
jComboBoxAuswahl.setEditable(true);
}
{
jLabel1 = new JLabel();
jDesktopPane1.add(jLabel1);
jLabel1.setText("Patient suchen :");
jLabel1.setBounds(5, 41, 95, 16);
}
{
jTextFieldEingabe = new JTextField();
jDesktopPane1.add(jTextFieldEingabe);
jTextFieldEingabe.setBounds(210, 40, 81, 19);
}
{
ListModel jListDatenbankModel =
new DefaultComboBoxModel(
new String[] {"Florian Schmidt", "Manuel Stocker" });
jListDatenbank = new JList();
//jListDatenbank.add(JScrollPaneTabelle);
jDesktopPane1.add(jListDatenbank);
jListDatenbank.setModel( jListDatenbankModel);
jListDatenbank.setBounds(5, 76, 374, 192);
}
{
//JScrollPaneTabelle = new JScrollPane();
//this.add((Component) JScrollPaneTabelle);
//((Component) JScrollPaneTabelle).setBounds(5, 76,374, 192);
}
{
jButtonSuchen = new JButton();
jDesktopPane1.add(jButtonSuchen);
jButtonSuchen.setText("Suchen");
jButtonSuchen.setBounds(297, 40, 82, 19);
jButtonSuchen.addActionListener(this);
}
{
jLabelBild = new JLabel(new ImageIcon(GUI_Arzt.class.getResource("arzt.jpg")));
jDesktopPane1.add(jLabelBild);
jLabelBild.setBounds(396, 0, 326, 295);
jLabelBild.setText("Bild");
jLabelBild.setSize(429, 310);
}
}
pack();
this.setSize(820, 360);
} catch (Exception e) {
e.printStackTrace();
}
}
public void actionPerformed(ActionEvent e)
{
if (e.getSource ()== jMenuItemBeenden)
{
System.exit(0);
}
if(e.getSource ()== jMenuItemDatenbank)
{
PoPUp1 = new gui();
PoPUp1.setVisible(true);
}
if(e.getSource ()== jButtonSuchen)
{
PoPUp1 = new gui();
PoPUp1.setVisible(true);
}
}
}
Datenbank GUI:
package Arzt;
import java.sql.*;
import java.util.Vector;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import Arzt.GUI_Arzt;
public class gui extends javax.swing.JFrame {
/** Creates new form Hauptfenster */
public gui() {
initComponents();
aktualisiereTabelle();
}
private void aktualisiereTabelle() {
Vector columnNames = new Vector();
Vector data = new Vector();
try{
//Abfrage definieren
String query = "SELECT * FROM Patienten ";
//"WHERE Bezeichnung = 'Senkkopfschraube mit Innensechskant' " +
//"Where Durchmesser = 'M3' ";
//"WHERE Stückzahl > ?';" ; //s. sql-anweisungen
//Datenbankverbindung herstellen
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); //s. Script//
Connection dbVerbindung = DriverManager.getConnection("jdbc
dbc:daten","","");
System.out.println("Verbindung erfolgreich...");
Statement stmt = dbVerbindung.createStatement();
ResultSet rst = stmt.executeQuery(query);
ResultSetMetaData md = rst.getMetaData();
int columns = md.getColumnCount();
// Spaltennamen ermitteln
for (int i = 1; i <= columns; i++) {
String colname=md.getColumnName(i);
columnNames.addElement( colname );
}
// Zeileninhalt ermitteln
while (rst.next()) {
Vector row = new Vector(columns);
for (int i = 1; i <= columns; i++) {
row.addElement( rst.getObject(i) );
}
data.addElement( row );
}
rst.close();
stmt.close();
} catch(Exception e) {
e.printStackTrace();
}
// Tabelle erzeugen
JTable table = new JTable(data, columnNames);
scrollTabelle.setViewportView(table);
//((JScrollPane) GUI_Arzt.JScrollPaneTabelle).setViewportView(table);
}
private void initComponents() {
scrollTabelle = new javax.swing.JScrollPane();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
getContentPane().add(scrollTabelle, java.awt.BorderLayout.CENTER);
java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
setBounds((screenSize.width-800)/2, (screenSize.height-200)/2, 800, 200);
}
// Variablendeklaration
private javax.swing.JScrollPane scrollTabelle;
}