package cc.glsn.v15.housefund; import java.awt.Font; import java.awt.GridBagConstraints; import java.awt.HeadlessException; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; import java.sql.ResultSet; import java.sql.SQLException; import java.util.LinkedList; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JPasswordField; import javax.swing.JTabbedPane; import javax.swing.JTextField; import cc.glsn.Util; import cc.glsn.v15.SQLConnection; public class Client implements KeyListener { /** * @param args */ public static void main(String[] args) { new Client(); } public Client() { Faces=new LinkedList(); new ConnectWindow(); } JFrame MainWindow; JTabbedPane Tabby; LinkedList Faces; String User; protected void newEdit(int TransID) { EditTab et=new EditTab(this,TransID); et.addKeyListener(this); Tabby.add(et.getTitle(),et); } protected void rmEditTab(EditTab et) { Tabby.remove(et); } private void openMain(String username, String password) { User=username.toLowerCase(); String Hash=Util.SHA1(password); password=null; try { SQLConnection C=Globals.getSQL(); char Q=39; ResultSet R=C.doSingleQuery("select * from people where shortname=" + Q + User + Q + " and password=" + Q + Hash + Q ); if (!R.first()) { new ConnectWindow(); return; } } catch (SQLException e1) { // TODO Auto-generated catch block e1.printStackTrace(); System.exit(-1); } try { MainWindow=new JFrame("Housefund - " + Globals.getFullName(User)); } catch (HeadlessException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); System.exit(1); } MainWindow.setContentPane(new JPanel(new java.awt.GridBagLayout())); MainWindow.setSize(900,600); if (User.equals("joe")) { MainWindow.setSize(1560,900); } MainWindow.addKeyListener(this); MainWindow.setVisible(true); { java.awt.GridBagConstraints c=new java.awt.GridBagConstraints(); c.gridheight=1; c.gridwidth=1; c.weightx=100.0; c.weighty=100.0; c.fill=GridBagConstraints.BOTH; c.insets=new java.awt.Insets(1,1,1,1); c.anchor=GridBagConstraints.WEST; Tabby=new JTabbedPane(JTabbedPane.TOP); Tabby.setFont(Globals.getFont(14,Font.BOLD)); MainWindow.getContentPane().add(Tabby,c); } OverviewPanel Overview=new OverviewPanel(User); Tabby.add("Overview",Overview); Faces.add(Overview); Tabby.addKeyListener(this); try { if (User.equals("joe")) { for(String n : Globals.getAllUsers()) { UserView UV=new UserView(n); Tabby.add(Globals.getFullName(n),UV); Faces.add(UV); UV.addKeyListener(this); } AllTrans at=new AllTrans(this); Tabby.add("All Transactions",at); at.addKeyListener(this); Faces.add(at); } else { UserView UV=new UserView(User); Tabby.add(Globals.getFullName(User),UV); Faces.add(UV); UV.addKeyListener(this); } new Updatemonster().start(); } catch(SQLException e) { e.printStackTrace(); System.exit(1); } MainWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } class ConnectWindow { JTextField UsernameText; JPasswordField PasswordText; JFrame LoginWindow; ConnectWindow() { String WindowTitle="Housefund Login"; LoginWindow=new JFrame(WindowTitle); //MainWindow.setSize(800,600); LoginWindow.setContentPane(new JPanel(new java.awt.GridBagLayout())); //MainWindow.setContentPane(new JPanel(new java.awt.FlowLayout())); //MainWindow.setContentPane(new JPanel(new java.awt.GridLayout(3,2))); LoginWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); UsernameText=new JTextField(10); PasswordText=new JPasswordField(10); Globals.addComponent(new JLabel("Username:"),LoginWindow.getContentPane(),0); Globals.addComponent(UsernameText,LoginWindow.getContentPane(),Globals.FlagEndRow); Globals.addComponent(new JLabel("Password:"),LoginWindow.getContentPane(),0); Globals.addComponent(PasswordText,LoginWindow.getContentPane(),Globals.FlagEndRow); //Connect Button JButton ConnectButton=new JButton("Connect"); ConnectButton.addActionListener(new ConnectPress()); Globals.addComponent(ConnectButton,LoginWindow.getContentPane(),0); LoginWindow.getRootPane().setDefaultButton(ConnectButton); //Exit Button JButton CloseButton=new JButton("Exit"); CloseButton.addActionListener(new ClosePress()); Globals.addComponent(CloseButton,LoginWindow.getContentPane(),Globals.FlagEndRow); JLabel Ver=new JLabel("Version: " + Globals.Ver); Ver.setFont(Globals.getFont(12)); Globals.addComponent(Ver,LoginWindow.getContentPane(),Globals.FlagEndRow+Globals.FlagsNoFont); //MainWindow.setSize(160,160); LoginWindow.pack(); LoginWindow.setVisible(true); System.out.println(LoginWindow.getSize()); } class ConnectPress implements ActionListener { public void actionPerformed(ActionEvent evt) { String Username=UsernameText.getText(); String Password=new String(PasswordText.getPassword()); LoginWindow.setVisible(false); openMain(Username,Password); } } } class ClosePress implements ActionListener { public void actionPerformed(ActionEvent evt) { System.exit(0); } } public void keyTyped(KeyEvent arg0) { // TODO Auto-generated method stub } public void keyPressed(KeyEvent e) { // TODO Auto-generated method stub if (e.getKeyCode()==KeyEvent.VK_F5) { new Updatemonster().start(); } } public void keyReleased(KeyEvent arg0) { // TODO Auto-generated method stub } class Updatemonster extends Thread { public void run() { System.out.println("Updating data..."); synchronized(Faces) { for(Face F : Faces) { new Updateminion(F).start(); } } } class Updateminion extends Thread { Face F; Updateminion(Face f) { F=f; } public void run() { try { F.updateData(); } catch (SQLException e1) { e1.printStackTrace(); System.exit(-1); } } } } }