import javax.swing.border.EmptyBorder; import java.awt.event.*; import java.awt.*; import javax.swing.*; import javax.swing.border.EtchedBorder; import javax.swing.border.TitledBorder; import java.awt.image.BufferedImage; import java.util.ArrayList; public class LandingPage extends JFrame { public boolean verify = false; Profile user = new Profile(); database newUser = new database(); //registrationPage register = new registrationPage(); //These variables keep the latest X and Y event locations. int lastClickX; int lastClickY; String coordinates; //This label is going to represent the map JLabel label; aboutPage aboutP; //this contentPane represents the top bar in the code private JPanel contentPane; //This is a textField for usernames private JTextField txtUser; //this is a textField for passwords private JTextField txtPass; //This is going to represent the popup menu on right click JPopupMenu popupMenu; //These are the control options for that popup menu private JMenuItem makeReport, viewInfo, deleteMarker,getAll; //This complaints window represents the window that pops up when you click add a problem Complaints complaints; //This points at an object instantiated by the complaints window ArrayList issues; //This is used for drawing MapComponent mapComponent; JButton btnLogin, btnRegister, btnAbout; JSeparator separator; Color clickLocation; //int colorRange[] = new int[6]; int colorRange[] = {238,245,239,242,238,245}; int mapPixels[]; ImageIcon map; /** * Create the frame. */ public LandingPage() { instantiate(); addAttributes(); addPopup(mapComponent, popupMenu); // Image img = new ImageIcon(this.getClass().getResource("/map.png")).getImage(); } public int instantiate(){ //Instantiate variables to 0 at first lastClickX = 0; lastClickY = 0; //Instantiate a complaints window; should only have one of this object complaints = new Complaints(lastClickX, lastClickY); //Makes the issues variable of this class point to the ArrayList created by the Complaints class issues = complaints.getIssues(); //Instantiate popup menu and add items to it popupMenu = new JPopupMenu(); makeReport = new JMenuItem("Make A Report"); viewInfo = new JMenuItem("View Info"); deleteMarker = new JMenuItem("Delete Marker"); getAll = new JMenuItem("Get All Issues"); mapComponent = new MapComponent(); label = new JLabel("AAAAAAA"); contentPane = new JPanel(); //Make a new text field for the user stuff txtUser = new JTextField(); txtUser.setText("enter username"); txtUser.setBounds(830, 13, 130, 26); txtUser.setColumns(10); //contentPane.add(txtUser); aboutP = new aboutPage(); btnLogin = new JButton("Login"); btnRegister = new JButton("Register"); btnAbout = new JButton("About"); separator = new JSeparator(); txtPass = new JTextField(); return 1; } public int addAttributes() { popupMenu.add(makeReport); popupMenu.add(viewInfo); popupMenu.add(deleteMarker); popupMenu.add(getAll); mapComponent.add(popupMenu); label.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { } }); label.setBounds(23, 51, 1216, 674); mapComponent.addMouseListener(new MouseAdapter(){ @Override public void mouseClicked(MouseEvent e) {} }); mapComponent.setBounds(23,51,1216,674); //Make a JPanel, add a border around it, and add the label to it. //contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); contentPane.setLayout(null); //contentPane.add(label); //Add the JPanel above to this frame, set its close operation, and bounds this.setContentPane(contentPane); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setBounds(100, 100, 1262,753); this.add(mapComponent, BorderLayout.CENTER); map = new ImageIcon("/Users/Hamza/Desktop/map.png"); label.setIcon(map); makeReport.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { //JFrame complaint = new complaints().setVisible(true); //Makes a new popup window of complaints, and logs the clicked X and Y locations //complaints = new Complaints(lastClickX, lastClickY); if(verify == true){ complaints.setCoords(lastClickX,lastClickY); complaints.setVisible(true); }else{ } } }); getAll.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { for(int i = 0; i < issues.size(); i++) { System.out.println(issues.get(i).getDescrip() + "\n"); complaints.repaint(); } } }); JButton btnAbout = new JButton("About"); btnAbout.setBounds(453, 13, 117, 29); separator.setBounds(23, 38, 1215, 12); txtPass.setText("enter password"); txtPass.setBounds(980, 13, 130, 26); //contentPane.add(txtPass); txtPass.setColumns(10); JTextField txtNewName = new JTextField(); txtNewName.setText("Enter New User"); txtNewName.setBounds(152, 10, 130, 26); txtNewName.setColumns(10); JTextField txtNewPass = new JTextField(); txtNewPass.setText("Enter New Pass"); txtNewPass.setBounds(294, 10, 130, 26); txtNewPass.setColumns(10); btnLogin.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if(newUser.checkLogin(txtUser.getText(), txtPass.getText())){ JOptionPane.showMessageDialog(null, "Login Success"); verify = true; }else{ JOptionPane.showMessageDialog(null, "Login Failed"); verify = false; } } }); btnLogin.setBounds(1122, 13, 117, 29); btnRegister.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { newUser.addUser(txtNewName.getText(), txtNewPass.getText()); JOptionPane.showMessageDialog(null, "Successfully Registered"); txtNewName.setText(""); txtNewPass.setText(""); } }); btnAbout.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { aboutP.setVisible(true); } }); btnRegister.setBounds(23, 10, 117, 29); contentPane.add(label); contentPane.add(txtNewName); contentPane.add(txtNewPass); contentPane.add(txtUser); contentPane.add(btnLogin); contentPane.add(btnRegister); contentPane.add(btnAbout); contentPane.add(separator); contentPane.add(txtPass); return 0; } private void addPopup(Component component, final JPopupMenu popup) { //Adds a listener to the Label. If clicked, open the menu component.addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent e) { if (e.isPopupTrigger() && SwingUtilities.isRightMouseButton(e)) { showMenu(e); } } public void mouseReleased(MouseEvent e) { if (e.isPopupTrigger() && SwingUtilities.isRightMouseButton(e)) { //Image imgMap = (BufferedImage) map; //clickLocation = showMenu(e); } } private void showMenu(MouseEvent e) { lastClickX = e.getX(); lastClickY = e.getY(); coordinates = "{" + lastClickX +"," + lastClickY +"}"; System.out.println(coordinates); //Shows the popup at x, y of the MapComponent popup.show(e.getComponent(), e.getX(), e.getY()); } }); } class MapComponent extends JComponent { public MapComponent(){ super(); class MouseClickListener implements MouseListener { public void mousePressed(MouseEvent e){ if(SwingUtilities.isRightMouseButton(e)) {} //repaint(); } public void mouseClicked(MouseEvent e){ repaint(); } public void mouseReleased(MouseEvent e){} public void mouseEntered(MouseEvent e){} public void mouseExited(MouseEvent e){} } MouseListener clickListener = new MouseClickListener(); this.addMouseListener(clickListener); } public void paintComponent(Graphics g) { for(int i = 0; i < issues.size(); i++) { Graphics2D g2 = (Graphics2D) g; //System.out.println(issues.get(i).getIcon().toString()); issues.get(i).getIcon().draw(g2); } } } }