📄 cameragui.java
字号:
package sept.view;/** * Class CameraGui * * This is a class of GUI for displaying the informating and communicate between the client and program. * * @author JiaJian Feng */import java.awt.*;import java.awt.event.*;import java.io.*;import java.net.*;import java.awt.Image;import javax.print.DocFlavor.URL;import javax.swing.*;import sept.model.*;public class CameraGui extends JFrame{ private JMenuBar menu; private JLabel photoLabel; private JMenu fileMenu,cameras,removeCamera,selectCamera,photos; private JMenuItem exitItem,addCamera,openImg,spCam; private Container content; private final JFileChooser photoSelection; private Photo choosePhoto; //private JScrollPane scroll; private boolean photoOpen=false; private JPanel photoPanel=new JPanel(); CameraManager cams; String camName,address; int noofcams=0,counter1=0; Socket socket; Camera onfocus=null; // URL u; /** * Method CameraGui * Creates the GUI to display the program */ public CameraGui() { fileMenu= new JMenu("File"); cameras=new JMenu("Camera"); photos=new JMenu("Photos"); exitItem=new JMenuItem("Exit"); //test1=new JMenu("Test"); fileMenu.add(exitItem); addCamera=new JMenuItem("Add Camera"); removeCamera=new JMenu("Remove Camera"); selectCamera=new JMenu("Select Camera"); cameras.add(addCamera); cameras.add(removeCamera); cameras.add(selectCamera); openImg=new JMenuItem("Open Photos"); photos.add(openImg); // removeCamera.setVisible(false); //selectCamera.setVisible(false); cams=new CameraManager(); noofcams=cams.numberOfCameras(); /** for(int i=0;i<noofcams;i++) { selectCamera.setVisible(true); spCam=new JMenuItem("cam"+i); selectCamera.add(spCam); spCam.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { } }); validate(); content.repaint(); }**/ // addcam=new Container(); /** removeCamera.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { } }); **/ photoSelection = new JFileChooser(new File("C:\\")); openImg.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { int result; result=photoSelection.showOpenDialog(CameraGui.this); if(result==JFileChooser.APPROVE_OPTION) { Object f=photoSelection.getSelectedFile(); File f1=photoSelection.getSelectedFile(); if(!photoOpen) { photoOpen=true; //choosePhoto=new Photo(f1.getName(),img); ImageIcon icon = new ImageIcon(f1.getPath()); //JLabel label = new JLabel(icon); photoLabel=new JLabel(); photoLabel.setIcon(icon); photoPanel.add(photoLabel); content.setLayout(new BorderLayout()); content.add(photoPanel,BorderLayout.CENTER); content.validate(); content.repaint(); } } } }); addCamera.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { camName=JOptionPane.showInputDialog("Enter the camera name"); address=JOptionPane.showInputDialog("Enter the camera Address"); cams.addCamera(camName,address); noofcams=cams.numberOfCameras(); if(noofcams!=0) { removeCamera.removeAll(); for(int i=0;i<noofcams;i++) { String camerName=cams.getCameraList().get(i).getName(); spCam=new JMenuItem(camerName); removeCamera.add(spCam); counter1=i; spCam.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { cams.removeCamera(cams.getCameraList().get(counter1).getName()); removeCamera.remove(spCam); validate(); content.repaint(); } }); validate(); content.repaint(); } selectCamera.removeAll(); for(int i=0;i<noofcams;i++) { String camerName=cams.getCameraList().get(i).getName(); onfocus=cams.getCameraList().get(i); spCam=new JMenuItem(camerName); selectCamera.add(spCam); spCam.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { cams.update(); Image pic =cams.getPhotos(onfocus.getName()).get(cams.getPhotos(onfocus.getName()).size()-1).getImage(); ImageIcon icon=new ImageIcon(pic); //ImageIcon("Http://camera1.csit.rmit.edu.au/IMAGE.JPG"); photoLabel=new JLabel(); photoLabel.setIcon(icon); photoPanel.add(photoLabel); content.removeAll(); content.setLayout(new BorderLayout()); content.add(photoPanel,BorderLayout.CENTER); content.validate(); content.repaint(); } }); } validate(); content.repaint(); /** addcam popAddCam=new addcam(); content.setVisible(false); popAddCam.setSize(400,400); popAddCam.setLocation(100,100); popAddCam.setVisible(true); **/ } }}); exitItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.exit(0); } }); menu=new JMenuBar(); menu.add(fileMenu); menu.add(cameras); menu.add(photos); //menu.add(exitMenu); this.setJMenuBar(menu); content=this.getContentPane(); //content.repaint(); /** this.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } });**/}/** public void camMenuBuilder(int camsNo, JMenu monMenu) { monMenu.removeAll(); for(int i=0;i<camsNo;i++) { String camerName=cams.getCameraList().get(i).getName(); onfocus=cams.getCameraList().get(i); spCam=new JMenuItem(camerName); monMenu.add(spCam); spCam.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { cams.removeCamera(cams.getCameraList().get(counter1).getName()); monMenu.removeAll(); camMenuBuilder(cams.getCameraList().size(),monMenu); } }); }**/ }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -