import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class VDGUI extends JFrame {
private boolean exit,load;
private JButton loadJButton,saveJButton,helpJButton,exitJButton,insertJButton,editJButton;
private JButtonActionListener aJButtonActionListener;
private JLabel countJLabel,arrayJLabel;
private JTextField countJTextField;
private JTextArea arrayJTextArea;
private JScrollPane aJScrollPane;
private static Font aFont=new Font("Tahoma",Font.BOLD,30);
private static Font cFont=new Font("Courier new",Font.BOLD,12);
private static Color fColor=Color.white;
private static Color editColor=Color.blue;
private static Color noeditColor=Color.red;
private static Color textColor=Color.white;
private int pw=100, buttonHeight=20, buttonY=235 ;
private int aktuelleButton,buttonWidth=100,nextButton=110;
private InsertJDialog aInsertJDialog;
public VDGUI()
{
super("Database");
setIconImage(getToolkit().getImage("vinyl.gif"));
setSize(800,580);
setLocation(0,0);
getContentPane().setLayout(null);
getContentPane().setBackground(fColor);
aJButtonActionListener = new JButtonActionListener(this);
loadJButton= new JButton("LOAD");
loadJButton.setBounds(10, buttonY, buttonWidth, buttonHeight);
loadJButton.setVisible(true);
getContentPane().add(loadJButton);
loadJButton.addActionListener(aJButtonActionListener);
saveJButton= new JButton("SAVE");
saveJButton.setBounds(aktuelleButton+=nextButton +10, buttonY, buttonWidth, buttonHeight);
saveJButton.setVisible(true);
getContentPane().add(saveJButton);
saveJButton.addActionListener(aJButtonActionListener);
helpJButton= new JButton("HELP");
helpJButton.setBounds(aktuelleButton+=nextButton, buttonY, buttonWidth, buttonHeight);
helpJButton.setVisible(true);
getContentPane().add(helpJButton);
helpJButton.addActionListener(aJButtonActionListener);
insertJButton= new JButton("INSERT");
insertJButton.setBounds(aktuelleButton+=nextButton, buttonY, buttonWidth, buttonHeight);
insertJButton.setVisible(true);
getContentPane().add(insertJButton);
insertJButton.addActionListener(aJButtonActionListener);
editJButton= new JButton("EDIT");
editJButton.setBounds(aktuelleButton+=nextButton, buttonY, buttonWidth, buttonHeight);
editJButton.setVisible(true);
getContentPane().add(editJButton);
editJButton.addActionListener(aJButtonActionListener);
exitJButton= new JButton("EXIT");
exitJButton.setBounds(aktuelleButton+=nextButton, buttonY, buttonWidth, buttonHeight);
exitJButton.setVisible(true);
getContentPane().add(exitJButton);
exitJButton.addActionListener(aJButtonActionListener);
countJLabel=new JLabel("Database");
countJLabel.setBounds(10, 5, 580, 25);
countJLabel.setFont(aFont);
countJLabel.setVisible(true);
getContentPane().add(countJLabel);
countJTextField=new JTextField();
countJTextField.setBounds(aktuelleButton+=nextButton, buttonY, buttonWidth/2, buttonHeight);
countJTextField.setFont(cFont);
countJTextField.setEditable(false);
countJTextField.setBackground(noeditColor);
countJTextField.setForeground(textColor);
countJTextField.setHorizontalAlignment(11);
countJTextField.setVisible(true);
getContentPane().add(countJTextField);
arrayJTextArea = new JTextArea();
arrayJTextArea.setFont(cFont);
arrayJTextArea.setEditable(false);
arrayJTextArea.setBackground(noeditColor);
arrayJTextArea.setForeground(textColor);
aJScrollPane = new JScrollPane(arrayJTextArea);
aJScrollPane.setBounds(10+nextButton,01,40,60);
aJScrollPane.setVisible(true);
getContentPane().add(aJScrollPane);
// Daten Tabelle
VinylTabelle newContentPane = new VinylTabelle();
newContentPane.setOpaque(true); //content panes must be opaque
setContentPane(newContentPane);
setVisible(true);
aInsertJDialog = new InsertJDialog(this,false);
}
public void run(){
do
{
} while ( exit == false );
}
public void callBackLoadJButton() { System.out.println("Lade *** Lade *** ERROR...");}
public void callBackSaveJButton() { System.out.println("Save");}
public void callBackHelpJButton() { System.out.println("Help");}
public void callBackInsertJButton() {
aInsertJDialog.setVisible(true);
}
public void callBackEditJButton() { System.out.println("Edit");}
}
class JButtonActionListener implements ActionListener
{
VDGUI dieGUI;
public JButtonActionListener(VDGUI mGUI)
{ dieGUI = mGUI; }
public void actionPerformed ( ActionEvent evt )
{
String [] commandString =
{"LOAD","SAVE","HELP","EXIT","INSERT","EDIT",
"PRINT GUI","PRINT PKW"};
int i,nr=-1;
for ( i=0, nr=-1 ; i < commandString.length ; i++ )
if ( commandString[i].equals(evt.getActionCommand())) { nr=i; break; }
switch ( nr )
{
case 0 : //dieGUI.callBackLoadJButton();
break;
case 1 : //dieGUI.callBackSaveJButton();
break;
case 2 : //dieGUI.callBackHelpJButton();
break;
case 3 : System.exit(0);
break;
case 4 : //dieGUI.callBackInsertJButton();
break;
case 5 : //dieGUI.callBackEditJButton();
break;
case 6 :
break;
case 7 :
break;
default : break;
}
}
}
class VinylTabelle extends JPanel {
private boolean DEBUG = false;
public VinylTabelle() {
// super(new GridLayout(1,0));
String[] columnNames = {"First Name",
"Last Name",
"Sport",
"# of Years",
"Vegetarian"};
Object[][] data = {
{"Mary", "Campione",
"Snowboarding", new Integer(5), new Boolean(false)},
{"Alison", "Huml",
"Rowing", new Integer(3), new Boolean(true)},
{"Kathy", "Walrath",
"Knitting", new Integer(2), new Boolean(false)},
{"Sharon", "Zakhour",
"Speed reading", new Integer(20), new Boolean(true)},
{"Philip", "Milne",
"Pool", new Integer(10), new Boolean(false)}
};
final JTable table = new JTable(data, columnNames);
table.setPreferredScrollableViewportSize(new Dimension(500, 70));
if (DEBUG) {
table.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
printDebugData(table);
}
});
}
//Create the scroll pane and add the table to it.
JScrollPane scrollPane = new JScrollPane(table);
//Add the scroll pane to this panel.
add(scrollPane);
}
private void printDebugData(JTable table) {
int numRows = table.getRowCount();
int numCols = table.getColumnCount();
javax.swing.table.TableModel model = table.getModel();
System.out.println("Value of data: ");
for (int i=0; i < numRows; i++) {
System.out.print(" row " + i + ":");
for (int j=0; j < numCols; j++) {
System.out.print(" " + model.getValueAt(i, j));
}
System.out.println();
}
System.out.println("--------------------------");
}
}