import java.sql.*;
import java.awt.*;
import java.awt.event.*;
class FrontEnd extends Frame implements ActionListener
{
TextField Skriv;
TextArea Felt;
Button Afsend,Tøm;
ConnectDB db;
public FrontEnd()
{
db = new ConnectDB( "jdbc:
interbase://localhost/C:/Documents and Settings/aslan/Skrivebord/ConnectDB/hotellazy.gdb", "sysdba", "masterkey" );
setTitle( "Hotel Lazy" );
setSize( 400, 350 );
setLayout( new FlowLayout( FlowLayout.CENTER, 60, 10 ) );
Felt = new TextArea(10,40);
Felt.setEditable(false);
add(Felt);
Skriv = new TextField( 30 );
add(Skriv);
Afsend = new Button( "Indsæt" );
Afsend.addActionListener(this);
add( Afsend );
Tøm = new Button( "Tøm" );
Tøm.addActionListener(this);
add( Tøm );
addWindowListener( new WindowAdapter()
{
public void windowClosing( WindowEvent e )
{
System.exit(0);
}
});
setVisible( true );
}
public void paint(Graphics g)
{
g.setColor(Color.blue);
g.fillRect(0,0,400,300);
}
public void actionPerformed( ActionEvent e )
{
if( e.getSource() == Afsend )
{
smidInd();
tagUd();
}
if(e.getSource() == Tøm)
{
TømDB();
}
}
public void smidInd()
{
db.Insert( "INSERT INTO Navne VALUES( '"+Skriv.getText()+"' )" );
Skriv.setText("");
}
public void tagUd()
{
Felt.setText("");
try
{
ResultSet row = db.Select( "SELECT * FROM Navne" );
while( row.next() )
{
Felt.append( row.getString(1)+"\n" );
}
}
catch( SQLException cs )
{
System.out.println( cs );
}
}
public void TømDB()
{
db.Insert("DELETE FROM Navne");
Felt.setText("");
}
public static void main( String args[] )
{
new FrontEnd();
}
}