package gui;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import javax.swing.table.*;
import classes.phoneClass;
import classes.dbLogin;
import java.sql.*;
import java.util.Vector;
import javax.swing.*;
/**
* 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 [url=http://www.cloudgarden.com]Cloud Garden (Java Resources)[/url] 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.
*/
@SuppressWarnings({"rawtypes", "unchecked", "serial"})
public class NewJFrame extends javax.swing.JFrame {
/**
*
*/
private static final long serialVersionUID = 1L;
private JPanel searchPanel, instructionPane;
private JComboBox brandBox;
private JScrollPane scrollPane;
private JLabel Label, instruction;
private JTable table;
private Connection con;
private ResultSet rset;
private ResultSetMetaData meta;
private Statement stm;
/**
* Auto-generated main method to display this JFrame
*/
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
try{
UIManager.setLookAndFeel("com.jtattoo.plaf.aluminium.AluminiumLookAndFeel");
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(LoginInterface.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(LoginInterface.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(LoginInterface.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(LoginInterface.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
NewJFrame inst = new NewJFrame();
inst.setLocationRelativeTo(null);
inst.setVisible(true);
}
});
}
public NewJFrame() {
super();
initGUI();
}
private void initGUI() {
final Vector columnNames = new Vector();
final Vector data = new Vector();
brandBox = new JComboBox(new phoneClass().phoneManufacturerArray());
brandBox.setBackground(new java.awt.Color(240,240,240));
brandBox.setSelectedItem(null);
brandBox.addItemListener(new ItemListener(){
@Override
public void itemStateChanged(ItemEvent ie){
if(ie.getStateChange() == ItemEvent.SELECTED){
try{
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
}catch(Exception e){
e.printStackTrace();
}
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/"
+ "phoneshopsystem", dbLogin.dbUser(), dbLogin.dbPwd());
String query = "SELECT phoneID, phoneModel, phonePrice, QuantityInStock FROM `"+(String)brandBox.getSelectedItem()+"`";
stm = con.createStatement();
rset = stm.executeQuery(query);
meta = rset.getMetaData();
int columns = meta.getColumnCount();
for(int i = 1; i <= columns; i++){
columnNames.addElement(meta.getColumnName(i));
}
if (rset.next()){
Vector rows = new Vector(columns);
for(int i = 1; i <= columns; i++){
rows.addElement(rset.getObject(i));
}
data.addElement(rows);
}else{
JOptionPane.showMessageDialog(null, "The Table: '"+brandBox.getSelectedItem()+"'"
+ " has nothing in \n stock yet!", "Unavailable Item",JOptionPane.ERROR_MESSAGE);
}
stm.close();
rset.close();
con.close();
}catch(SQLException sql){
sql.printStackTrace();
}
}
}
});
table = new JTable(data, columnNames){
public Class getColumnClass(int column){
for(int row = 0; row <= column; row ++){
Object obj = getValueAt(row, column);
if(obj != null){
return obj.getClass();
}
}
return Object.class;
}
};
table.setPreferredSize(new java.awt.Dimension(534, 180));
table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
table.setGridColor(Color.LIGHT_GRAY);
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
table.setSelectionBackground(new Color(248, 248, 248));
table.setSelectionForeground(new Color(51, 0, 51));
scrollPane = new JScrollPane();
scrollPane.setPreferredSize(new java.awt.Dimension(534, 189));
scrollPane.setBackground(new java.awt.Color(240,240,240));
scrollPane.setBorder(BorderFactory.createTitledBorder(""));
scrollPane.add(table);
table.setDebugGraphicsOptions(DebugGraphics.BUFFERED_OPTION);
searchPanel = new JPanel();
FlowLayout searchPanelLayout = new FlowLayout();
searchPanel.setLayout(searchPanelLayout);
searchPanel.setPreferredSize(new java.awt.Dimension(525, 37));
searchPanel.setBackground(new java.awt.Color(240,240,240));
Label = new JLabel("Phone Brand: ");
Label.setFont(new Font("Times New Roman", Font.BOLD, 13));
Label.setForeground(new Color(51, 0, 51));
instructionPane = new JPanel();
instructionPane.setLayout(new FlowLayout());
instructionPane.setBackground(new java.awt.Color(240,240,240));
instruction = new JLabel();
instruction.setText("<html><body><p>"
+ "Select The Phone-Brand e.g 'Nokia',"
+ " To View Inventory."
+ "</p><br></body></html>");
instruction.setFont(new Font("Times New Roman", 3, 11));
instruction.setEnabled(false);
instructionPane.add(instruction);
getContentPane().add(instructionPane, BorderLayout.NORTH);
searchPanel.add(Label);
searchPanel.add(brandBox);
getContentPane().add(searchPanel, BorderLayout.CENTER);
getContentPane().add(scrollPane, BorderLayout.SOUTH);
pack();
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
getContentPane().setBackground(new java.awt.Color(240,240,240));
setPreferredSize(new Dimension(550, 330));
}
}