⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sensorimage.java

📁 layout of sensors on diagram / building plan
💻 JAVA
字号:
 /* SensorImage.java * * @author Gilad Kinor & Lena Gurevich */package my.image;import javax.swing.*;import java.awt.*;import java.awt.event.*;public class SensorImage extends JFrame {    /** Creates new form SensorImage - the main class which builds the GUI */    public SensorImage() {        initComponents();    }    /** This method is called from within the constructor to     * initialize the form.     * it initiates the GUI (done with NetBeans GUI builder) and adds a GlassPane     */    @SuppressWarnings("unchecked")    // <editor-fold defaultstate="collapsed" desc="Generated Code">    private void initComponents() {        jPanel1 = new javax.swing.JPanel();        jLabel1 = new javax.swing.JLabel();        jPanel2 = new javax.swing.JPanel();        jPanel3 = new javax.swing.JPanel();        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);        setResizable(false);        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)), "Illustration", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 11))); // NOI18N        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/my/image/illustration/planfloor4_1.JPG"))); // NOI18N        jLabel1.setMinimumSize(new java.awt.Dimension(1, 1));        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);        jPanel1.setLayout(jPanel1Layout);        jPanel1Layout.setHorizontalGroup(            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)            .addGroup(jPanel1Layout.createSequentialGroup()                .addContainerGap()                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 470, javax.swing.GroupLayout.PREFERRED_SIZE)                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))        );        jPanel1Layout.setVerticalGroup(            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)            .addGroup(jPanel1Layout.createSequentialGroup()                .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)                .addContainerGap())        );        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)), "Thermometer", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 11))); // NOI18N        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);        jPanel2.setLayout(jPanel2Layout);        jPanel2Layout.setHorizontalGroup(            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)            .addGap(0, 84, Short.MAX_VALUE)        );        jPanel2Layout.setVerticalGroup(            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)            .addGap(0, 577, Short.MAX_VALUE)        );        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)), "Floors", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 11))); // NOI18N        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);        jPanel3.setLayout(jPanel3Layout);        jPanel3Layout.setHorizontalGroup(            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)            .addGap(0, 582, Short.MAX_VALUE)        );        jPanel3Layout.setVerticalGroup(            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)            .addGap(0, 43, Short.MAX_VALUE)        );        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());        getContentPane().setLayout(layout);        layout.setHorizontalGroup(            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)            .addGroup(layout.createSequentialGroup()                .addContainerGap()                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()                        .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 488, Short.MAX_VALUE)                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))                    .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))                .addContainerGap())        );        layout.setVerticalGroup(            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)            .addGroup(layout.createSequentialGroup()                .addContainerGap()                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))        );        //Set up the glass pane, which appears over the        //content pane and is an item listener on the change        //mouse. added seperately to the GUI        myGlassPane = new SensorGlassPane();        this.setGlassPane(myGlassPane);        addMouseListener(myGlassPane);        pack();    }// </editor-fold>    /**    * the main method. calls for the main class and sets its visibility to true    */    public static void main(String args[]) {        javax.swing.SwingUtilities.invokeLater(new Runnable() {            public void run() {                new SensorImage().setVisible(true);            }        });    }    // Variables declaration - do not modify    private javax.swing.JLabel jLabel1;    private javax.swing.JPanel jPanel1;    private javax.swing.JPanel jPanel2;    private javax.swing.JPanel jPanel3;    private SensorGlassPane myGlassPane;    // End of variables declaration}/** Creates new form SensorGlassPane - which adds a glass panel to the GUI for drawing  a dot in various places*/class SensorGlassPane extends JComponent implements MouseListener{    //a point variable, to determine where to draw the dot    Point point;    @Override //overrides "paint" method from the JComponent, paints the color orange and sets its place    protected void paintComponent(Graphics g) {        if (point != null) {            g.setColor(Color.orange);            g.fillOval(point.x-8, point.y-35, 10, 10);        }    }    //sets the point to be drawn on    public void setPoint(Point p) {        point = p;    }    //constructor    public SensorGlassPane() {    }    //overrides function from MouseListener. acts when mouse is clicked somewhere on the GUI    public void mouseClicked(MouseEvent e) {        //gets the point where the mouse was clikced        Point check = e.getPoint();        //checks whether it was clicked within the boundaries of the illustration        if ((35<=check.x) && (check.x<=486) && (64<=check.y) && (check.y<=622)){            //sets the point where the draw will take place            this.setPoint(check);            //set "true" for visibility            setVisible(true);            //repaints the dot            this.repaint();        }        else            //set "false" for visibility, if point is out of boundary            setVisible(false);    }    //overrides function from MouseListener. unsupported    public void mousePressed(MouseEvent e) {    }    //overrides function from MouseListener. unsupported    public void mouseReleased(MouseEvent e) {    }    //overrides function from MouseListener. unsupported    public void mouseEntered(MouseEvent e) {    }    //overrides function from MouseListener. unsupported    public void mouseExited(MouseEvent e) {    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -